stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

KeyError: 'sample'

Open ProgramerSalar opened this issue 1 year ago • 0 comments

if you get this error

File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python3.11/dist-packages/diffusers/utils/outputs.py", line 110, in __getitem__
    return inner_dict[k]
           ~~~~~~~~~~^^^
KeyError: 'sample'

then you should modify the image pipe

##Before

with autocast("cuda"):
...     image = pipe(prompt)["sample"][0]  

##After

with autocast("cuda"):
...     image = pipe(prompt)[0]  
...     image[0].save("astronaut_rides_horse.png")

Note: before image pipe have the sample in the string format but in the after code i will remove

ProgramerSalar avatar Apr 24 '25 11:04 ProgramerSalar