Git Product home page Git Product logo

adacode's Introduction

AdaCode

This repository provides the official implementation for the paper

Learning Image-Adaptive Codebooks for Class-Agnostic Image Restoration
Kechun Liu, Yitong Jiang, Inchang Choi, Jinwei Gu
In ICCV 2023.

arXiv

Abstract: Recent work of discrete generative priors, in the form of codebooks, has shown exciting performance for image reconstruction and restoration, since the discrete prior space spanned by the codebooks increases the robustness against diverse image degradations. Nevertheless, these methods require separate training of codebooks for different image categories, which limits their use to specific image categories only (e.g. face, architecture, etc.), and fail to handle arbitrary natural images. In this paper, we propose AdaCode for learning image-adaptive codebooks for classagnostic image restoration. Instead of learning a single codebook for all categories of images, we learn a set of basis codebooks. For a given input image, AdaCode learns a weight map with which we compute a weighted combination of these basis codebooks for adaptive image restoration. Intuitively, AdaCode is a more flexible and expressive discrete generative prior than previous work. Experimental results show that AdaCode achieves state-of-the-art performance on image reconstruction and restoration tasks, including image super-resolution and inpainting.


Dependencies and Installation

  • Ubuntu >= 18.04
  • CUDA >= 11.0
  • Other required packages in requirements.txt
# git clone this repository
git clone https://github.com/kechunl/AdaCode.git
cd AdaCode 

# create new anaconda env
conda create -n AdaCode python=3.8
conda activate AdaCode 

# install python dependencies
pip install -r requirements.txt
python setup.py develop

Inference

# super resolution
python inference.py -i ./testset/sr -t sr -s 2 -o results_x2/
python inference.py -i ./testset/sr -t sr -s 4 -o results_x4/

# inpainting
python inference.py -i ./testset/inpaint -t inpaint -o results_inpaint/

Train the model

Preparation

Dataset

Please prepare the training and testing data follow descriptions in the paper. In brief, you need to crop 512 x 512 high resolution patches, and generate the low resolution patches with degradation_bsrgan function provided by BSRGAN. You may find generate_dataset.py and generate_inpaint_datset.py useful in generating low resolution and masked patches.

Model preparation

Before training, you need to

  • Download the pretrained stage 2 model: generator, discriminator
  • Put the pretrained models in experiments/pretrained_models
  • Specify their path in the corresponding option file.

Train SR model

python basicsr/train.py -opt options/stage3/train_Adacode_stage3.yaml

Acknowledgement

This project is based on FeMaSR.

adacode's People

Contributors

kechunl avatar

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.