GithubHelp home page GithubHelp logo

idealo / image-super-resolution Goto Github PK

View Code? Open in Web Editor NEW
4.5K 101.0 746.0 14.98 MB

πŸ”Ž Super-scale your images and run experiments with Residual Dense and Adversarial Networks.

Home Page: https://idealo.github.io/image-super-resolution/

License: Apache License 2.0

Shell 0.09% Python 99.91%
image-super-resolution neural-network tensorflow keras aws convolutional-neural-networks deep-learning computer-vision machine-learning e-commerce

image-super-resolution's Introduction

Image Super-Resolution (ISR)

Build Status Docs License

The goal of this project is to upscale and improve the quality of low resolution images.

This project contains Keras implementations of different Residual Dense Networks for Single Image Super-Resolution (ISR) as well as scripts to train these networks using content and adversarial loss components.

The implemented networks include:

Read the full documentation at: https://idealo.github.io/image-super-resolution/.

Docker scripts and Google Colab notebooks are available to carry training and prediction. Also, we provide scripts to facilitate training on the cloud with AWS and nvidia-docker with only a few commands.

ISR is compatible with Python 3.6 and is distributed under the Apache 2.0 license. We welcome any kind of contribution. If you wish to contribute, please see the Contribute section.

Contents

Troubleshooting

Training not delivering good/patchy results

When training your own model, start with only PSNR loss (50+ epochs, depending on the dataset) and only then introduce GANS and feature loss. This can be controlled by the loss weights argument.

This is just sample, you will need to tune these parameters.

PSNR only:

loss_weights = {
  'generator': 1.0,
  'feature_extractor': 0.0,
  'discriminator': 0.00
}

Later:

loss_weights = {
  'generator': 0.0,
  'feature_extractor': 0.0833,
  'discriminator': 0.01
}

Weights loading

If you are having trouble loading your own weights or the pre-trained weights (AttributeError: 'str' object has no attribute 'decode'), try:

pip install 'h5py==2.10.0' --force-reinstall

Issue

Pre-trained networks

The weights used to produced these images are available directly when creating the model object.

Currently 4 models are available:

  • RDN: psnr-large, psnr-small, noise-cancel
  • RRDN: gans

Example usage:

model = RRDN(weights='gans')

The network parameters will be automatically chosen. (see Additional Information).

Basic model

RDN model, PSNR driven, choose the option weights='psnr-large' or weights='psnr-small' when creating a RDN model.

butterfly-sample
Low resolution image (left), ISR output (center), bicubic scaling (right). Click to zoom.

GANS model

RRDN model, trained with Adversarial and VGG features losses, choose the option weights='gans' when creating a RRDN model.

baboon-comparison
RRDN GANS model (left), bicubic upscaling (right).
-> more detailed comparison

Artefact Cancelling GANS model

RDN model, trained with Adversarial and VGG features losses, choose the option weights='noise-cancel' when creating a RDN model.

temple-comparison
Standard vs GANS model. Click to zoom.
sandal-comparison
RDN GANS artefact cancelling model (left), RDN standard PSNR driven model (right).
-> more detailed comparison

Installation

There are two ways to install the Image Super-Resolution package:

  • Install ISR from PyPI (recommended):
pip install ISR
  • Install ISR from the GitHub source:
git clone https://github.com/idealo/image-super-resolution
cd image-super-resolution
python setup.py install

Usage

Prediction

Load image and prepare it

import numpy as np
from PIL import Image

img = Image.open('data/input/test_images/sample_image.jpg')
lr_img = np.array(img)

Load a pre-trained model and run prediction (check the prediction tutorial under notebooks for more details)

from ISR.models import RDN

rdn = RDN(weights='psnr-small')
sr_img = rdn.predict(lr_img)
Image.fromarray(sr_img)

Large image inference

To predict on large images and avoid memory allocation errors, use the by_patch_of_size option for the predict method, for instance

sr_img = model.predict(image, by_patch_of_size=50)

Check the documentation of the ImageModel class for further details.

Training

Create the models

from ISR.models import RRDN
from ISR.models import Discriminator
from ISR.models import Cut_VGG19

lr_train_patch_size = 40
layers_to_extract = [5, 9]
scale = 2
hr_train_patch_size = lr_train_patch_size * scale

rrdn  = RRDN(arch_params={'C':4, 'D':3, 'G':64, 'G0':64, 'T':10, 'x':scale}, patch_size=lr_train_patch_size)
f_ext = Cut_VGG19(patch_size=hr_train_patch_size, layers_to_extract=layers_to_extract)
discr = Discriminator(patch_size=hr_train_patch_size, kernel_size=3)

Create a Trainer object using the desired settings and give it the models (f_ext and discr are optional)

from ISR.train import Trainer
loss_weights = {
  'generator': 0.0,
  'feature_extractor': 0.0833,
  'discriminator': 0.01
}
losses = {
  'generator': 'mae',
  'feature_extractor': 'mse',
  'discriminator': 'binary_crossentropy'
}

log_dirs = {'logs': './logs', 'weights': './weights'}

learning_rate = {'initial_value': 0.0004, 'decay_factor': 0.5, 'decay_frequency': 30}

flatness = {'min': 0.0, 'max': 0.15, 'increase': 0.01, 'increase_frequency': 5}

trainer = Trainer(
    generator=rrdn,
    discriminator=discr,
    feature_extractor=f_ext,
    lr_train_dir='low_res/training/images',
    hr_train_dir='high_res/training/images',
    lr_valid_dir='low_res/validation/images',
    hr_valid_dir='high_res/validation/images',
    loss_weights=loss_weights,
    learning_rate=learning_rate,
    flatness=flatness,
    dataname='image_dataset',
    log_dirs=log_dirs,
    weights_generator=None,
    weights_discriminator=None,
    n_validation=40,
)

Start training

trainer.train(
    epochs=80,
    steps_per_epoch=500,
    batch_size=16,
    monitored_metrics={'val_PSNR_Y': 'max'}
)

Additional Information

You can read about how we trained these network weights in our Medium posts:

RDN Pre-trained weights

The weights of the RDN network trained on the DIV2K dataset are available in weights/sample_weights/rdn-C6-D20-G64-G064-x2/PSNR-driven/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5.
The model was trained using C=6, D=20, G=64, G0=64 as parameters (see architecture for details) for 86 epochs of 1000 batches of 8 32x32 augmented patches taken from LR images.

The artefact can cancelling weights obtained with a combination of different training sessions using different datasets and perceptual loss with VGG19 and GAN can be found at weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5 We recommend using these weights only when cancelling compression artefacts is a desirable effect.

RDN Network architecture

The main parameters of the architecture structure are:

  • D - number of Residual Dense Blocks (RDB)
  • C - number of convolutional layers stacked inside a RDB
  • G - number of feature maps of each convolutional layers inside the RDBs
  • G0 - number of feature maps for convolutions outside of RDBs and of each RBD output


source: Residual Dense Network for Image Super-Resolution

RRDN Network architecture

The main parameters of the architecture structure are:

  • T - number of Residual in Residual Dense Blocks (RRDB)
  • D - number of Residual Dense Blocks (RDB) insider each RRDB
  • C - number of convolutional layers stacked inside a RDB
  • G - number of feature maps of each convolutional layers inside the RDBs
  • G0 - number of feature maps for convolutions outside of RDBs and of each RBD output


source: ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks

Contribute

We welcome all kinds of contributions, models trained on different datasets, new model architectures and/or hyperparameters combinations that improve the performance of the currently published model.

Will publish the performances of new models in this repository.

See the Contribution guide for more details.

Bump version

To bump up the version, use

bumpversion {part} setup.py

Citation

Please cite our work in your publications if it helps your research.

