image-super-resolution icon indicating copy to clipboard operation
image-super-resolution copied to clipboard

Upscaling transparent PNGs

Open santoshachari opened this issue 4 years ago • 3 comments

I am trying to upscale transparent png files like this one. slide25

It keeps failing with the following error.

2020-10-14 09:38:01.281548: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-10-14 09:38:01.295004: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fabf55fd880 executing computations on platform Host. Devices:
2020-10-14 09:38:01.295032: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "try.py", line 19, in <module>
    sr_img = rdn.predict(lr_img)
  File "/Users/santosh/Code/isr/ISR/models/imagemodel.py", line 59, in predict
    sr_img = self.model.predict(lr_img)[0]
  File "/Users/santosh/.pyenv/versions/3.6.5/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 909, in predict
    use_multiprocessing=use_multiprocessing)
  File "/Users/santosh/.pyenv/versions/3.6.5/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_arrays.py", line 715, in predict
    x, check_steps=True, steps_name='steps', steps=steps)
  File "/Users/santosh/.pyenv/versions/3.6.5/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 2472, in _standardize_user_data
    exception_prefix='input')
  File "/Users/santosh/.pyenv/versions/3.6.5/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 574, in standardize_input_data
    str(data_shape))
ValueError: Error when checking input: expected LR to have shape (None, None, 3) but got array with shape (827, 831, 4)

Here's my code:

import numpy as np
import os
from PIL import Image

import time
timestr = time.strftime("%Y%m%d-%H%M%S")

dirname = os.path.dirname(__file__)
filename = os.path.join('/Users/santosh/Code/isr/data/input/sample/slide25.png')

img = Image.open(filename)

lr_img = np.array(img)

# psnr-large
from ISR.models import RDN

rdn = RDN(weights='psnr-large')
sr_img = rdn.predict(lr_img)
img = Image.fromarray(sr_img)
img.save("psnr-large-slide25.png")

# psnr-small
from ISR.models import RDN

rdn = RDN(weights='psnr-small')
sr_img = rdn.predict(lr_img)
img = Image.fromarray(sr_img)
img.save("psnr-small-slide25.png")

# noise-cancel
from ISR.models import RDN

rdn = RDN(weights='noise-cancel')
sr_img = rdn.predict(lr_img)
img = Image.fromarray(sr_img)
img.save("noise-cancel-slide25.png")

#gans
from ISR.models import RRDN

rdn = RRDN(weights='gans')
sr_img = rdn.predict(lr_img)
img = Image.fromarray(sr_img)
img.save("gans-slide25.png")

Please suggest how to address this.

I've tried flattening the png (img.convert("RGB")) and it works, but I don't want the background.

santoshachari avatar Oct 14 '20 04:10 santoshachari

@mlesniak-idealo Just checking if you can help here.

santoshachari avatar Oct 16 '20 08:10 santoshachari

Hi, there is no way around flattening the image if you want to use the pretrained models. Look at this issue for alternative options: https://github.com/idealo/image-super-resolution/issues/158

cfrancesco avatar Nov 12 '20 14:11 cfrancesco

hi, why its taking so much time in cpu mode any solution

balaji4399 avatar Feb 28 '24 12:02 balaji4399