GuHuangAI / DiffusionEdge

Code for AAAI 2024 paper: "DiffusionEdge: Diffusion Probabilistic Model for Crisp Edge Detection"
Apache License 2.0
236 stars 25 forks source link

error #16

Open LooperzZ opened 8 months ago

LooperzZ commented 8 months ago

Traceback (most recent call last): File "D:\Python_code\DiffusionEdge-main\demo.py", line 346, in main(args) File "D:\Python_code\DiffusionEdge-main\demo.py", line 124, in main results_folder=sampler_cfg.save_folder, cfg=cfg, File "D:\Python_code\DiffusionEdge-main\demo.py", line 173, in init sd = data['ema'] KeyError: 'ema'

GuHuangAI commented 8 months ago

Please show the running command, and I'll check if there is a bug.

zhaoaite commented 2 months ago

I have the same problem. First I run the xxx_train.yaml to train my own data, and generate a '.pt' file, then run xxx_sample.yaml to test, make use_ema: True, but it dosen't work. KeyError: 'ema' if I change use_ema to False, It also can not process the testing imag.

GuHuangAI commented 2 months ago

@zhaoaite Did you train the two stages? Please give more detailed information about your training.

GuHuangAI commented 2 months ago

@zhaoaite you can check the 'ema' setting in this file. If the 'enable_resume' is False, the ema model will not be saved.

zhaoaite commented 2 months ago

1. accelerate launch train_cond_ldm.py --cfg ./configs/BIPED_train.yaml 2.python demo.py --cfg ./configs/BIPED_sample.yaml --input_dir data --pre_weight test_results/model-2.pt --out_dir test_results --bs 8        

The model-2.pt is the generated weight. How to train the two stages? can you provide the steps? Thank you!

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2024年8月28日(星期三) 中午1:24 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [GuHuangAI/DiffusionEdge] error (Issue #16)

@zhaoaite you can check the 'ema' setting in this file

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

GuHuangAI commented 2 months ago

@zhaoaite Please follow the readme file. If you do not want to train the first stage model ,you can also use the pretrained weight that we release here. If you have trained the second stage model, please show the errors when you run the demo.py.

zhaoaite commented 2 months ago

Hi,After I trained the two stages and save the two pt file, I run the test code again "python demo.py --cfg  H:\research\DiffusionEdge-main\configs\BIPED_sample.yaml --input_dir ./data --pre_weight H:/research/DiffusionEdge-main/test_results/model-stage2.pt --out_dir test_results --bs 8", but there is another error.

" sd = torch.load(path, map_location="cpu") Restored from H:/research/DiffusionEdge-main/test_results/model-15-first.pt ==>Load AutoEncoder Info:  <All keys matched successfully> E:\Coding_app\anaconda3\envs\diffedge\lib\site-packages\torchvision\models_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=Swin_B_Weights.IMAGENET1K_V1. You can also use weights=Swin_B_Weights.DEFAULT to get the most up-to-date weights.   warnings.warn(msg) E:\Coding_app\anaconda3\envs\diffedge\lib\site-packages\torch\functional.py:513: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\actions-runner_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\TensorShape.cpp:3610.)   return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined] Load swin_transformer: <All keys matched successfully> swin H:\research\DiffusionEdge-main\denoising_diffusion_pytorch\ddm_const_sde.py:954: FutureWarning: torch.cuda.amp.custom_fwd(args...) is deprecated. Please use torch.amp.custom_fwd(args..., device_type='cuda') instead.   def forward(ctx, input_tensor, gt_grad): H:\research\DiffusionEdge-main\denoising_diffusion_pytorch\ddm_const_sde.py:961: FutureWarning: torch.cuda.amp.custom_bwd(args...) is deprecated. Please use torch.amp.custom_bwd(args..., device_type='cuda') instead.   def backward(ctx, grad_scale):

WEIGHTING LOSS

H:\research\DiffusionEdge-main\demo.py:167: FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.   data = torch.load(cfg.sampler.ckpt_path, map_location=lambda storage, loc: storage) Traceback (most recent call last):   File "H:\research\DiffusionEdge-main\demo.py", line 344, in <module>     main(args)   File "H:\research\DiffusionEdge-main\demo.py", line 119, in main     sampler = Sampler(   File "H:\research\DiffusionEdge-main\demo.py", line 180, in init     model.load_state_dict(data['model'])   File "E:\Coding_app\anaconda3\envs\diffedge\lib\site-packages\torch\nn\modules\module.py", line 2215, in load_state_dict     raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for LatentDiffusion:"

Please check the error code. thx!

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2024年8月28日(星期三) 中午1:43 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [GuHuangAI/DiffusionEdge] error (Issue #16)

@zhaoaite Please follow the readme file. If you do not want to train the first stage model ,you can also use the pretrained weight that we release here. If you have trained the second stage model, please show the errors when you run the demo.py.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

GuHuangAI commented 2 months ago

The error occurs when running model.load_state_dict(data['model']). I don't see the reason. Can you check if the data dictionary has a key named 'model'?

zhaoaite commented 2 months ago

Hi 

This problem has been solved.    This is a model loading error.   Demo.py line 180, change 'model.load_state_dict(data['model'])' to model.load_state_dict(data['model'],strict=False). Thank you!

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2024年8月28日(星期三) 下午2:48 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [GuHuangAI/DiffusionEdge] error (Issue #16)

The error occurs when running model.load_state_dict(data['model']). I don't see the reason. Can you check if the data dictionary has a key named 'model'?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>