@misc{cardinale2018isr,
  title={ISR},
  author={Francesco Cardinale et al.},
  year={2018},
  howpublished={\url{https://github.com/idealo/image-super-resolution}},
}

Maintainers

Copyright

See LICENSE for details.

image-super-resolution's People

Contributors

cclauss avatar cfrancesco avatar datitran avatar dependabot[bot] avatar matthewscholefield avatar mlesniak-idealo avatar pniedzwiedzinski avatar wazted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-super-resolution's Issues

Weights

Really simple issue, but the weights for Large RDN model were updated in the wget command, but not in the execution of ISR_Prediction_Tutorial.ipynb (it's downloading PSNR-driven/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5, but calling weights/rdn-C6-D20-G64-G064-x2_div2k-e086.hdf5)

while training this error raised

Traceback (most recent call last):
File "train.py", line 75, in
monitored_metrics={'val_generator_PSNR_Y' : 'max'}
File "D:\ProgramData\Anaconda3\envs\isr\lib\site-packages\ISR\train\trainer.py", line 308, in train
validation_feats = self.feature_extractor.model.predict(validation_set['hr'])
File "D:\ProgramData\Anaconda3\envs\isr\lib\site-packages\keras\engine\training.py", line 1149, in predict
x, _, _ = self._standardize_user_data(x)
File "D:\ProgramData\Anaconda3\envs\isr\lib\site-packages\keras\engine\training.py", line 751, in _standardize_user_data
exception_prefix='input')
File "D:\ProgramData\Anaconda3\envs\isr\lib\site-packages\keras\engine\training_utils.py", line 128, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input_2 to have 4 dimensions, but got array with shape (1024, 1)


and here is the training code:

# -*- coding: utf-8 -*-



# Create the models

from ISR.models import RRDN
from ISR.models import Discriminator
from ISR.models import Cut_VGG19

lr_train_patch_size = 32
layers_to_extract = [5, 9]
scale = 4
hr_train_patch_size = lr_train_patch_size * scale

rrdn  = RRDN(arch_params={'C':4, 'D':3, 'G':64, 'G0':64, 'T':10, 'x':scale}, patch_size=lr_train_patch_size)
f_ext = Cut_VGG19(patch_size=hr_train_patch_size, layers_to_extract=layers_to_extract)
discr = Discriminator(patch_size=hr_train_patch_size, kernel_size=3)



# Create a Trainer object using the desired settings and give it the models (f_ext and discr are optional)

from ISR.train import Trainer

loss_weights = {
  'generator': 0.0,
  'feature_extractor': 0.0833,
  'discriminator': 0.01
}

losses = {
  'generator': 'mae',
  'feature_extractor': 'mse',
  'discriminator': 'binary_crossentropy'
}

log_dirs = {'logs': './logs', 'weights': './weights'}

learning_rate = {'initial_value': 0.0004, 'decay_factor': 0.5, 'decay_frequency': 30}

flatness = {'min': 0.0, 'max': 0.15, 'increase': 0.01, 'increase_frequency': 5}

adam_optimizer = {'beta1': 0.9, 'beta2': 0.999, 'epsilon': None}

trainer = Trainer(
    generator=rrdn,
    discriminator=discr,
    feature_extractor=f_ext,
    lr_train_dir='low_res/training',
    hr_train_dir='high_res/training',
    lr_valid_dir='low_res/validation',
    hr_valid_dir='high_res/validation',
    loss_weights=loss_weights,
    losses=losses,
    learning_rate=learning_rate,
    flatness=flatness,
    log_dirs=log_dirs,
    adam_optimizer=adam_optimizer,
    metrics={'generator': 'PSNR_Y'},
    dataname='celebA',
    weights_generator=None,
    weights_discriminator=None,
    n_validation=32,
)



# start train
trainer.train(
    epochs=10,
    steps_per_epoch=20,
    batch_size=32,
    #monitored_metrics = {'val_generator_loss': 'min'}
    monitored_metrics={'val_generator_PSNR_Y' : 'max'}
)

Unable to open .hdf5 file (file signature not found)

Hello,
When I tried to run he perdaction using this piece of code :

import tensorflow as tf
from ISR.models import RDN
import h5py
rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')

I got an error


OSError Traceback (most recent call last)
in
3 import h5py
4 rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
----> 5 rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
6
7 sr_img = rdn.predict(lr_img)

~\Anaconda3\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
1155 if h5py is None:
1156 raise ImportError('load_weights requires h5py.')
-> 1157 with h5py.File(filepath, mode='r') as f:
1158 if 'layer_names' not in f.attrs and 'model_weights' in f:
1159 f = f['model_weights']

~\Anaconda3\lib\site-packages\h5py_hl\files.py in init(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds)
392 fid = make_fid(name, mode, userblock_size,
393 fapl, fcpl=make_fcpl(track_order=track_order),
--> 394 swmr=swmr)
395
396 if swmr_support:

~\Anaconda3\lib\site-packages\h5py_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
168 if swmr and swmr_support:
169 flags |= h5f.ACC_SWMR_READ
--> 170 fid = h5f.open(name, flags, fapl=fapl)
171 elif mode == 'r+':
172 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py_objects.pyx in h5py._objects.with_phil.wrapper()

h5py_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file signature not found)

So any help please, has anyone faced the same problem? How can I fix it?

Thanks a lot!

Can't find the model I just trained

Hi, I trained the network by ISR_Traininig_Tutorial.ipynb on Google Colab platform. The training process ended successfully, but I can't find the model.

Folder "weights/<actual_train>/<actual_date_time>" contains only session_config.yml file.

Has anyone encountered this problem?

Randomly getting valueError during training

Hi
I am training this model with my own image dataset and I am randomly getting one of the following errors. Sometimes, one epoch gets completed and during the next epoch one of following error appears.

I think following error appears due to some floor/ceiling type function because only one pixel is less than the required one

env/lib/python3.5/site-packages/Keras-2.2.4-py3.5.egg/keras/engine/training_utils.py", line 138, in standardize_input_data
    str(data_shape))
ValueError: Error when checking target: expected generator to have shape (80, 80, 3) but got array with shape (80, 79, 3)
env/lib/python3.5/site-packages/ISR-2.0.5-py3.5.egg/ISR/utils/datahandler.py", line 153, in _transform_batch
ValueError: could not broadcast input array from shape (80,80,3) into shape (80)

Here's the code


lr_train_patch_size = 40
layers_to_extract = [5, 9]
scale = 2
hr_train_patch_size = lr_train_patch_size * scale

rrdn  = RRDN(arch_params={'C':4, 'D':3, 'G':64, 'G0':64, 'T':22, 'x':scale},patch_size=lr_train_patch_size)
#rrdn.model.load_weights()
f_ext = Cut_VGG19(patch_size=hr_train_patch_size, layers_to_extract=layers_to_extract)
discr = Discriminator(patch_size=hr_train_patch_size, kernel_size=3)



loss_weights = {
  'generator': 1.0,
  #'feature_extractor': 0.0833,
  #'discriminator': 0.01
}
losses = {
  'generator': 'mae',
  #'feature_extractor': 'mse',
  #'discriminator': 'binary_crossentropy'
}

log_dirs = {'logs': './logs', 'weights': './weights'}

learning_rate = {'initial_value': 0.0004, 'decay_factor': 0.5, 'decay_frequency': 30}

flatness = {'min': 0.0, 'max': 0.15, 'increase': 0.01, 'increase_frequency': 5}

#rrdn.model.load_weights(weight_path)

trainer = Trainer(
    generator=rrdn,
    #discriminator=discr,
    discriminator= None,
    #feature_extractor=f_ext,
    feature_extractor = None,
    lr_train_dir=lr_train_dir_check,
    hr_train_dir=hr_train_dir_check,
    lr_valid_dir=lr_valid_dir_check,
    hr_valid_dir=hr_valid_dir_check,
    loss_weights=loss_weights,
    learning_rate=learning_rate,
    flatness=flatness,
    dataname='lr_bicubic_dataset',
    log_dirs=log_dirs,
    weights_generator=None,
    weights_discriminator=None,
    n_validation=40,
)
print("I am here")
trainer.train(
    epochs=5,
    steps_per_epoch=8,
    batch_size=8,
    monitored_metrics={'val_loss': 'min'}
)

Training with multiple parameters

Hello,
Can we run the Training of the model with a range of parameters so it can generate multiple models and just select the best result and discard the rest.
Idditionally I am thinking of crowdsourcing for the best performance parameters ( with a top).

Does this make any sense?

Br
Vlad

Image size limit?

Cool project! What are the limits on how big an input image can be (assuming you are using the Colab Tutorial notebook)?

I tried to run predictions on a 1024x1024 image but got an OOM error. Is there a way to apply Super Resolution to larger images?

How to use?

python setup.py install

I run the command. Installation complete.

Which file will I run now?

Error with Pretrained Model When Converting to Tensorflow.js

Hi,

I am trying to convert the model weights into a json file using the instructions here: https://js.tensorflow.org/tutorials/import-keras.html . The model is able to convert correctly but I keep getting a 'Uncaught (in promise) TypeError: Cannot read property 'model_config' of null' error when trying to load the model in javascript. I think it has something to do with not using model.save() when saving the keras model in python. Any help will be appreciated. Thanks.

Parameters in session_config.yml

