models icon indicating copy to clipboard operation
models copied to clipboard

Super resolution model test

Open nyanmn opened this issue 3 years ago • 0 comments

The following code was used in testing super resolution model.

orig_img = Image.open("midge_header_2.jpg")
img = resizeimage.resize_cover(orig_img, [224,224], validate=False)
img_ycbcr = img.convert('YCbCr')
img_y_0, img_cb, img_cr = img_ycbcr.split()
img_ndarray = np.asarray(img_y_0)

img_4 = np.expand_dims(np.expand_dims(img_ndarray, axis=0), axis=0)
img_5 = img_4.astype(np.float32) / 255.0


ort_session = onnxruntime.InferenceSession("model/super-resolution-10/super_resolution/super_resolution.onnx")
ort_inputs = {ort_session.get_inputs()[0].name: img_5} 
ort_outs = ort_session.run(None, ort_inputs)
img_out_y = ort_outs[0]

img_out_y = Image.fromarray(np.uint8((img_out_y[0] * 255.0).clip(0, 255)[0]), mode='L')
# get the output image follow post-processing step from PyTorch implementation
final_img = Image.merge(
    "YCbCr", [
        img_out_y,
        img_cb.resize(img_out_y.size, Image.BICUBIC),
        img_cr.resize(img_out_y.size, Image.BICUBIC),
    ]).convert("RGB")
#plt.imshow(final_img)
plt.figure(figsize=(20, 10))

images = [orig_img, final_img]
titles = ['LR', f'SR (x{final_img.size[0] // orig_img.size[0]})']

for i, (img, title) in enumerate(zip(images, titles)):
   plt.subplot(1, 2, i+1)
   plt.imshow(img)
   plt.title(title)
   plt.xticks([])
   plt.yticks([])
plt.savefig('sample_detection.png', bbox_inches='tight')

Not very sure what parameter to modify. But the output image was not full image as original and resolution is not good. The output image is blur. What could be the problem?

You can see input and output image here

The test image to test is here.

nyanmn avatar Oct 14 '20 05:10 nyanmn