Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting attribute error trying to use with Stable Diffusion #18

Open
celticsha opened this issue May 15, 2023 · 12 comments
Open

Getting attribute error trying to use with Stable Diffusion #18

celticsha opened this issue May 15, 2023 · 12 comments
Labels
sd-webui The usage of ImageReward in sd-webui

Comments

@celticsha
Copy link

I followed the instructions to use ImageReward with Stable Diffusion's webui, but I get the following error:
AttributeError: module 'ImageReward' has no attribute 'load'

@DenSckriva
Copy link

Same issue for me and the issue persist on a fresh install of Automatic1111 too

@tongyx361
Copy link
Collaborator

Thank both of you so much for the issues! Let's resolve it together 😀
I'm sorry I don't have enough information to reproduce this error with just this line of error AttributeError: module 'ImageReward' has no attribute 'load'
Could any of you provide more information, for example, the complete error message in terminal?

@DenSckriva
Copy link

Thank both of you so much for the issues! Let's resolve it together 😀 I'm sorry I don't have enough information to reproduce this error with just this line of error AttributeError: module 'ImageReward' has no attribute 'load' Could any of you provide more information, for example, the complete error message in terminal?

Of course !

Error completing request
Arguments: ('task(b99ytqs0h3thvof)', 'RAW, photography, masterpiece, sfw, 1cat mainecoon, (detailed fur, realistic grey fur), laying under a cherry tree, cherry blossom, detailed background ', ' easynegative, verybadimagenegative_v1.3, deformityv6, animal ears, nudity, nude, naked, anthro, human', [], 40, 16, False, False, 4, 1, 7, -1.0, -1.0, 0, 0, 0, False, 904, 512, False, 0.7, 2, 'Latent', 0, 0, 0, [], 2, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', <controlnet.py.UiControlNetUnit object at 0x00000180BE80B8B0>, False, '', '', '', '', '', '', '', '', '', '', '', '', '', [], 0.5, 'All Frames', 'Loop', False, '0', False, False, 'positive', 'comma', 0, False, False, '', False, False, 100.0, True, '', '', 1.0, 0.1, '', 3000.0, True, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, '', 5, 24, 12.5, 1000, '', 'DDIM', 0, 64, 64, '', 64, 7.5, 0.42, 'DDIM', 64, 64, 1, 0, 92, True, True, True, False, False, False, 'midas_v21_small', None, False, 50) {}
Traceback (most recent call last):
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 56, in run
    shared.image_reward_model  # if loaded, do nothing
AttributeError: module 'modules.shared' has no attribute 'image_reward_model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "I:\stable-diffusion-webui\modules\txt2img.py", line 53, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *args)
  File "I:\stable-diffusion-webui\modules\scripts.py", line 408, in run
    processed = script.run(p, *script_args)
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 63, in run
    shared.image_reward_model = reward.load(
AttributeError: module 'ImageReward' has no attribute 'load'

@tongyx361
Copy link
Collaborator

Thank both of you so much for the issues! Let's resolve it together 😀 I'm sorry I don't have enough information to reproduce this error with just this line of error AttributeError: module 'ImageReward' has no attribute 'load' Could any of you provide more information, for example, the complete error message in terminal?

Of course !

Error completing request
Arguments: ('task(b99ytqs0h3thvof)', 'RAW, photography, masterpiece, sfw, 1cat mainecoon, (detailed fur, realistic grey fur), laying under a cherry tree, cherry blossom, detailed background ', ' easynegative, verybadimagenegative_v1.3, deformityv6, animal ears, nudity, nude, naked, anthro, human', [], 40, 16, False, False, 4, 1, 7, -1.0, -1.0, 0, 0, 0, False, 904, 512, False, 0.7, 2, 'Latent', 0, 0, 0, [], 2, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', <controlnet.py.UiControlNetUnit object at 0x00000180BE80B8B0>, False, '', '', '', '', '', '', '', '', '', '', '', '', '', [], 0.5, 'All Frames', 'Loop', False, '0', False, False, 'positive', 'comma', 0, False, False, '', False, False, 100.0, True, '', '', 1.0, 0.1, '', 3000.0, True, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, '', 5, 24, 12.5, 1000, '', 'DDIM', 0, 64, 64, '', 64, 7.5, 0.42, 'DDIM', 64, 64, 1, 0, 92, True, True, True, False, False, False, 'midas_v21_small', None, False, 50) {}
Traceback (most recent call last):
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 56, in run
    shared.image_reward_model  # if loaded, do nothing
AttributeError: module 'modules.shared' has no attribute 'image_reward_model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "I:\stable-diffusion-webui\modules\txt2img.py", line 53, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *args)
  File "I:\stable-diffusion-webui\modules\scripts.py", line 408, in run
    processed = script.run(p, *script_args)
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 63, in run
    shared.image_reward_model = reward.load(
AttributeError: module 'ImageReward' has no attribute 'load'

It seems that you are experiencing the same problem as this issue.

You could try the possible solution described below:

A possible workaround for you (and other Windows users experiencing similar problems) is that: if you only wish to use ImageReward in SD Web UI, then you can choose to install the ImageReward into the models directory of SD Web UI. Specifically, in your image-reward.py, you need to replace the

shared.image_reward_model = reward.load(
    "ImageReward-v1.0",
) # using shared to make the model object global among modules

with

shared.image_reward_model = reward.load(
    "ImageReward-v1.0",
    download_root=Path.cwd().parent / "models" / "ImageReward",
) # using shared to make the model object global among modules

If you wish to use ImageReward elsewhere than in the SD Web UI, feel free to inquire further.

We're sorry that since the user who raised the issue above did not provide feedback on whether the solution we had suggestted worked, we have not yet updated the repository with the corresponding improvements.

If any of you can confirm the validity of the solution, we'd appreciate it!

@DenSckriva
Copy link

Thanks for the support to get started :)

I made the modification of the script but the problem remains the same with exactly the same error.

I can only consider a bad installation since the script doesn't seem to find the files it needs. However my ImageReward folder is located in the same folder as stable-diffusion.

Could the fact that the whole thing is installed on disk I: instead of C: be the cause?

@tongyx361
Copy link
Collaborator

Thanks for the support to get started :)

I made the modification of the script but the problem remains the same with exactly the same error.

I can only consider a bad installation since the script doesn't seem to find the files it needs. However my ImageReward folder is located in the same folder as stable-diffusion.

Could the fact that the whole thing is installed on disk I: instead of C: be the cause?

Sorry for my earlier lapse in judgment, your errors are not the same. I have experimented with Windows 10 and reproduced your error.

If you started SD Web UI with the webui-user.bat or webui.bat script, your error is probably caused by failing to install the "image-reward" pip package in venv's Python environment.

To resolve this error, you need to make sure that "image-reward" is installed in venv Python environment. To do this, try:

  1. In the stable-diffusion-webui\venv\Scripts directory, run activate or activate.bat (if you are using cmd) or activate.ps1 (if you are using PowerShell) from . If you see the prompt (venv) appear at the far left of the command line, you have successfully activated venv created by the SD Web UI.
  2. Run pip show image-reward to check if "image-reward" is exactly not installed in your venv.
  3. Then run pip install image-reward to install "image-reward" in your venv.

@DenSckriva
Copy link

Not bad ! There is better.

I had to change the script back to default. Well, now the generation is done correctly but when it is finished, a new error has appeared.

locon load lora method
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:09<00:00,  6.45it/s]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.07it/s]
load checkpoint from C:\Users\Sckriva/.cache/ImageReward\ImageReward.pt████████████████| 60/60 [00:08<00:00,  7.28it/s]
checkpoint loaded
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.30it/s]
Error completing request███████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.23it/s]
Arguments: ('task(vhud00f8rsxxy5e)', 'pokemon style, masterpiece, 1girl, (misty from pokemon), extremely detailed face, ginger hair, green eyes, smile, wear  sexy and beautiful rich japanese kimono, ultradetailed, detailed background, indoor background, dusk, Cherry flower, striding, oversatured, ultra high res, intricate, <lora:Misty:0.9>', 'bad_prompt_version2-neg, By bad artist -neg, verybadimagenegative_v1.3,', [], 60, 14, False, False, 1, 1, 8.5, -1.0, -1.0, 0, 0, 0, False, 904, 512, False, 0.7, 2, 'Latent', 0, 0, 0, [], 2, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', <controlnet.py.UiControlNetUnit object at 0x000002561D6B3040>, False, '', '', '', '', '', '', '', '', '', '', '', '', '', [], 0.5, 'All Frames', 'Loop', False, '0', False, False, 'positive', 'comma', 0, False, False, '', False, False, 100.0, True, '', '', 1.0, 0.1, '', 3000.0, True, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, '', 5, 24, 12.5, 1000, '', 'DDIM', 0, 64, 64, '', 64, 7.5, 0.42, 'DDIM', 64, 64, 1, 0, 92, True, True, True, False, False, False, 'midas_v21_small', None, False, 50) {}
Traceback (most recent call last):
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "I:\stable-diffusion-webui\modules\txt2img.py", line 53, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *args)
  File "I:\stable-diffusion-webui\modules\scripts.py", line 408, in run
    processed = script.run(p, *script_args)
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 80, in run
    img.info["parameters"] += f"\n ImageReward Score: {score:.4f}"