Some parameters are missing or wrong when saving the configuration with the weights.
missing: patch_size, layers_to_extract
wrong: feature_extractor.name

Benchmarking

Can you please add some performance numbers to the main project docs indicating inference latency running some common hardware options e.g. AWS p2, GCP gpu instance, CPU inference, Raspbery pi, etc.

paper

sorry,i can not find your paper which can match this codes,can you give me a link?

"git lfs pull" error (This repository is over its data quota)

Getting an error if try git lfs pull afterward:

$ git lfs pull
batch response: This repository is over its data quota. Purchase more data packs to restore access.
error: failed to fetch some objects from 'https://github.com/idealo/image-super-resolution.git/info/lfs'

Parameters for more subtle output effect

Just wondering if there are any parameters I can play with to get a slightly less intense brushy & flat effect? The examples look a bit more realistic and have more depth, if that makes any sense? (bicubic on the left and the Large RDN noise cancelling, detail enhancing model on the right)
Screen Shot 2019-08-05 at 23 06 54

terminate called after throwing an instance of 'std::bad_alloc'

Hi there

Tried running the following:

import numpy as np
from PIL import Image
from ISR.models import RDN

img = Image.open('/home/nexor/Desktop/mpv-shot0001.jpg')
lr_img = np.array(img)

rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')

sr_img = rdn.predict(lr_img)
Image.fromarray(sr_img)

And weirdly enough I got the following error message:

Using TensorFlow backend.
WARNING:tensorflow:From /home/nexor/.local/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
2019-05-29 18:34:16.765468: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3606655000 Hz
2019-05-29 18:34:16.765802: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x560275415c70 executing computations on platform Host. Devices:
2019-05-29 18:34:16.765815: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
2019-05-29 18:34:18.009409: W tensorflow/core/framework/allocator.cc:124] Allocation of 530841600 exceeds 10% of system memory.
2019-05-29 18:34:18.209551: W tensorflow/core/framework/allocator.cc:124] Allocation of 530841600 exceeds 10% of system memory.
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[1]    5181 abort (core dumped)  ./isrtest.py

Maybe I got some dependency version off?

Out of memory error when model is called repeatedly

Hi
The model with pretrained weights is working correctly while making a prediction on a single image but when I try to make prediction on a lots of images, this gives me out of memory error or system kills it because of it consumption of all the memory. Sometimes it does make prediction for on 5 to 10 images before giving out of memory error. I think it is because of the fact that keras keeps on building the computation graphs before the previous graphs gets completed and in this way free memory keeps on decreasing. Now is it possible that it(model) first predicts on one image and after that for the next image and so on.
My code

