KupynOrest / DeblurGAN

Image Deblurring using Generative Adversarial Networks
Other
2.52k stars 521 forks source link

Train your own dataset #222

Open hydwjy opened 2 years ago

hydwjy commented 2 years ago

I want to train my dataset and what to do

Ahmadreza1365 commented 1 year ago

If you have your own dataset, you need to prepare them as follow: let's say you have a folder called "blurred_sharp" in the directory that you cloned "DeblurGAN-master". you make two sub-folders and let's call them "blurred" and "sharp". In each of these folders, again you need to make two subfolders and call them "train" and "test". So now you have:

-DeblurGAN-master

- blurred_sharp

  - blurred
      - train
      - test

  - sharp
      - train
      - test

You need to put your sharp and blurred images in these folders accordingly. Make sure for example, when you put the blurred image, in the "..\blurred\train" folder, you put it's associate sharp image in "..\sharp\train" folder.

Now you need to create another folder, let's call it "combine" and put it in the following directory: ..\DeblurGAN-master\blurred_sharp\combine

via cmd or VScode (any platform that you are using) go to the "DeblurGAN-master" folder and "run combine_A_and_B.py". below is an example:

python datasets/combine_A_and_B.py --fold_A "C:\TEMP\DeblurGAN-master\blurred_sharp\blurred" --fold_B "C:\TEMP\DeblurGAN-master\blurred_sharp\sharp" --fold_AB "C:\TEMP\DeblurGAN-master\blurred_sharp\combine"

It will create two subfolders (train and test) in the "combine" folder that you created earlier. You will see the blurred and sharp images concatenated.


Now make sure you have visdom package correctly installed in your python. Then open cmd and run:

python -m visdom.server

you will probably get the following message:


Checking for scripts. It's Alive! INFO:root:Application Started INFO:root:Working directory: C:\Users\u109980.visdom You can navigate to http://localhost:8097

Then copy/paste "http://localhost:8097" in your browser to be able to monitor the training progress.

now you can run the following code for training:

python train.py --dataroot "C:\TEMP\DeblurGAN-master\blurred_sharp\combine" --learn_residual --resize_or_crop crop --fineSize 256


When the training is completed after 300 epochs, put your test images in a folder (let's say "..\DeblurGAN-master\TEST" ). Now you can test it with the following command.

python test.py --dataroot "C:\TEMP_TEST\DeblurGAN-master\TEST" --model test --dataset_mode single --learn_residual

remember if your device cannot handle parallel processing, in the "test.py" change the number of threads to zero as follow: opt.nThreads = 0

CaseinBrt commented 2 months ago

We can't get the result of deblur type after testing a blurry image. What should we do? do we need to combine a blurry and sharp image like in the process of training? Also is it possible to select particular region only of the image to deblur? something like comparative between an entire image and the selected part region of the image, thank you!

below our own test image that showed in the results after testing it.

image

image image