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

Python interface for loading super-resolution dataset #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AnimatedRNG
Copy link

This custom PyTorch Dataset loads images from a
folder, performs several image operations upon
them, and then returns patches to the caller.
To avoid expensive disk reads/writes, all of the
images are cached in memory in compressed form,
and then decompressed and cached as the iterator
iterates over them.

@AnimatedRNG AnimatedRNG changed the title Python interface for loading super-resolution Dataset Python interface for loading super-resolution dataset Jan 1, 2019
@twtygqyy
Copy link
Owner

twtygqyy commented Jan 2, 2019

Thanks for the PR @AnimatedRNG
I will take a look.

@AnimatedRNG
Copy link
Author

@twtygqyy Awesome. I just pushed a few minor tweaks and fixes (changed the cache size, disabled shuffle). I mostly wrote this because my desktop doesn't have enough memory to run the Matlab script to create the dataset. I haven't actually trained using this method, but I'm running it right now and hopefully I'll get something similar to your pretrained model.

To perform bicubic interpolation directly on tensors, you need the nightly build of Pytorch.

I'm also using OpenCV for image augmentation and color conversions. I think you can probably replace some of these operations with numpy/PyTorch equivalents if needed.

Also, I just realized that this model doesn't seem to operate in a linear colorspace -- maybe once I get things working I'll make the dataset also convert the images from/to sRGB.

This custom PyTorch Dataset loads images from a
folder, performs several image operations upon
them, and then returns patches to the caller.
To avoid expensive disk reads/writes, all of the
images are cached in memory in compressed form,
and then decompressed and cached as the iterator
iterates over them.
@AnimatedRNG
Copy link
Author

The image augmentation now uses PyTorch's API rather than OpenCV. torch.flip is unreasonably slow, but otherwise I'm noticing a substantial performance improvement over the old version.

@AnimatedRNG
Copy link
Author

On a different note, I finished training on DIV2K using this method and I was unable to replicate your results. I haven't looked much in eval.py, so maybe I'm wrong, but I'm somewhat confused about the PSNR scores (the model trained for 1 epochs did better (22.923043055308984) than the one trained for 100 epochs (22.68411311135478), despite a clear improvement in image quality in the latter case). Perhaps you should also print out the SSIM?

For reference, here is the butterfly demo after 1 epoch of training:

1_epoch

and after 100 epochs:

100_epoch

For reference, here is how your pre-trained model looks:

pre-trained

@twtygqyy
Copy link
Owner

twtygqyy commented Jan 7, 2019

Hi @AnimatedRNG if you used PyTorch API to generate the data for training, and use Matlab generated data for evaluation, the script cannot output correct PSNR sore. The reason is due the different bicubic interpolation implementation between Matlab and python. Check out https://www.reddit.com/r/MachineLearning/comments/6vdo51/p_matlab_bicubic_imresize_implemented_in_python/ for more information.

@AnimatedRNG
Copy link
Author

Ah, good point. I'll try generating some of my own bicubic-downsampled images and seeing if the results get any better.

I'd rather use PyTorch's bicubic downsample than Matlab's (or the imresize Python implementation that you mentioned), mostly for performance reasons. PyTorch's bicubic downsample also happens to be compatible with OpenCV's bicubic downsample, which is another plus.

So I'll either generate new .mat's for the demo/evaluation scripts or just load them as PNGs.

@twtygqyy
Copy link
Owner

@AnimatedRNG Thanks for the update. I think for this repo, the purpose is for reproducing paper result, thus Matlab preprocessing was applied for consistency so as to have a fair comparison with the paper. Ideally, I agree it is better to use bicubic without anti-aliasing for practical use.

@leonardozcm
Copy link

Hey,I'm glad to inform you that your suggests really work!!!
I write a python script to generate trainable dataset, sooner I will commit it for further usage.

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

Successfully merging this pull request may close these issues.

3 participants