rdn.model.load_weights('image-super-resolution/weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
for f in files:
    img = Image.open(f)
    lr_img = np.array(img)
    sr_img = rdn.predict(lr_img)
    hr_img = Image.fromarray(sr_img)
    hr_img.save("model_"+f)
    print(f+" is done")

The error I am getting is this

2019-07-15 10:54:26.136079: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2019-07-15 10:54:26.149052: E tensorflow/stream_executor/cuda/cuda_driver.cc:300] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2019-07-15 10:54:26.149107: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:163] retrieving CUDA diagnostic information for host: host_tower
2019-07-15 10:54:26.149118: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:170] hostname: cledl2-Precision-7820-Tower
2019-07-15 10:54:26.149170: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:194] libcuda reported version is: 390.116.0
2019-07-15 10:54:26.149202: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:198] kernel reported version is: 390.116.0
2019-07-15 10:54:26.149212: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:305] kernel version seems to match DSO: 390.116.0
2019-07-15 10:58:10.703357: W tensorflow/core/framework/allocator.cc:122] Allocation of 5865369600 exceeds 10% of system memory.
b320_150dpi_25-58.jpg is done
2019-07-15 11:00:52.459730: W tensorflow/core/framework/allocator.cc:122] Allocation of 4101580800 exceeds 10% of system memory.
b320_150dpi_25-64.jpg is done
2019-07-15 11:03:38.891812: W tensorflow/core/framework/allocator.cc:122] Allocation of 4270080000 exceeds 10% of system memory.
b320_150dpi_25-10.jpg is done
2019-07-15 11:06:22.367807: W tensorflow/core/framework/allocator.cc:122] Allocation of 4185067520 exceeds 10% of system memory.
b320_150dpi_25-35.jpg is done
2019-07-15 11:10:14.411686: W tensorflow/core/framework/allocator.cc:122] Allocation of 6017474560 exceeds 10% of system memory.
b210_150dpi_91.jpg is done
b209_150dpi_15.jpg is done
b320_150dpi_25-12.jpg is done
2019-07-15 11:26:49.040817: W tensorflow/core/framework/op_kernel.cc:1273] OP_REQUIRES failed at concat_op.cc:153 : Resource exhausted: OOM when allocating tensor with shape[1,2368,1386,1280] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
Traceback (most recent call last):
  File "inference.py", line 38, in <module>
    sr_img = rdn.predict(lr_img)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/ISR-2.0.5-py3.5.egg/ISR/models/imagemodel.py", line 21, in predict
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/Keras-2.2.4-py3.5.egg/keras/engine/training.py", line 1169, in predict
    steps=steps)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/Keras-2.2.4-py3.5.egg/keras/engine/training_arrays.py", line 294, in predict_loop
    batch_outs = f(ins_batch)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/Keras-2.2.4-py3.5.egg/keras/backend/tensorflow_backend.py", line 2715, in __call__
    return self._call(inputs)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/Keras-2.2.4-py3.5.egg/keras/backend/tensorflow_backend.py", line 2675, in _call
    fetched = self._callable_fn(*array_vals)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1439, in __call__
    run_metadata_ptr)
  File "/home/user/Documents/experiment/SIP_env/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[1,2368,1386,1280] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
         [[{{node LRLs_Concat/concat}} = ConcatV2[N=20, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](LRL_1/add, LRL_2/add, LRL_3/add, LRL_4/add, LRL_5/add, LRL_6/add, LRL_7/add, LRL_8/add, LRL_9/add, LRL_10/add, LRL_11/add, LRL_12/add, LRL_13/add, LRL_14/add, LRL_15/add, LRL_16/add, LRL_17/add, LRL_18/add, LRL_19/add, LRL_20/add, RDB_Concat_20_1/concat/axis)]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

And more often the program gets killed by os.

How to resume training?

Hi, Nice project. Can you guide me how to resume training? I know weights_generator and weights_discriminator exist for transfer learning. Should I save some other things or specify anything else ... ? Thank you.

Questions on images used in SR training

Hi,
I have some questions in mind for a while and want to discuss possibilities.
Lr images for training are obtained by cubic rescale of hr ones, and that's fine. This process is preserving the exact noise found in hr image also, don't know if this is an additional benefit or not.
I am taking photos of small technical pieces for documentation purposes, so my photography environment conditions are fixed (same light levels, same background, same object distance, etc).
I have a couple of unusual options in mind, to obtain lr and hr image sets, under given conditions.

One is, taking two photos of same objects, at two different resolutions directly set from the digital camera. One is for lr, and the other one is for hr.

Other option is a bit more complicated and will require more work. No resolution change this time, but a different optical zoom via lens is used to get wide (lr) and zoomed-in (hr) images. Especially with this one, it's possible to capture seriously rich detail levels in hr images.

Do you think any of these helps the SR to perform better, by means of detail preservation and noise, in final images?

Inference of large images

I think it would be a great feature to have some option for prediction of larger images, by applying sr to tiles of the main image and stitching the results, this is after enabling gpu inference of course.
Thanks!

Training own dataset

Hi I want to train my own dataset.

I received the following error
The directory name is invalid: 'weights\rrdn-C4-D3-G64-G064-T10-x2\2019-05-27_23:41'

Any reasons why?

OSError: Unable to open file (file signature not found)

When I run this sample Usage

import numpy as np
from PIL import Image

img = Image.open(r'MyJPG_Path')
lr_img = np.array(img)

from ISR.models import RDN

rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
sr_img = rdn.predict(lr_img)
Image.fromarray(sr_img)

It warns that:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')
  File "lib\site-packages\keras\engine\network.py", line 1157, in load_weights
    with h5py.File(filepath, mode='r') as f:
  File "lib\site-packages\h5py\_hl\files.py", line 394, in __init__
    swmr=swmr)
  File "lib\site-packages\h5py\_hl\files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

I use the original hdf5 file which is downloaded from the Github source. I wonder how to cope with this problem.

Prediction input dimension error

Hi im trying to do inference on the rrdn model i just trained but i received the following error

