idealo / image-super-resolution

🔎 Super-scale your images and run experiments with Residual Dense and Adversarial Networks.
https://idealo.github.io/image-super-resolution/
Apache License 2.0
4.62k stars 762 forks source link

Upscaling transparent PNGs #151

Open santoshachari opened 3 years ago

santoshachari commented 3 years ago

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 commented 3 years ago

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

cfrancesco commented 3 years ago

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

balaji4399 commented 7 months ago

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