CompVis / stable-diffusion

A latent text-to-image diffusion model
https://ommer-lab.com/research/latent-diffusion-models/
Other
67.4k stars 10.08k forks source link

ldm module not found in txt2img #261

Open Bstrum36 opened 1 year ago

Bstrum36 commented 1 year ago

I am running windows 10 and using condo..

I have cloned the git CompVis/stable-diffusion C:\Users\Conda\ldm\stable-diffusion-main

After a long process I have all the modules installed

I get this when I try txt2img.py

PS C:\Users\Conda\ldm\stable-diffusion-main\scripts> python txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 18, in from ldm.util import instantiate_from_config ModuleNotFoundError: No module named 'ldm'

Please advise

Li-Mingshuang commented 1 year ago

Copying 'ldm' folder in stable-diffusion-main to 'scripts' folder. That's how I solve this problem. It begins to run with other problems occurring.

Bstrum36 commented 1 year ago

Thanks for the quick response. I copied the ldm folder to scripts and the program ran a little more. Below is the new error.

PS C:\Users\Conda\ldm\stable-diffusion-main\scripts> python txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 345, in main() File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 240, in main config = OmegaConf.load(f"{opt.config}") File "C:\Users\Conda\envs\tf-gpu\lib\site-packages\omegaconf\omegaconf.py", line 187, in load with io.open(os.path.abspath(file_), "r", encoding="utf-8") as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Conda\ldm\stable-diffusion-main\scripts\configs\stable-diffusion\v1-inference.yaml'

Here is the directory structure of the project from PyCharm. Note I did not delete the ldm folder from the stable-diffusion-main just copied it into scripts. [image: image.png]

Thanks for your help. I am looking forward to getting this workin as I have a project in mind.

On Sun, Sep 11, 2022 at 3:59 AM doraam @.***> wrote:

Copying 'ldm' folder in stable-diffusion-main to 'scripts' folder. That's how I solve this problem. It begins to run with other problems occurring.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1242911367, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRUKMHOTORIE364CUPYLV5WGOXANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

bitRAKE commented 1 year ago

The intent is to use the scripts from the parent directory:

C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms

... in this way the other interfaces have proper hierarchy.

Please, restore the repo and use in the expected fashion.

Bstrum36 commented 1 year ago

Here is the latest please advise.

PS C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Loading model from models/ldm/stable-diffusion-v1/model.ckpt Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 345, in main() File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 241, in main model = load_model_from_config(config, f"{opt.ckpt}") File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 51, in load_model_from_config pl_sd = torch.load(ckpt, map_location="cpu") File "C:\Users\Conda\envs\tf-gpu\lib\site-packages\torch\serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "C:\Users\Conda\envs\tf-gpu\lib\site-packages\torch\serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "C:\Users\Conda\envs\tf-gpu\lib\site-packages\torch\serialization.py", line 211, in init super(_open_file, self).init(open(name, mode)) FileNotFoundError: [Errno 2] No such file or directory: 'models/ldm/stable-diffusion-v1/model.ckpt' PS C:\Users\Conda\ldm\stable-diffusion-main>

On Sun, Sep 11, 2022 at 2:09 PM Rickey Bowers Jr. @.***> wrote:

The intent is to use the scripts from the parent directory:

C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms

... in this way the other interfaces have proper hierarchy.

Please, restore the repo and use in the expected fashion.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1243014474, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRUIXEQX2EBSKMYFX7ITV5YN4NANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

bitRAKE commented 1 year ago

As per the installation instructions, model.ckpt is required in the correct location:

models/ldm/stable-diffusion-v1/model.ckpt

This check point file will need to be one of the provided check points: https://huggingface.co/CompVis

Most people are using: sd-v1-4.ckpt - which needs to be renamed and stored in the correct location.

Bstrum36 commented 1 year ago

I'll give it a try. Thanks

On Sun, Sep 11, 2022, 2:27 PM Rickey Bowers Jr. @.***> wrote:

