castorini / daam

Diffusion attentive attribution maps for interpreting Stable Diffusion.
MIT License
669 stars 61 forks source link

Newer version of diffusers fails due to tensor being passed to safety checker #54

Closed rockerBOO closed 8 months ago

rockerBOO commented 10 months ago

With diffusers 0.21.2 the safety checker hook fails due to tensors being passed instead of numpy arrays.

Traceback (most recent call last):
  File "/mnt/900/builds/sd-scripts/daam/test.py", line 161, in <module>
    main(args)
  File "/mnt/900/builds/sd-scripts/daam/test.py", line 115, in main
    out = pipe(
  File "/mnt/900/builds/sd-scripts/.venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/mnt/900/builds/sd-scripts/.venv/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 708, in __call__
    image, has_nsfw_concept = self.run_safety_checker(image, device, prompt_embeds.dtype)
  File "/mnt/900/builds/sd-scripts/daam/daam/trace.py", line 140, in _hooked_run_safety_checker
    pil_image = self.numpy_to_pil(image)
  File "/mnt/900/builds/sd-scripts/.venv/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 1699, in numpy_to_pil
    return numpy_to_pil(images)
  File "/mnt/900/builds/sd-scripts/.venv/lib/python3.10/site-packages/diffusers/utils/pil_utils.py", line 43, in numpy_to_pil
    images = (images * 255).round().astype("uint8")
AttributeError: 'Tensor' object has no attribute 'astype'. Did you mean: 'dtype'?

Am aware the library isn't supported at this version. Making a PR to fix with backwards compatibility.

daemon commented 9 months ago

Thanks for this!

daemon commented 8 months ago

Resolved in latest release.