KeyError: 'parameters'

@tongyx361
Copy link
Collaborator

Not bad ! There is better.

I had to change the script back to default. Well, now the generation is done correctly but when it is finished, a new error has appeared.

locon load lora method
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:09<00:00,  6.45it/s]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.07it/s]
load checkpoint from C:\Users\Sckriva/.cache/ImageReward\ImageReward.pt████████████████| 60/60 [00:08<00:00,  7.28it/s]
checkpoint loaded
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.30it/s]
Error completing request███████████████████████████████████████████████████████████████| 60/60 [00:08<00:00,  7.23it/s]
Arguments: ('task(vhud00f8rsxxy5e)', 'pokemon style, masterpiece, 1girl, (misty from pokemon), extremely detailed face, ginger hair, green eyes, smile, wear  sexy and beautiful rich japanese kimono, ultradetailed, detailed background, indoor background, dusk, Cherry flower, striding, oversatured, ultra high res, intricate, <lora:Misty:0.9>', 'bad_prompt_version2-neg, By bad artist -neg, verybadimagenegative_v1.3,', [], 60, 14, False, False, 1, 1, 8.5, -1.0, -1.0, 0, 0, 0, False, 904, 512, False, 0.7, 2, 'Latent', 0, 0, 0, [], 2, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', <controlnet.py.UiControlNetUnit object at 0x000002561D6B3040>, False, '', '', '', '', '', '', '', '', '', '', '', '', '', [], 0.5, 'All Frames', 'Loop', False, '0', False, False, 'positive', 'comma', 0, False, False, '', False, False, 100.0, True, '', '', 1.0, 0.1, '', 3000.0, True, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, '', 5, 24, 12.5, 1000, '', 'DDIM', 0, 64, 64, '', 64, 7.5, 0.42, 'DDIM', 64, 64, 1, 0, 92, True, True, True, False, False, False, 'midas_v21_small', None, False, 50) {}
Traceback (most recent call last):
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "I:\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "I:\stable-diffusion-webui\modules\txt2img.py", line 53, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *args)
  File "I:\stable-diffusion-webui\modules\scripts.py", line 408, in run
    processed = script.run(p, *script_args)
  File "I:\stable-diffusion-webui\scripts\image_reward.py", line 80, in run
    img.info["parameters"] += f"\n ImageReward Score: {score:.4f}"
KeyError: 'parameters'

This seems a little weird. I'm sorry that I failed to reproduce it in my own environment.

To resolve this error, could you kindly provide the image generation settings when you encountered this error? For example, a screenshot of the entire SD Web UI interface would help.

In addition, you might want to try the following modification in the image_reward.py file:

Replace the existing code:

            img.info["parameters"] += f"\n ImageReward Score: {score:.4f}"

with the following:

            if img.info.get("parameters") is None:
                img.info["parameters"] = f"ImageReward Score: {score:.4f}"
            else:
                img.info["parameters"] += f"\n ImageReward Score: {score:.4f}"

This modification tries to ensure that the ImageReward Score information is properly added to the img.info["parameters"].

Please let us know if this resolves the issue.

@JeffreyBull76
Copy link

I have a similar error, tried the fixes here, imagereward is installed and showing when running pip show, but still get this error...

"image-reward" package is successfully installed! Error loading script: image_reward.py Traceback (most recent call last): File "C:\SD_NewInstall\stable-diffusion-webui\scripts\image_reward.py", line 21, in <module> import ImageReward as reward ModuleNotFoundError: No module named 'ImageReward'

Tried various fixes nothing seems to work.
My SD is installed to C; but my image directories are in D; could this cause the issue?

@tongyx361
Copy link
Collaborator

I have a similar error, tried the fixes here, imagereward is installed and showing when running pip show, but still get this error...

"image-reward" package is successfully installed! Error loading script: image_reward.py Traceback (most recent call last): File "C:\SD_NewInstall\stable-diffusion-webui\scripts\image_reward.py", line 21, in <module> import ImageReward as reward ModuleNotFoundError: No module named 'ImageReward'

Tried various fixes nothing seems to work. My SD is installed to C; but my image directories are in D; could this cause the issue?

Thank you so much for the issue! Let's resolve it together 😀

Usually, I guess that the path of image directory makes little difference. There might be other problems.

Could you please provide the full error message printed in the terminal?

@Katehuuh
Copy link

Katehuuh commented Jul 5, 2023

Thanks for the support to get started :)
I made the modification of the script but the problem remains the same with exactly the same error.
I can only consider a bad installation since the script doesn't seem to find the files it needs. However my ImageReward folder is located in the same folder as stable-diffusion.
Could the fact that the whole thing is installed on disk I: instead of C: be the cause?

