kousw / stable-diffusion-webui-daam

DAAM for Stable Diffusion Web UI
Other
163 stars 28 forks source link

Error: cannot generate heatmaps due to - AttributeError: module 'matplotlib.cm' has no attribute 'turbo' #14

Closed charliehaydenhicks closed 1 year ago

charliehaydenhicks commented 1 year ago

Note that the render completed, but the extension did not. as in, the main image was rendered, but not the heatmaps.

Error AttributeError: module 'matplotlib.cm' has no attribute 'turbo'

Using automatic 1111 colab

full dump

Error executing callback before_image_saved_callback for /content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam_script.py
Traceback (most recent call last):
  File "/content/stable-diffusion-webui/modules/script_callbacks.py", line 121, in before_image_saved_callback
    c.callback(params)
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam_script.py", line 207, in handle_before_image_saved
    before_image_saved_handler(params)
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam_script.py", line 108, in <lambda>
    before_image_saved_handler = lambda params : self.before_image_saved(params)
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam_script.py", line 175, in before_image_saved
    img : Image.Image = utils.image_overlay_heat_map(params.image, heat_map_img, alpha=self.alpha, caption=caption, image_scale=self.heatmap_image_scale)
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam/utils.py", line 62, in image_overlay_heat_map
    heat_map = _convert_heat_map_colors(heat_map)
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam/utils.py", line 85, in _convert_heat_map_colors
    color_map = np.array([ get_color(i) * 255 for i in range(256) ])
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam/utils.py", line 85, in <listcomp>
    color_map = np.array([ get_color(i) * 255 for i in range(256) ])
  File "/content/stable-diffusion-webui/extensions/stable-diffusion-webui-daam/scripts/daam/utils.py", line 83, in get_color
    return np.array(cm.turbo(value / 255)[0:3])
AttributeError: module 'matplotlib.cm' has no attribute 'turbo'
kousw commented 1 year ago

'turbo' is not supported in older versions of matplotlib. Please upgrade matplotlib.

charliehaydenhicks commented 1 year ago

Okay, I had already run the pip install --upgrade matplotlib command but the error persisted. I'll investigate as an issue with pip

charliehaydenhicks commented 1 year ago

Update: looks like pip was indeed able to update matplotlib. I can call cm.turbo in the terminal, but after rebooting I still have the issue in the app.

Here's what I see in the terminal (proof turbo should exist)

cm.turbo(5 / 255)
(0.21291, 0.12947, 0.37314, 1.0)
Havegum commented 1 year ago

If matplotlib is the updated version in the terminal but not while running the project, could it be a virtualenv issue? I'm not sure how that works in colab.

Adding an install.py-file like this might resolve the issue for future users:

import launch
if not launch.is_installed('matplotlib'):
    launch.run_pip('install matplotlib==3.6.2', desc='Installing matplotlib==3.6.2')
charliehaydenhicks commented 1 year ago
import launch
if not launch.is_installed('matplotlib'):
    launch.run_pip('install matplotlib==3.6.2', desc='Installing matplotlib==3.6.2')

Thanks @Havegum , would this be a new file or inserted into an existing. If so where would that file be made or found?

charliehaydenhicks commented 1 year ago

Thanks @Havegum ! I added this one line to the launch.py file. I am running it on gdrive so the file was there to edit.

run_pip('install matplotlib==3.6.2', desc='Installing matplotlib==3.6.2')

KuroiMatoO commented 1 year ago

run_pip('install matplotlib==3.6.2', desc='Installing matplotlib==3.6.2')

Where exactly you added this line? Having the same issue.

Havegum commented 1 year ago

Where exactly you added this line? Having the same issue.

Create a new file in the root folder of this extension. If you haven't renamed the folder, it's probably at /extensions/stable-diffusion-webui-daam. Create a file in there called install.py, put those three lines in, save, and start the webui.