srgan | Pytorch implementation of Photo-Realistic Single Image | Computer Vision library
kandi X-RAY | srgan Summary
kandi X-RAY | srgan Summary
This is a complete Pytorch implementation of Christian Ledig et al: "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network", reproducing their results. This paper's main result is that through using an adversarial and a content loss, a convolutional neural network is able to produce sharp, almost photo-realistic upsamplings of images. The implementation tries to be as faithful as possible to the original paper. See implementation details for a closer look. Pretrained checkpoints of SRResNet and SRGAN trained on the COCO dataset (118k images) are provided.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Build a runner
- Gets an attribute from the configuration
- Return True if attribute exists
- Convert input tensors into a CUDA module
- Perform training step
- Request data from the loader
- Calculate average loss
- Get sr_transform
- Tests input image using adaptive scaling
- Update values_by_keys
- Train the network
- Validates the validation results
- Updates dictionary with values_by_keys
- Download and extract and extract the data from a zip file
- Print information about the GPU
- Download and extract dataset
- Download and extract a set5 dataset
- Downloads and extracts a BDS500 dataset
- Validate the validation results
- Load a dataset
- Perform a single training step
- Return a train dataset
- Get an image transformer
- Create a SRDataset from a folder
- Create a SRDataset from a folder or folder
- Set the CUDA_VISIBLE_DEVICES environment variable
- Get the inference checkpoint from a training checkpoint
- Get an sr_output transform
- Restore checkpoint from checkpoint file
- Performs a single evaluation step
srgan Key Features
srgan Examples and Code Snippets
Community Discussions
Trending Discussions on srgan
QUESTION
I'm implementing SRGAN (and am not very experienced in this field), which uses a pre-trained VGG19 model to extract features. The following code was working fine on Keras 2.1.2 and tf 1.15.0 till yesterday. then it started throwing an "AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'" So i updated the keras version to 2.4.3 and tf to 2.5.0. but then its showing a "Input 0 of layer fc1 is incompatible with the layer: expected axis -1 of input shape to have value 25088 but received input with shape (None, 32768)" on the following line
...ANSWER
Answered 2021-Jun-01 at 11:46Importing keras from tensorflow
and setting include_top=False
in
QUESTION
I've been working on reimplementing Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network (SRGAN), now I'm stuck with the given information in section 3.2. Based on the paper, the target HR should be in the range [-1,1], the input LR should be in the range [0,1], and MSE loss was calculated on images in range [-1,1].
The last sentence implies that the output from the generator network should be in [-1,1]. So that the content_loss = MSELoss(generator(output), target). Am I understanding correctly? But when I print the output from my generator network, whose laster is just a conv2d, it gives me images in the rage [0,1].
I'm not getting a good result by running SRResNet-MSE part, and I think maybe because the MSE loss is calculating on different ranges instead of just one [-1,1]?
But how can the output from my generator be in range [-1,1] if I still want to follow paper's architecture, which has conv2d as the last layer?
I also include my code Class Generator here
...ANSWER
Answered 2020-Jul-23 at 04:06Given that you want output in the range [-1,1] and currently you are getting output in [0,1] simply doing.
QUESTION
How can I save a jupyter notebook with outputs? I'm editing my notebook with Google Collab and want to save it as a .ipynb file with outputs shown, like here: https://nbviewer.jupyter.org/github/krasserm/super-resolution/blob/master/example-srgan.ipynb.
But when I Download .ipynb
on Google Collab, you can't see the outputs in the resulting file. How can I get the outputs to show?
Related question: how can I have the outputs save in the Google Collab doc? Right now, the outputs always disappear on reload, even though I disabled the hide outputs on save.
...ANSWER
Answered 2020-Jun-09 at 18:12When I downloaded it did show me the content. Make sure you used
Save
on the notebook before downloading (I uploaded my result to https://nbviewer.jupyter.org/ and it worked and showed the preview). If it doesn't work, check the next item on my list.Double-check the settings at "Settings" -> "Site" and make sure "New notebooks use private outputs (omit outputs when saving)" is disabled. Similarly, check also "Edit" -> "Notebook settings" and make sure "Omit code cell output when saving this notebook" is disabled. Yes, these are two separate settings.
Retry 1# if it didn't work before after toggling both settings. Also, notebooks should now save the output.
QUESTION
I have images that are having very low quality and these images I have to use for person identification but with this quality it's difficult to detect. I want to enhance the quality of the images using deep learning/machine learning techniques. I have studied about SRCNN, perceptual Loss, SRResNet, SRGAN but most of the super image resolution techniques require original images for improving the quality of the images. So my question is there any deep learning techniques that can be used for the improving the quality of the images without using the original images.
...ANSWER
Answered 2020-Feb-21 at 02:22QUESTION
I want to use including and after tensorflow2.0 in Docker. I want to use (https://github.com/tensorlayer/srgan).
My Dockerfile is
...ANSWER
Answered 2020-Jan-14 at 05:57Can you try setting
config.gpu_options.allow_growth = True
QUESTION
- Context
- The problem
- Trying to solve the problem
- Question
- Related questions
I use a custom .tflite
model I saved in the Firebase servers (https://firebase.google.com/docs/ml-kit/android/use-custom-models). This is my custom Super-Resolution images GAN generator: I give it a 32x32 image, and it gives me the super resolutioned 128x128 image. I am trying to use it in my Android app.
I followed the documentation whose I gave the link above.
The problemThe following exception is thrown:
Trying to solve the problem Analysing the expected input and output shapesI/System.out: com.google.firebase.ml.common.FirebaseMLException: Internal error has occurred when executing Firebase ML tasks
According to the Google Colab Python Interpreter, my expected input and output are the following:
[ 1 32 32 3]
class 'numpy.float32'>
[ 1 128 128 3]
class 'numpy.float32'>
So I must give my generator model a 32x32x3 image, and it must output a 128x128x3 image, everything is normal here :). This is the normal work of a SRGAN generator.
Analysing the Android app sourcesHere is the Android app source code... it includes both the configuration and the inference run of my generator model. Data to be sent is also shown.
Configuring the ML Kit client ...ANSWER
Answered 2019-Sep-02 at 13:10Problem solved by changing a few lines... stupid error! The key here was to take account of the first dimension, which contains only 1 value (the first "1"). 1 value only since I just send (and receive) only 1 image.
1.
QUESTION
I have written a TensorFlow / Keras Super-Resolution GAN. I've converted the resulting trained .h5
model to a .tflite
model, using the below code, executed in Google Colab:
ANSWER
Answered 2019-Aug-30 at 11:31In general, quantization means, shifting from dtype float32 to uint8. So theoretically our model should reduce by the size of 4. This will be clearly visible in files of greater size.
Check whether your model has been quantized or not by using the tool "https://lutzroeder.github.io/netron/". Here you have to load the model and check the random layers having weight.The quantized graph contains the weights value in uint8 format
In unquantized graph the weights value will be in float32 format.
Only setting "converter.post_training_quantize=True" is not enough to quantize your model. The other settings include:
converter.inference_type=tf.uint8
converter.default_ranges_stats=[min_value,max_value]
converter.quantized_input_stats={"name_of_the_input_layer_for_your_model":[mean,std]}
Hoping you are dealing with images.
min_value=0, max_value=255, mean=128(subjective) and std=128(subjective).
name_of_the_input_layer_for_your_model= first name of the graph when you load your model in the above mentioned link or you can get the name of the input layer through the code "model.input" will give the output "tf.Tensor 'input_1:0' shape=(?, 224, 224, 3) dtype=float32". Here the input_1 is the name of the input layer(NOTE: model must include the graph configuration and the weight.)
QUESTION
My question is composed by:
- A context in which I present my project, my working environment and my workflow
- The detailed problem
- The concerned parts of my code
- The solutions I tried to solve my problem
- The question reminder
I've written a Python Keras implementation of a downgraded version of the original Super-Resolution GAN. Now I want to test it using Google Firebase Machine Learning Kit, by hosting it in the Google servers. That's why I have to convert my Keras program to a TensorFlow Lite one.
Environment and workflow (with the problem)I'm training my program on Google Colab working environment: there, I've installed TF 2.0.0-beta1
(this choice is motivated by this uncorrect answer: https://datascience.stackexchange.com/a/57408/78409).
Workflow (and problem):
I write locally my Python Keras program, keeping in mind that it will run on TF 2. So I use TF 2 imports, for example:
from tensorflow.keras.optimizers import Adam
and alsofrom tensorflow.keras.layers import Conv2D, BatchNormalization
I send my code to my Drive
I run without any problem my Google Colab Notebook: TF 2 is used.
I get the output model in my Drive, and I download it.
I try to convert this model to the TFLite format by executing the following CLI:
tflite_convert --output_file=srgan.tflite --keras_model_file=srgan.h5
: here the problem appears.
Instead of outputing the TF Lite converted model from the TF (Keras) model, the previous CLI outputs this error:
ValueError: Unknown loss function:build_vgg19_loss_network
The function build_vgg19_loss_network
is a custom loss function that I've implemented and that must be used by the GAN.
The custom loss function is implemented like that:
...ANSWER
Answered 2019-Aug-22 at 18:40Since you are claiming that TFLite conversion is failing due to a custom loss function, you can save the model file without keep the optimizer details. To do that, set include_optimizer
parameter to False as shown below:
QUESTION
I am trying to replicate the example mentioned at this address by tensorlayer:
https://github.com/tensorlayer/srgan/blob/master/train.py
It has below import statements:
...ANSWER
Answered 2019-Jul-24 at 12:24The model
you imported is a custom module, it is placed in this repo srgan
, you got to clone the dependency of train.py
too.
QUESTION
A single line in my model, tr.nn.Linear(hw_flat * num_filters*8, num_fc)
, is causing an OOM error on initialization of the model. Commenting it out removes the memory issue.
ANSWER
Answered 2019-Apr-13 at 22:44Your linear layer is quite large - it does, in fact, need at least 18GB of memory. (Your estimate is off for two reasons: (1) a float32
takes 4 bytes of memory, not 32, and (2) you didn't multiply by the output size.)
From the PyTorch documentation FAQs:
Don’t use linear layers that are too large. A linear layer
nn.Linear(m, n)
usesO(n*m)
memory: that is to say, the memory requirements of the weights scales quadratically with the number of features. It is very easy to blow through your memory this way (and remember that you will need at least twice the size of the weights, since you also need to store the gradients.)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install srgan
You can use srgan like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page