huangzehao / caffe-vdsr

A Caffe-based implementation of very deep convolution network for image super-resolution
MIT License
273 stars 134 forks source link

Test code in pyCaffe/C++ #40

Closed ghost closed 4 years ago

ghost commented 7 years ago

Do anyone have the test code without matconvnet. I tried using python interface and I am not able to get good results. I am able to get good results using matconvnet and the given test code. But not for python interface. Seems like I have done something wrong in the data preprocessing. It would be great if anyone has done it already.

huangzehao commented 7 years ago

Hi, you can try PIL.Image.LANCZOS instead of BICUBIC to get better resize performance. Since PIL.Image.BICUBIC is worse than matlab's bicubic imresize, and I found LANCZOS is more comparable.

ghost commented 7 years ago

And do I have to add padding after output of every convolutional layers or I can take output directly from the last layer? Could you please post the test script if you have it. Thank you so much.

huangzehao commented 7 years ago

Hi, you can take output directly from the last layer. I am sorry that I don't have the test script in python.

ghost commented 7 years ago

Thank you for your reply. Here is my code :

import numpy as np import matplotlib.pyplot as plt import cv2 import caffe caffe.set_mode_gpu() net = caffe.Net('model/deploy.prototxt', 'model/vdsr.caffemodel',caffe.TEST)

input = cv2.imread('testImages/temp.jpg') input = cv2.cvtColor(input, cv2.COLOR_BGR2YCR_CB) input = input[:, :, 0] input = input.reshape(1, input.shape[0], input.shape[1]) out = net.forward_all(data = input.astype(float)/255) mat = out['sum'][0] output = mat.reshape(mat.shape[1], mat.shape[2])

If I use pyplot to show this image, it does not look nice. But if I convert this caffemodel to mat and test using your code, Its working fine. Could you please guide me to right direction.

sdlpkxd commented 6 years ago

In matlab, the Anti-Aliasing is default. And if you use PIL,there is no Anti-Aliasing. So the low resolution picture generated by imresize() in matlab is better. I also troubled by this before.

LucyLu-LX commented 6 years ago

@sdlpkxd What method of interpolation did you use in python to fix this problem? I tried INTER_CUBIC and INTER_LANCZOS4 in opencv. The result was terrible.

sdlpkxd commented 6 years ago

I use matlab imresize() to do data augmentation instead of opencv. You can use cv2.resize() in opencv2 instead.