Sorry for my earlier lapse in judgment, your errors are not the same. I have experimented with Windows 10 and reproduced your error.

If you started SD Web UI with the webui-user.bat or webui.bat script, your error is probably caused by failing to install the "image-reward" pip package in venv's Python environment.

To resolve this error, you need to make sure that "image-reward" is installed in venv Python environment. To do this, try:

  1. In the stable-diffusion-webui\venv\Scripts directory, run activate or activate.bat (if you are using cmd) or activate.ps1 (if you are using PowerShell) from . If you see the prompt (venv) appear at the far left of the command line, you have successfully activated venv created by the SD Web UI.
  2. Run pip show image-reward to check if "image-reward" is exactly not installed in your venv.
  3. Then run pip install image-reward to install "image-reward" in your venv.

Hi :) Please consider the following, add this instructions to https://github.com/THUDM/ImageReward#integration-into-stable-diffusion-web-ui or directly from image_reward.py:

import pip
pip.main(['install', 'image-reward'])

@tongyx361
Copy link
Collaborator

Thanks for the support to get started :)
I made the modification of the script but the problem remains the same with exactly the same error.
I can only consider a bad installation since the script doesn't seem to find the files it needs. However my ImageReward folder is located in the same folder as stable-diffusion.
Could the fact that the whole thing is installed on disk I: instead of C: be the cause?