Error when checking input: expected LR_input to have shape (40, 40, 3) but got array with shape (908, 908, 3)

May I check whats the reason to be (40,40,3) input dimension?

ResourceExhaustError

Hi Dear,
I have a 2GB GPU. When I run a small image lets say of size 200 by 200 or smaller, it runs it with no error. But when I give a bigger image of lets say 400x400, it gives me this error and I could not find on how to set gpu configurations options for the code. Can you please help.

ResourceExhaustedError: OOM when allocating tensor with shape[1,448,480,544] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc

What changes should be made to run on GPU machine

I've used this model with pre-trained weights for prediction and It's working perfectly (Thank you for that! ) . The issue is that it's running on CPU and taking long time to upscale a single image (about 2 minutes). I've GPU in my machine and this module is not utilizing it. I think there's need to be some changes in the code (or whatever). Now my question is that what should be changed in the code for prediction (as well for training) such that this module uses my (precious) GPU resources?

Thanks in advance. Waiting for your reply

Weights

The weights files are still not actual weights files. Could they be uploaded, please?
Thanks!

cannot download weights

Hello
I am trying to download the weights for the repo into my google colab but i keep getting this error

image

/content/image-super-resolution
batch response: This repository is over its data quota. Purchase more data packs to restore access.
error: failed to fetch some objects from 'https://github.com/idealo/image-super-resolution.git/info/lfs'

Also i failed to run your google colab notebook it now says

image

Can you help me with this?

Installing is buggy with PIP

Hi,
I have tried to train my own dataset; however, I got this error

`TypeError Traceback (most recent call last)
in ()
weights_generator=None,
weights_discriminator=None,
---> n_validation=40,
)

TypeError: init() got an unexpected keyword argument 'flatness'`

Then, I have tried to use !git clone but this time other errors came up. I think you need to upgrade "!pip install ISR" with the latest version for training. If I am wrong, please correct me. Thank you!

Running prediction on GPU

Great project, thank you!

Just wondering if you have been able to run the predictions (not the training) on GPU. Using the Dockerfile.gpu I find that ISR will use the CPU to calculate the prediction and not the GPU.

Time_Stamp on Windows 10 fails to create folders due to colon

The line where the folder name is create is this (in predictor.py)
out_folder = self.output_dir / self.make_basename() / get_timestamp()
The get_timestamp() function, from utils:
def get_timestamp():
ts = datetime.now()
time_stamp = '{y}-{m:02d}-{d:02d}
{h:02d}:{mm:02d}'.format(
y=ts.year, m=ts.month, d=ts.day, h=ts.hour, mm=ts.minute
)
return time_stamp

Windows folders with the time as 19:57 will fail to create.

Undefined name 'logger' in test_utils.py

flake8 testing of https://github.com/idealo/image-super-resolution on Python 3.7.1

$ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

./tests/utils/test_datahandler.py:254:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(batch) is 2)
                        ^
./tests/utils/test_datahandler.py:280:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(batch) is 2)
                        ^
./tests/utils/test_utils.py:42:25: F821 undefined name 'logger'
                        logger.error('{p} is missing key {k}'.format(p=parameter, k=key))
                        ^
./tests/utils/test_utils.py:47:25: F821 undefined name 'logger'
                        logger.info(
                        ^
./tests/train/test_trainer.py:87:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.layers) is 4)
                        ^
./tests/train/test_trainer.py:88:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.loss_weights) is 4)
                        ^
./tests/train/test_trainer.py:92:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.layers) is 3)
                        ^
./tests/train/test_trainer.py:93:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.loss_weights) is 3)
                        ^
./tests/train/test_trainer.py:97:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.layers) is 2)
                        ^
./tests/train/test_trainer.py:98:25: F632 use ==/!= to compare str, bytes, and int literals
        self.assertTrue(len(combined.loss_weights) is 1)
                        ^
8     F632 use ==/!= to compare str, bytes, and int literals
2     F821 undefined name 'logger'
10

E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.

  • F821: undefined name name
  • F822: undefined name name in __all__
  • F823: local variable name referenced before assignment
  • E901: SyntaxError or IndentationError
  • E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree

OSError while loading sample weights

While I was loading model with sample weights in Google Colab this exception occurred:

Using TensorFlow backend.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-5-913aee289ebe> in <module>()
      2 
      3 rdn = RDN(arch_params={'C':6, 'D':20, 'G':64, 'G0':64, 'x':2})