As per the installation instructions, model.ckpt is required in the correct location:

models/ldm/stable-diffusion-v1/model.ckpt

This check point file will need to be one of the provided check points: https://huggingface.co/CompVis

Most people are using: sd-v1-4.ckpt - which needs to be renamed and stored in the correct location.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1243017713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRULCQXTUORQF7S7YLP3V5YQCJANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

Bstrum36 commented 1 year ago

Slowly but hopefully surely we are moving forward.

Looks like a little progress but...

PS C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Loading model from models/ldm/stable-diffusion-v1/model.ckpt Global Step: 470000 Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 345, in main() File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 241, in main model = load_model_from_config(config, f"{opt.ckpt}") File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 55, in load_model_from_config model = instantiate_from_config(config.model) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\diffusion\ddpm.py", line 24, in from ldm.models.autoencoder import VQModelInterface, IdentityFirstStage, AutoencoderKL File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\autoencoder.py", line 6, in from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ModuleNotFoundError: No module named 'taming'

What do I do now? Am I getting close??

On Sun, Sep 11, 2022 at 2:09 PM Rickey Bowers Jr. @.***> wrote:

The intent is to use the scripts from the parent directory:

C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms

... in this way the other interfaces have proper hierarchy.

Please, restore the repo and use in the expected fashion.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1243014474, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRUIXEQX2EBSKMYFX7ITV5YN4NANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

Bstrum36 commented 1 year ago

Moved forward from ModuleNotFoundError: No module named 'taming' (error below) I installed : (tf-gpu) C:\Users\Conda\HelloWorld> pip install taming-transformers and taming is imported

Now we have moved forward a little ore and get the following:

PS C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Global seed set to 42 Loading model from models/ldm/stable-diffusion-v1/model.ckpt Global Step: 470000 Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 345, in main() File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 241, in main model = load_model_from_config(config, f"{opt.ckpt}") File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 55, in load_model_from_config model = instantiate_from_config(config.model) File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(**config.get("params", dict())) File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "C:\Users\Conda\envs\tf-gpu\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\diffusion\ddpm.py", line 24, in from ldm.models.autoencoder import VQModelInterface, IdentityFirstStage, AutoencoderKL File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\autoencoder.py", line 6, in from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ImportError: cannot import name 'VectorQuantizer2' from 'taming.modules.vqvae.quantize' (C:\Users\Conda\envs\tf-gpu\lib\site-packages\taming\modules\vqvae\quantize.py)

This looks a little "detailed" . How do I move forward again? Thanks

