ImageReward
ImageReward copied to clipboard
Getting attribute error trying to use with Stable Diffusion
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'
Same issue for me and the issue persist on a fresh install of Automatic1111 too
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?
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'
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!
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?
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:
- In the
stable-diffusion-webui\venv\Scripts
directory, runactivate
oractivate.bat
(if you are using cmd) oractivate.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. - Run
pip show image-reward
to check if "image-reward" is exactly not installed in your venv. - Then run
pip install image-reward
to install "image-reward" in your venv.
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'
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.
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?
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?
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
orwebui.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:
- In the
stable-diffusion-webui\venv\Scripts
directory, runactivate
oractivate.bat
(if you are using cmd) oractivate.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.- Run
pip show image-reward
to check if "image-reward" is exactly not installed in your venv.- 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'])
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
orwebui.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:
- In the
stable-diffusion-webui\venv\Scripts
directory, runactivate
oractivate.bat
(if you are using cmd) oractivate.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.- Run
pip show image-reward
to check if "image-reward" is exactly not installed in your venv.- 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:
https://github.com/THUDM/ImageReward/blob/9e96d39662876d579f9ed0982a1cc6b422e29691/sdwebui/image_reward.py#L20-L31