----> 4 rdn.model.load_weights('/content/image-super-resolution/weights/sample_weights/rdn-C6-D20-G64-G064-x2_div2k-e086.hdf5')
      5 
      6 sr_img = rdn.model.predict(lr_img)[0]

/usr/local/lib/python3.6/dist-packages/keras/engine/network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1155         if h5py is None:
   1156             raise ImportError('`load_weights` requires h5py.')
-> 1157         with h5py.File(filepath, mode='r') as f:
   1158             if 'layer_names' not in f.attrs and 'model_weights' in f:
   1159                 f = f['model_weights']

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
    310             with phil:
    311                 fapl = make_fapl(driver, libver, **kwds)
--> 312                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
    313 
    314                 if swmr_support:

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    140         if swmr and swmr_support:
    141             flags |= h5f.ACC_SWMR_READ
--> 142         fid = h5f.open(name, flags, fapl=fapl)
    143     elif mode == 'r+':
    144         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file signature not found)

I found that this error might mean that the file is corrupted. Or maybe it's the fault of Google Colab πŸ€”

While predicting this error is raised

I have trained my own model and I'm able to predict in single images. But I'm unable to use predictor class to run on the model on entire image of input directory. Failing in predictor.get_predictions() method with below error:
ConstructorError: while constructing a Python object
module 'ISR.utils.metrics' is not imported
in "", line 25, column 26:
metrics: {generator: !!python/name:ISR.utils.metrics. ...

Problem during inference of image

I'm having problem while inferring at my own test image. When I run inference.py I face following warning/errors and then script stops and nothing happens

Colocations automatically by placer. 2019-06-21 15:20:59.768463: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2019-06-21 15:20:59.795912: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1895565000 Hz 2019-06-21 15:20:59.796758: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x2ea5490 executing computations on platform Host. Devices: 2019-06-21 15:20:59.796805: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined> 2019-06-21 15:21:21.162024: W tensorflow/core/framework/allocator.cc:124] Allocation of 118087680 exceeds 10% of system memory.

My system RAM is 4GB, OS is ubuntu 18.04.2 LTS and I am running it inside virtual enviroment

ValueError: You are trying to load a weight file containing 154 layers into a model with 148 layers.

Hi, When I finished training my own datasets(train:153 images, val:39 images),I got some weights under folder "wieghts", I tried some of the weights to predict, but I got errors like below:
Traceback (most recent call last): File "/home/gaoya/Files/python/GAN/ISR_predict_153_x2_images.py", line 17, in <module> rdn.model.load_weights('/home/gaoya/Files/python/GAN/weights/rrdn-C4-D3-G64-G064-T10-x2/images/153x2-vgg19-5-9-srgan-large/rrdn-C4-D3-G64-G064-T10-x2_images_153x2-vgg19-5-9-srgan-large-e074.hdf5') File "/usr/local/lib/python3.6/dist-packages/keras/engine/network.py", line 1166, in load_weights f, self.layers, reshape=reshape) File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 1030, in load_weights_from_hdf5_group str(len(filtered_layers)) + ' layers.') ValueError: You are trying to load a weight file containing 154 layers into a model with 148 layers.
What's wrong with this?

monitored_metrics error

I got an error while training the network as follows:
TypeError(): train() missing 1 required positional argument: 'monitored metrics'

TypeError: train() missing 1 required positional argument: 'monitored_metrics'

OS:Win10,64/ Ubuntu18.04
python: 3.6
keras: 2.2.4
tensorflow: 1.13.1(win10), 1.12.0(Ubuntu18.04)

Hi , When I train my own datasets, I got the error like below:
Traceback (most recent call last): File "D:\Files\python\MachineLearning\GAN\ISR_train_153_x2_images.py", line 46, in <module> batch_size=16, TypeError: train() missing 1 required positional argument: 'monitored_metrics'
Can someone figure out?

Upgrade to TensorFlow 2.0

TensorFlow 2.0 is beta now and a stable candidate is going to be released soon. So we can start upgrading it to TF 2.0 soon.

Issue with RRDN weight hdf5 file

Hi,

there seems to be an issue with the RRDN weight hdf5 file. When loading it into the RRDN model, it throws an error. File might be corrupted.

Tested it on Colab.

Can you re-upload it?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.