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

The Generated Images Contain a Lot of Noise #11

Closed
Shi5013 opened this issue Jul 23, 2024 · 7 comments
Closed

The Generated Images Contain a Lot of Noise #11

Shi5013 opened this issue Jul 23, 2024 · 7 comments

Comments

@Shi5013
Copy link

Shi5013 commented Jul 23, 2024

Hello, @nickk124 . Thank you for your exciting work!
I ran your code on my own dataset, but the images output in the ./ddim-{dataset}-256-segguided/samples folder contain a lot of noise. I would greatly appreciate any advice you could offer. Here are the details of my training:

CUDA_VISIBLE_DEVICES=0,1 python3 main.py \
    --mode train \
    --model_type DDIM \
    --img_size 256 \
    --num_img_channels 1 \
    --dataset Liver_4DCT \
    --img_dir ./data \
    --seg_dir ./seg_data \
    --segmentation_guided \
    --num_segmentation_classes 2 \
    --train_batch_size 8 \
    --eval_batch_size 4 \
    --num_epochs 200

img_v3_02d1_26410a5f-54be-446a-aeef-748ced5f663g
img_v3_02d1_7bd83271-45d3-4d71-a7e9-ead0bc4ddc3g
img_v3_02d1_91d2f868-cbff-48cd-8de6-6a5d057ba14g
img_v3_02d1_33de5d9d-982b-42e2-90cb-b3fa93ce86ag

By the way, during the first training, I encountered the following error when saving the safetensor file at the 30th epoch:

File "/media/user_gou/Elements/Shi/diffusion/main.py", line 418, in <module>
    main(
  File "/media/user_gou/Elements/Shi/diffusion/main.py", line 341, in main
    train_loop(
  File "/media/user_gou/Elements/Shi/diffusion/training.py", line 203, in train_loop
    pipeline.save_pretrained(config.output_dir)
  File "/home/user_gou/anaconda3/envs/voxelmorph/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 661, in save_pretrained
    save_method(os.path.join(save_directory, pipeline_component_name), **save_kwargs)
  File "/home/user_gou/anaconda3/envs/voxelmorph/lib/python3.10/site-packages/diffusers/models/modeling_utils.py", line 361, in save_pretrained
    safetensors.torch.save_file(
AttributeError: module 'safetensors' has no attribute 'torch'

However, I have since modified the code and re-ran it, and this error no longer occurs.

@nickk124
Copy link
Member

Hi!

For your first question, how many epochs did you train for? I've noticed that for some datasets, it can take 100, 200 or even more epochs until the noisyness in the images goes away.

For your second question, my apologies for the bug! Can I ask, what fix you made?

Best,
Nick

@Shi5013
Copy link
Author

Shi5013 commented Jul 25, 2024

Thank you for your answer!
Regarding the first issue, I initially trained for only 30 epochs. I tried again and after training for 200 epochs, the noise in the images almost disappeared. It was my mistake.

Regarding the second issue, I don’t think it’s your mistake. After searching on Google, I found this:
safetensors_issues
image
Following their suggestion, I changed import safetensors to from safetensors.torch import load_file, save_file, and this resolved the issue. I’m not sure why it worked either.

@nickk124
Copy link
Member

Hi, where exactly did you change import safetensors to from safetensors.torch import load_file, save_file? I'd like to post about this potential bug on the README.

Otherwise, I think your issues are resolved so I'll go ahead and close this.
Thanks!

@Shi5013
Copy link
Author

Shi5013 commented Jul 26, 2024

The changes were made in the site-packages of the diffusers library within the Anaconda environment, specifically at the location indicated by the error message.

File "/home/user_gou/anaconda3/envs/voxelmorph/lib/python3.10/site-packages/diffusers/models/modeling_utils.py", line 361, in save_pretrained
    safetensors.torch.save_file(

In the import section of this file, change import safetensors to from safetensors.torch import load_file, save_file. Additionally, modify the calls to the two functions. Maybe on lines 109 and 361? (I'm not not sure the actually line because I have already modified.)

@nickk124
Copy link
Member

Ok, thanks so much for the help. I'll add it to the README!

@ssqrots
Copy link

ssqrots commented Dec 27, 2024

"Hello, could you please tell me specifically what changes should be made to line 109 and line 361?"

@Shi5013
Copy link
Author

Shi5013 commented Dec 28, 2024

Simply changed the way of function calling. In the previous file, because it was import safetensors, the usage on lines 109 and 361 was safetensors.torch.save_file(.

However, later I changed import safetensors to from safetensors.torch import load_file, save_file, so the prefix in the previous usage should be removed, and the function should be called directly as save_file(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants