sjtuplayer / anomalydiffusion

[AAAI 2024] AnomalyDiffusion: Few-Shot Anomaly Image Generation with Diffusion Model
MIT License
138 stars 19 forks source link

instantiate_from_config function - issue #5

Open CVKim opened 6 months ago

CVKim commented 6 months ago

The above error occurs, how can I solve it? It is expected to occur in the instantiate_from_config function, and the values that exist inside the model seem to be different.

model.ckpt

Error Log : Unexpected Keys: ['model_ema.decay', 'model_ema.num_updates']

sjtuplayer commented 6 months ago

Could you please show me the whole error log?

CVKim commented 6 months ago

E+00000.155: Error while enumerating installed packages.

         Traceback (most recent call last):
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 361, in get_environment_description
             report("    {0}=={1}\n", pkg.name, pkg.version)
         AttributeError: 'PathDistribution' object has no attribute 'name'

         Stack where logged:
           File "/opt/conda/lib/python3.8/runpy.py", line 194, in _run_module_as_main
             return _run_code(code, main_globals, None,
           File "/opt/conda/lib/python3.8/runpy.py", line 87, in _run_code
             exec(code, run_globals)
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
             cli.main()
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
             run()
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 281, in run_file
             log.describe_environment("Pre-launch environment:")
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 369, in describe_environment
             info("{0}", get_environment_description(header))
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 363, in get_environment_description
             swallow_exception("Error while enumerating installed packages.")
           File "/root/.vscode-server/extensions/ms-python.debugpy-2024.0.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 215, in swallow_exception
             _exception(format_string, *args, **kwargs)

Global seed set to 23 Loading model from /User/anomalydiffusion/models/ldm/text2img-large/model.ckpt Backend TkAgg is interactive backend. Turning interactive mode on. LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 872.30 M params. making attention of type 'vanilla' with 512 in_channels Working with z of shape (1, 4, 32, 32) = 4096 dimensions. making attention of type 'vanilla' with 512 in_channels Restored from /User/anomalydiffusion/models/ldm/text2img-large/model.ckpt with 0 missing and 2 unexpected keys Unexpected Keys: ['model_ema.decay', 'model_ema.num_updates']

image

sjtuplayer commented 6 months ago

It seems to be the mismatch version between imgaug and numpy. You can try installing imgaug=0.4.0

CVKim commented 6 months ago

Exception has occurred: NameError name 'trainer' is not defined File "/User/anomalydiffusion/main.py", line 648, in model = load_model_from_config(config, osp.join(ROOT, opt.actual_resume)) File "/User/anomalydiffusion/main.py", line 32, in load_model_from_config model = instantiate_from_config(config.model) File "/User/anomalydiffusion/ldm/util.py", line 86, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/User/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 500, in init self.embedding_manager = self.instantiate_embedding_manager(personalization_config, self.cond_stage_model) File "/User/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 578, in instantiate_embedding_manager model = instantiate_from_config(config, embedder=embedder) File "/User/anomalydiffusion/ldm/util.py", line 86, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/User/anomalydiffusion/ldm/util.py", line 94, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "/User/anomalydiffusion/ldm/modules/embedding_manager2.py", line 4, in from ldm.data.personalized import per_img_token_list File "/User/anomalydiffusion/ldm/data/personalized.py", line 10, in from .mask_generate import generate_mask File "/User/anomalydiffusion/ldm/data/mask_generate.py", line 4, in import imgaug.augmenters as iaa ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

During handling of the above exception, another exception occurred:

File "/User/anomalydiffusion/main.py", line 891, in if trainer.global_rank == 0: NameError: name 'trainer' is not defined


I reinstalled it using pip install imgaug==0.4.0, but the same error occurred!

sjtuplayer commented 6 months ago

Then it may come from the version of numpy and python. Do you use python==3.8 and numpy==1.23.1?

CVKim commented 6 months ago

numpy - 1.19.2 python - 3.8.5

I'm using it as above!

xuyu666 commented 6 months ago

I'm having the same problem, along with ninja configuration issues (didn't think of a good solution), can the author give some advice?


Environment:

python==3.8.5 numpy==1.23.1 imgaug==0.4.0


Error information:

Global seed set to 23 Running on GPUs 0, Loading model from models/ldm/text2img-large/model.ckpt LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 872.30 M params. making attention of type 'vanilla' with 512 in_channels Working with z of shape (1, 4, 32, 32) = 4096 dimensions. making attention of type 'vanilla' with 512 in_channels Restored from models/ldm/text2img-large/model.ckpt with 0 missing and 2 unexpected keys Unexpected Keys: ['model_ema.decay', 'model_ema.num_updates'] Traceback (most recent call last): File "main.py", line 645, in model = load_model_from_config(config, opt.actual_resume) File "main.py", line 30, in load_model_from_config model = instantiate_from_config(config.model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 500, in init self.embedding_manager = self.instantiate_embedding_manager(personalization_config, self.cond_stage_model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 578, in instantiate_embedding_manager model = instantiate_from_config(config, embedder=embedder) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/modules/embedding_manager2.py", line 8, in from ldm.models.psp_encoder.encoders import psp_encoders File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/encoders/psp_encoders.py", line 8, in from ..stylegan2.model import EqualLinear File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/model.py", line 7, in from .op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/init.py", line 1, in from .fused_act import FusedLeakyReLU, fused_leaky_relu File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/fused_act.py", line 9, in fused = load( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1202, in load return _jit_compile( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1425, in _jit_compile _write_ninja_file_and_build_library( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1506, in _write_ninja_file_and_build_library verify_ninja_availability() File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1562, in verify_ninja_availability raise RuntimeError("Ninja is required to load C++ extensions") RuntimeError: Ninja is required to load C++ extensions

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 888, in if trainer.global_rank == 0: NameError: name 'trainer' is not defined

sgw-ite commented 6 months ago

I'm having the same problem, along with ninja configuration issues (didn't think of a good solution), can the author give some advice?

Environment:

python==3.8.5 numpy==1.23.1 imgaug==0.4.0

Error information:

Global seed set to 23 Running on GPUs 0, Loading model from models/ldm/text2img-large/model.ckpt LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 872.30 M params. making attention of type 'vanilla' with 512 in_channels Working with z of shape (1, 4, 32, 32) = 4096 dimensions. making attention of type 'vanilla' with 512 in_channels Restored from models/ldm/text2img-large/model.ckpt with 0 missing and 2 unexpected keys Unexpected Keys: ['model_ema.decay', 'model_ema.num_updates'] Traceback (most recent call last): File "main.py", line 645, in model = load_model_from_config(config, opt.actual_resume) File "main.py", line 30, in load_model_from_config model = instantiate_from_config(config.model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 500, in init self.embedding_manager = self.instantiate_embedding_manager(personalization_config, self.cond_stage_model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 578, in instantiate_embedding_manager model = instantiate_from_config(config, embedder=embedder) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/modules/embedding_manager2.py", line 8, in from ldm.models.psp_encoder.encoders import psp_encoders File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/encoders/psp_encoders.py", line 8, in from ..stylegan2.model import EqualLinear File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/model.py", line 7, in from .op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/init.py", line 1, in from .fused_act import FusedLeakyReLU, fused_leaky_relu File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/fused_act.py", line 9, in fused = load( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1202, in load return _jit_compile( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1425, in _jit_compile _write_ninja_file_and_build_library( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1506, in _write_ninja_file_and_build_library verify_ninja_availability() File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1562, in verify_ninja_availability raise RuntimeError("Ninja is required to load C++ extensions") RuntimeError: Ninja is required to load C++ extensions

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 888, in if trainer.global_rank == 0: NameError: name 'trainer' is not defined

i have the same problem

sjtuplayer commented 6 months ago

I'm having the same problem, along with ninja configuration issues (didn't think of a good solution), can the author give some advice?

Environment:

python==3.8.5 numpy==1.23.1 imgaug==0.4.0

Error information:

Global seed set to 23 Running on GPUs 0, Loading model from models/ldm/text2img-large/model.ckpt LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 872.30 M params. making attention of type 'vanilla' with 512 in_channels Working with z of shape (1, 4, 32, 32) = 4096 dimensions. making attention of type 'vanilla' with 512 in_channels Restored from models/ldm/text2img-large/model.ckpt with 0 missing and 2 unexpected keys Unexpected Keys: ['model_ema.decay', 'model_ema.num_updates'] Traceback (most recent call last): File "main.py", line 645, in model = load_model_from_config(config, opt.actual_resume) File "main.py", line 30, in load_model_from_config model = instantiate_from_config(config.model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 500, in init self.embedding_manager = self.instantiate_embedding_manager(personalization_config, self.cond_stage_model) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/diffusion/ddpm.py", line 578, in instantiate_embedding_manager model = instantiate_from_config(config, embedder=embedder) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict()), kwargs) File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/util.py", line 93, in get_obj_from_str return getattr(importlib.import_module(module, package=None), cls) File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/modules/embedding_manager2.py", line 8, in from ldm.models.psp_encoder.encoders import psp_encoders File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/encoders/psp_encoders.py", line 8, in from ..stylegan2.model import EqualLinear File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/model.py", line 7, in from .op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/init.py", line 1, in from .fused_act import FusedLeakyReLU, fused_leaky_relu File "/home/xuyu/xuyu_model/AnomalyDiffusion/anomalydiffusion/ldm/models/psp_encoder/stylegan2/op/fused_act.py", line 9, in fused = load( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1202, in load return _jit_compile( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1425, in _jit_compile _write_ninja_file_and_build_library( File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1506, in _write_ninja_file_and_build_library verify_ninja_availability() File "/home/xuyu/.conda/envs/Anomalydiffusion/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1562, in verify_ninja_availability raise RuntimeError("Ninja is required to load C++ extensions") RuntimeError: Ninja is required to load C++ extensions During handling of the above exception, another exception occurred: Traceback (most recent call last): File "main.py", line 888, in if trainer.global_rank == 0: NameError: name 'trainer' is not defined

i have the same problem

It seems to be the lack of Ninja, you can just try installing Ninja.

xuyu666 commented 6 months ago

Hiiii, after installing ninja, this error is reported, is it still necessary to configure the c++ related environment, such as installing VS and configuring environment variables?

image

sjtuplayer commented 6 months ago

Hiiii, after installing ninja, this error is reported, is it still necessary to configure the c++ related environment, such as installing VS and configuring environment variables?

image

Hi! The problem of Ninja is usually because of the Windows system. And you should also ensure the cuda version>10.0. To find how to install ninja on Windows, you can refer to https://github.com/rosinality/stylegan2-pytorch/issues/63 or https://github.com/rosinality/stylegan2-pytorch/issues/1.

xuyu666 commented 6 months ago

Ok thanks, I'll try it first and see if I can fix it myself. ps:I tried it in ubuntu first as well and I also get some errors about ninja, I'm not familiar with c++ so I'm still struggling a bit~

xuyu666 commented 6 months ago

Sorry, I really can't solve this ninja configuration problem (Win and Ubuntu environments), ubuntu final result is shown below, it seems to need cuda10.0 version and other conditions to run? Can the author follow up with a docker environment? Thank you for your time. image

sjtuplayer commented 6 months ago

Sorry, I really can't solve this ninja configuration problem (Win and Ubuntu environments), ubuntu final result is shown below, it seems to need cuda10.0 version and other conditions to run? Can the author follow up with a docker environment? Thank you for your time. image

I have encountered this problem in Ubuntu before and it comes from the mismatch version of cuda and gcc. You can follow my environment setting. cuda: 11.8 cudnn: 8 gcc: 7 Hope it works for you!

tianzhijiaoziA commented 6 months ago

Hi! The above issue seems to have persisted after I installed Ninja using pip 企业微信截图_20240304143352

duanyuanyi commented 5 months ago

你好!在我使用 pip 安装 Ninja 后,上述问题似乎仍然存在 企业微信截图_20240304143352

你好,我的问题和你的相同,你有解决吗?

xuyu666 commented 5 months ago

暂时解决了,我是这么处理的:

主要解决思路是保持conda内外部cuda版本的统一。 1、本机装了cuda11.8 + gcc 7.5。 2、在conda环境里装匹配cuda11.8的torch。

duanyuanyi commented 5 months ago

暂时解决了,我是这么处理的:

主要解决思路是保持conda内外部cuda版本的统一。 1、本机装了CUDA11.8 + GCC 7.5。 2、在conda环境里装匹配cuda11.8的torch。

谢谢,确实是gcc的问题

lsxwtt commented 4 months ago

暂时解决了,我是这么处理的:

主要解决思路是保持conda内外部cuda版本的统一。 1、本机装了cuda11.8 + gcc 7.5。 2、在conda环境里装匹配cuda11.8的torch。

您好,我遇到了相同的问题,请问您安装的是那个pytorch和ninja版本呀?

boxbox2 commented 2 months ago

你好!在我使用 pip 安装 Ninja 后,上述问题似乎仍然存在 企业微信截图_20240304143352

你好,我的问题和你的相同,你有解决吗?

image image

我虽然显示缺少了Unexpected key(s) in state_dict: "model_ema.decay", "model_ema.num_updates",但还是能正常运行但sample_scaled_gs和condition_gs是这样的图片正常吗?