Sorry for my earlier lapse in judgment, your errors are not the same. I have experimented with Windows 10 and reproduced your error.
If you started SD Web UI with the webui-user.bat or webui.bat script, your error is probably caused by failing to install the "image-reward" pip package in venv's Python environment.
To resolve this error, you need to make sure that "image-reward" is installed in venv Python environment. To do this, try:

  1. In the stable-diffusion-webui\venv\Scripts directory, run activate or activate.bat (if you are using cmd) or activate.ps1 (if you are using PowerShell) from . If you see the prompt (venv) appear at the far left of the command line, you have successfully activated venv created by the SD Web UI.
  2. Run pip show image-reward to check if "image-reward" is exactly not installed in your venv.
  3. Then run pip install image-reward to install "image-reward" in your venv.

Hi :) Please consider the following, add this instructions to https://github.com/THUDM/ImageReward#integration-into-stable-diffusion-web-ui or directly from image_reward.py:

import pip
pip.main(['install', 'image-reward'])

Thank you very much for the suggestion! We have actually added similar code to image_reward.py as follows:

try:
import ImageReward as reward
except ModuleNotFoundError as error:
print('"image-reward" package has not been properly installed. Installing...')
if subprocess.check_call(["pip", "install", "image-reward"]) == 0:
print(f'"image-reward" package is successfully installed!')
import ImageReward as reward
else:
print('"image-reward" package installation failed!')
print(
"Please open an issue with full error message at https://github.com/THUDM/ImageReward/issues"
)

@xujz18 xujz18 reopened this Jul 11, 2023
@xujz18 xujz18 added the sd-webui The usage of ImageReward in sd-webui label Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sd-webui The usage of ImageReward in sd-webui
Projects
None yet
Development

No branches or pull requests

6 participants