---------- Forwarded message --------- From: Bill Strum @.> Date: Sun, Sep 11, 2022 at 4:45 PM Subject: Re: [CompVis/stable-diffusion] ldm module not found in txt2img (Issue #261) To: CompVis/stable-diffusion < @.> Cc: CompVis/stable-diffusion @.>, Author < @.>

Slowly but hopefully surely we are moving forward.

Looks like a little progress but...

PS C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms Loading model from models/ldm/stable-diffusion-v1/model.ckpt Global Step: 470000 Traceback (most recent call last): File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 345, in main() File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 241, in main model = load_model_from_config(config, f"{opt.ckpt}") File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\txt2img.py", line 55, in load_model_from_config model = instantiate_from_config(config.model) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\diffusion\ddpm.py", line 24, in from ldm.models.autoencoder import VQModelInterface, IdentityFirstStage, AutoencoderKL File "C:\Users\Conda\ldm\stable-diffusion-main\scripts\ldm\models\autoencoder.py", line 6, in from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer ModuleNotFoundError: No module named 'taming'

What do I do now? Am I getting close??

On Sun, Sep 11, 2022 at 2:09 PM Rickey Bowers Jr. @.***> wrote:

The intent is to use the scripts from the parent directory:

C:\Users\Conda\ldm\stable-diffusion-main> python scripts\txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms

... in this way the other interfaces have proper hierarchy.

Please, restore the repo and use in the expected fashion.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1243014474, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRUIXEQX2EBSKMYFX7ITV5YN4NANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

bitRAKE commented 1 year ago

Your installation is incomplete.

After you install anaconda, you need to install git. Otherwise, conda env create -f environment.yaml will not complete. Their directions are geared toward linux users, imho.

Did you notice an error at the end of environment creation, or is this another thing?

Bstrum36 commented 1 year ago

This was another thing. I forwarded the initial issue.

ImportError: cannot import name 'VectorQuantizer2' from 'taming.modules.vqvae.quantize' (C:\Users\Conda\envs\tf-gpu\lib\site-packages\taming\modules\vqvae\quantize.py)

I'm pretty deep into this as you can see. I went through the created environment and I dont think it worked.

Currently my development environment consists of starting conda pointing to the tf--gpu environment I have been currently using with great success on my tensor flow and torch projects

I launch the comda cmd prompt from conda and then launch pycharm

So if I do go back and try the create environment should I be an existenting env?

On Sun, Sep 11, 2022 at 7:36 PM Rickey Bowers Jr. @.***> wrote:

Your installation is complete.

After you install anaconda, you need to install git. Otherwise, conda env create -f environment.yaml will not complete. Their directions are geared toward linux users, imho.

Did you notice an error at the end of environment creation, or is this another thing?

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1243068508, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRUOGMISW5L2CYU7YGCTV5ZUH3ANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

bitRAKE commented 1 year ago

Anaconda starts with a (base) environment, but being in another environment is fine as long as the git command works. You can try it, and get a help message from git.

Environment creation for stable diffusion will make another environment: (ldm). The name of which is defined at the top of: https://github.com/CompVis/stable-diffusion/blob/69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc/environment.yaml#L1

My current thinking is that you don't have git. Which means you are very close to having it fixed. conda install -c anaconda git It'll gather some info and install git, correcting the problem.

git clone https://github.com/CompVis/stable-diffusion monkey
cd monkey
copy ..\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt
conda env create -f environment.yaml
conda activate ldm
python optimizedSD\optimized_img2img.py --skip_grid --from-file "..\prompts.txt" --init-img "..\init.png" --strength 0.79 --outdir ".." --W 1280 --H 1280 --ddim_steps 40 --scale 7.5 --n_samples 1

Assuming you wanted to run from the monkey directory, and you've downloaded the model file into where the command prompt starts.

You'll probably need to do conda env remove -n ldm first though to remove the previous attempt - that's broken.

Bstrum36 commented 1 year ago

You were right. Idid not have git on my new computer.

I have installed git cloned the repo The contents of monkey are shown below

Directory of C:\Users\Conda\HelloWorld\monkey

09/12/2022 03:21 PM

. 09/12/2022 03:21 PM .. 09/12/2022 03:21 PM assets 09/12/2022 03:21 PM configs 09/12/2022 03:21 PM data 09/12/2022 03:21 PM 765 environment.yaml 09/12/2022 03:21 PM ldm 09/12/2022 03:21 PM 14,467 LICENSE 09/12/2022 03:21 PM 28,916 main.py 09/12/2022 03:21 PM models 09/12/2022 03:21 PM 10,368 notebook_helpers.py 09/12/2022 03:21 PM 12,656 README.md 09/12/2022 03:21 PM scripts 09/12/2022 03:21 PM 245 setup.py 09/12/2022 03:21 PM 9,488 Stable_Diffusion_v1_Model_Card.md 7 File(s) 76,905 bytes 8 Dir(s) 801,861,029,888 bytes free

and when I do the copy i get the following: (tf-gpu) C:\Users\Conda\HelloWorld\monkey>copy ..\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt The system cannot find the file specified.

One step forward, one step back. Please advise

On Mon, Sep 12, 2022 at 2:28 PM Rickey Bowers Jr. @.***> wrote:

Anaconda starts with a (base) environment, but being in another environment is fine as long as the git command works. You can try it, and get a help message from git.

Environment creation for stable diffusion will create make another environment: (ldm). The name of which is defined at the top of:

https://github.com/CompVis/stable-diffusion/blob/69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc/environment.yaml#L1

My current thinking is that you don't have git. Which means you are very close to having it fixed. conda install -c anaconda git It'll gather some info and install git, correcting the problem.

git clone https://github.com/CompVis/stable-diffusion monkeycd monkeycopy ..\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt conda env create -f environment.yaml conda activate ldm python optimizedSD\optimized_img2img.py --skip_grid --from-file "..\prompts.txt" --init-img "..\init.png" --strength 0.79 --outdir ".." --W 1280 --H 1280 --ddim_steps 40 --scale 7.5 --n_samples 1

Assuming you wanted to run from the monkey directory, and you've downloaded the model file into where the command prompt starts.

— Reply to this email directly, view it on GitHub https://github.com/CompVis/stable-diffusion/issues/261#issuecomment-1244133347, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2XRULLF5I2ELENJFNGHWLV55Y5BANCNFSM6AAAAAAQJQ5XH4 . You are receiving this because you authored the thread.Message ID: @.***>

bitRAKE commented 1 year ago

Oh, so you haven't downloaded the model from HugginFace? It's a huge 4GB file - couldn't miss it:

https://github.com/CompVis/stable-diffusion#stable-diffusion-v1

Weights are here: https://huggingface.co/CompVis/stable-diffusion-v-1-4-original

The sd-v1-4.ckpt file will need to be copied to the correct location, and renamed to model.ckpt.

...and then it's smooth sailing.

(Other models will be release in time - sd-v1-5.ckpt is being tested for release.)

NickelCoating commented 1 year ago

Such issues could be avoided by using a real programming language (compiled language instead interpreted) for CLI (Command Line Interface) applications.

If you want SD to use another language and it does not have to be Rust. Then perhaps let the developers know on my rather long rant about this issue: https://github.com/CompVis/stable-diffusion/issues/283

bitRAKE commented 1 year ago

Yes, Python is showing it's age in this regard. It is a different ecosystem which comes with it's own learning curve beyond the language itself.

Cyberes commented 1 year ago

Such issues could be avoided by using a real programming language (compiled language instead interpreted) for CLI (Command Line Interface) applications.

But then again. I do not get how it works. Why did this person even bother to write this comment? Does he know that Rust is an actual compiled language and therefore no longer has the problems described in these comments? Or does he simply want to bash other languages without actually knowing what he is talking about?

TBoehm commented 1 year ago

FYI at least for me (linux on google cloud) using a symlink to the model.ckpt file didn't work. By copying the model with the proper name to the right folder (models/ldm/text2img-large/model.ckpt for example) it worked.

sarang13579 commented 1 year ago

Anaconda starts with a (base) environment, but being in another environment is fine as long as the git command works. You can try it, and get a help message from git.

Environment creation for stable diffusion will make another environment: (ldm). The name of which is defined at the top of:

https://github.com/CompVis/stable-diffusion/blob/69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc/environment.yaml#L1

My current thinking is that you don't have git. Which means you are very close to having it fixed. conda install -c anaconda git It'll gather some info and install git, correcting the problem.

git clone https://github.com/CompVis/stable-diffusion monkey
cd monkey
copy ..\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt
conda env create -f environment.yaml
conda activate ldm
python optimizedSD\optimized_img2img.py --skip_grid --from-file "..\prompts.txt" --init-img "..\init.png" --strength 0.79 --outdir ".." --W 1280 --H 1280 --ddim_steps 40 --scale 7.5 --n_samples 1

Assuming you wanted to run from the monkey directory, and you've downloaded the model file into where the command prompt starts.

You'll probably need to do conda env remove -n ldm first though to remove the previous attempt - that's broken.

Thanks this solution solves my problems