Official Chainer implementation of GP-GAN: Towards Realistic High-Resolution Image Blending (ACMMM 2019, oral)

Overview

GP-GAN: Towards Realistic High-Resolution Image Blending (ACMMM 2019, oral)

[Project] [Paper] [Demo] [Related Work: A2RL (for Auto Image Cropping)] [Colab]
Official Chainer implementation of GP-GAN: Towards Realistic High-Resolution Image Blending

Overview

source destination mask composited blended

The author's implementation of GP-GAN, the high-resolution image blending algorithm described in:
"GP-GAN: Towards Realistic High-Resolution Image Blending"
Huikai Wu, Shuai Zheng, Junge Zhang, Kaiqi Huang

Given a mask, our algorithm can blend the source image and the destination image, generating a high-resolution and realsitic blended image. Our algorithm is based on deep generative models Wasserstein GAN.

Contact: Hui-Kai Wu ([email protected])

Citation

@article{wu2017gp,
  title   = {GP-GAN: Towards Realistic High-Resolution Image Blending},
  author  = {Wu, Huikai and Zheng, Shuai and Zhang, Junge and Huang, Kaiqi},
  journal = {ACMMM},
  year    = {2019}
}

Getting started

  • The code is tested with python==3.5 and chainer==6.3.0 on Ubuntu 16.04 LTS.

  • Download the code from GitHub:

    git clone https://github.com/wuhuikai/GP-GAN.git
    cd GP-GAN
  • Install the requirements:

    pip install -r requirements/test/requirements.txt
  • Download the pretrained model blending_gan.npz or unsupervised_blending_gan.npz from Google Drive, and then put them in the folder models.

  • Run the script for blending_gan.npz:

    python run_gp_gan.py --src_image images/test_images/src.jpg --dst_image images/test_images/dst.jpg --mask_image images/test_images/mask.png --blended_image images/test_images/result.png

    Or run the script for unsupervised_blending_gan.npz:

    python run_gp_gan.py --src_image images/test_images/src.jpg --dst_image images/test_images/dst.jpg --mask_image images/test_images/mask.png --blended_image images/test_images/result.png --supervised False
  • Type python run_gp_gan.py --help for a complete list of the arguments.

Train GP-GAN step by step

Train Blending GAN

  • Download Transient Attributes Dataset here.

  • Crop the images in each subfolder:

    python crop_aligned_images.py --data_root [Path for imageAlignedLD in Transient Attributes Dataset]
  • Train Blending GAN:

    python train_blending_gan.py --data_root [Path for cropped aligned images of Transient Attributes Dataset]
  • Training Curve

  • Visual Result

    Training Set Validation Set

Training Unsupervised Blending GAN

  • Requirements

    pip install git+git://github.com/mila-udem/fuel.git@stable
  • Download the hdf5 dataset of outdoor natural images: ourdoor_64.hdf5 (1.4G), which contains 150K landscape images from MIT Places dataset.

  • Train unsupervised Blending GAN:

    python train_wasserstein_gan.py --data_root [Path for outdoor_64.hdf5]
  • Training Curve

  • Samples after training

Visual results

Mask Copy-and-Paste Modified-Poisson Multi-splines Supervised GP-GAN Unsupervised GP-GAN
Comments
  • Save a trained model

    Save a trained model

    Hello Hukai Wu.. The available pretrained model is saved as .npz file. During training for every epoch, separately for generator, discriminator and snapshot a .npz file is getting saved. How to save full trained model in .npz format?

    opened by supritbansod 8
  • Error while loading pretrained weights

    Error while loading pretrained weights

    I got the following error while loading the blending_GAN.npz for resuming the training. I want to fine tune the data on a different dataset. Its training on it from scratch but cannot load the provided weights

    Traceback (most recent call last):
      File "train_blending_gan.py", line 178, in <module>
        main()
      File "train_blending_gan.py", line 170, in main
        chainer.serializers.load_npz(args.resume, trainer)
      File "/usr/local/lib/python3.6/dist-packages/chainer/serializers/npz.py", line 243, in load_npz
        d.load(obj)
      File "/usr/local/lib/python3.6/dist-packages/chainer/serializer.py", line 83, in load
        obj.serialize(self)
      File "/usr/local/lib/python3.6/dist-packages/chainer/training/trainer.py", line 388, in serialize
        self.updater.serialize(serializer['updater'])
      File "/usr/local/lib/python3.6/dist-packages/chainer/training/updaters/standard_updater.py", line 265, in serialize
        iterator.serialize(serializer['iterator:' + name])
      File "/usr/local/lib/python3.6/dist-packages/chainer/iterators/multiprocess_iterator.py", line 218, in serialize
        self.current_position)
      File "/usr/local/lib/python3.6/dist-packages/chainer/serializers/npz.py", line 176, in __call__
        dataset = self.npz[key]
      File "/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py", line 266, in __getitem__
        raise KeyError("%s is not a file in the archive" % key)
    KeyError: 'updater/iterator:main/current_position is not a file in the archive'
    

    Note : The weight file was renamed for convenience, the path is correct.

    opened by trancenoid 8
  • Blending result of supervised GP-GAN

    Blending result of supervised GP-GAN

    Hi,

    Thanks for sharing your work.

    I have run the latest code and got the test result (supervised GP-GAN) like the following image: Result

    The result looks like it does not work properly. Is this an issue?

    opened by NTU-P04922004 8
  • requirements for test

    requirements for test

    installed cupy 6.3.0 and chainer 6.3.0 as requested, getting the following error for running run_gp_gan.py:

    File "cupy/core/core.pyx", line 2284, in cupy.core.core.tensordot_core File "cupy/core/core.pyx", line 2383, in cupy.core.core.tensordot_core File "cupy/cuda/cublas.pyx", line 927, in cupy.cuda.cublas.sgemmEx File "cupy/cuda/cublas.pyx", line 308, in cupy.cuda.cublas.check_status cupy.cuda.cublas.CUBLASError: CUBLAS_STATUS_EXECUTION_FAILED

    List of modules installed:

    chainer==6.3.0 cupy==6.3.0 cycler==0.10.0 decorator==4.4.2 fastrlock==0.5 filelock==3.0.12 imageio==2.9.0 kiwisolver==1.3.1 matplotlib==3.3.3 networkx==2.5 numpy==1.19.4 Pillow==8.0.1 pkg-resources==0.0.0 protobuf==3.7.1 pyparsing==2.4.7 python-dateutil==2.8.1 PyWavelets==1.1.1 scikit-image==0.15.0 scipy==1.5.4 six==1.15.0 typing==3.6.6 typing-extensions==3.6.6

    opened by nadavru1029 5
  • ValueError: axes don't match array

    ValueError: axes don't match array

    Upon selecting 2 images of the same size I run into this error for the run_gp_gan.py. Can someone guide. What could be the possible error I am committing?

    opened by aradhyamathur 5
  • What's the purpose of laplacian/gaussian_param?

    What's the purpose of laplacian/gaussian_param?

    First of all, thanks for the great work which point out a framework for high resolution on GAN!!

    But I don't understand what's the purpose of the functions "laplacian_param" and "gaussian_param" in gp_gan.py?

    Could you give me some hint?

    opened by u10116032 5
  • Hi, Thank you for your work.I just want to ask something when I run your code for my work it gave me nothing and it just stuck here like this.

    Hi, Thank you for your work.I just want to ask something when I run your code for my work it gave me nothing and it just stuck here like this.

    python run_gp_gan.py --image_size 640 --src_image im2.jpg --dst_image im1.jpg --mask_image mask_screenshot_05.09.2022.png --blended_image images/test_images/result.jpg
    Input arguments: nef: 64 ngf: 64 nc: 3 nBottleneck: 4000 ndf: 64 image_size: 640 color_weight: 1 sigma: 0.5 gradient_kernel: normal smooth_sigma: 1 supervised: True nz: 100 n_iteration: 2 gpu: 0 g_path: models/blending_gan.npz unsupervised_path: models/unsupervised_blending_gan.npz list_path: result_folder: blending_result src_image: im2.jpg dst_image: im1.jpg mask_image: mask_screenshot_05.09.2022.png blended_image: images/test_images/result.jpg

    I waited for so long and I didn't,t get output result

    opened by noreenanwar 4
  • Problems installing via Docker File

    Problems installing via Docker File

    Successfully built the docker container. Running your test script (in docker) or doing import chainer in the python3 console results in following output. However importing other installed packages works (like numpy).

    >>> import chainer Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/dist-packages/chainer/__init__.py", line 10, in <module> from chainer import backends # NOQA File "/usr/local/lib/python3.5/dist-packages/chainer/backends/__init__.py", line 1, in <module> from chainer.backends import cuda # NOQA File "/usr/local/lib/python3.5/dist-packages/chainer/backends/cuda.py", line 45, in <module> from chainer.backends import _cpu File "/usr/local/lib/python3.5/dist-packages/chainer/backends/_cpu.py", line 8, in <module> import chainerx File "/usr/local/lib/python3.5/dist-packages/chainerx/__init__.py", line 28, in <module> from chainerx.creation.from_data import asanyarray # NOQA ImportError: No module named 'chainerx.creation'

    Following the installation for chainerX resulted in output that suggests that everything is properly installed.

    Did I miss something? I executed following command in the docker image: python3 run_gp_gan.py --src_image images/test_images/src.jpg --dst_image images/test_images/dst.jpg --mask_image images/test_images/mask.png --blended_image images/test_images/result.png

    How I used docker: Built the image with docker image build -t gp-gan:1.0 .Then I started the container via docker container run -dit --name gp-gan gp-gan:1.0 and then attached via docker attach gp-gan

    Any help would be greatly appreciated! :)

    opened by mowolf 4
  • Parameters for reproducing Figure 10.

    Parameters for reproducing Figure 10.

    Hi - thanks for making an implementation of your work available. Could you share the CLI input arguments that were used for creating the bear/beach example from Figure 10 please? Using the images from here, I haven't been able to obtain comparable results with the default parameter settings. I can reproduce the results in images/test_images correctly with the default params. Thanks in advance!

    opened by giles-shaw 3
  • Pretrained model is not accessible

    Pretrained model is not accessible

    Hello! I was tried to look on the performance of pretrained model throw all available links (GitHub and Colab), but it seems the model weights are under private configuration at the moment. Can you help in accessing please?

    Screenshot 2021-11-09 at 16 36 51 (2)
    opened by akhmedov 3
  • image width height different causing error

    image width height different causing error

    Hi @wuhuikai , I have image with 600x799, and I initially just not modify the image size, and get following error: copy_paste_init = obj_im_pyramid[0] * mask_init + bg_im_pyramid[0] * (1 - mask_init) ValueError: operands could not be broadcast together with shapes (64,64,4) (64,64,3)

    Then due to there is no separate width, height argument, I pass in --image_size=800, and the python execution hangs after it print out input arguments. Any idea what I did wrong?

    opened by shiyingZhang90 3
  • [Urgent!!!] When I use my own datasets, after I run the sheet

    [Urgent!!!] When I use my own datasets, after I run the sheet "train_blending_gan.py", the command line seems to be stuck and no any errors!

    When I use my own datasets, after I run the sheet "train_blending_gan.py", the command line seems to be stuck like this:

    Input arguments:
            nef: 64
            ngf: 64
            nc: 3
            nBottleneck: 4000
            ndf: 64
            lr_d: 0.0002
            lr_g: 0.002
            beta1: 0.5
            l2_weight: 0.999
            gpu: 1
            n_epoch: 25
            data_root: steel_plates
            load_size: 64
            image_size: 64
            ratio: 0.5
            val_ratio: 0.05
            d_iters: 5
            clamp_lower: -0.01
            clamp_upper: 0.01
            experiment: encoder_decoder_blending_result
            test_folder: samples
            workers: 4
            batch_size: 64
            test_size: 64
            train_samples: 150000
            test_samples: 256
            manual_seed: 5
            resume: 
            snapshot_interval: 1
            print_interval: 1
            plot_interval: 10
    
    Create & Init models ...
            Init G network ...
            Init D network ...
            Copy models to gpu 1 ...
    Init models done ...
    
    Load images from steel_plates ...
            21 folders in total, 1 val folders ...
            Trainset contains 150000 image files
            Valset contains 256 image files
    
    Saving samples to encoder_decoder_blending_result/samples ...
    
    
    
    

    And, when I kill this script, the command line shown like this:

    ^CTraceback (most recent call last):
      File "train_blending_gan.py", line 183, in <module>
        main()
      File "train_blending_gan.py", line 164, in main
        train_batch = [trainset[idx][0] for idx in range(args.test_size)]
      File "train_blending_gan.py", line 164, in <listcomp>
        train_batch = [trainset[idx][0] for idx in range(args.test_size)]
      File "/home/wyy/anaconda3/envs/python36/lib/python3.6/site-packages/chainer/dataset/dataset_mixin.py", line 67, in __getitem__
        return self.get_example(index)
      File "/ssd3/wyy/projects/GP-GAN/dataset.py", line 84, in get_example
        obj_croped = self._crop(obj, rw, rh, sx, sy)
      File "/ssd3/wyy/projects/GP-GAN/dataset.py", line 66, in _crop
        im = resize(im, (rw, rh), order=1, preserve_range=False, mode='constant')
      File "/home/wyy/anaconda3/envs/python36/lib/python3.6/site-packages/skimage/transform/_warps.py", line 148, in resize
        cval=cval, mode=ndi_mode)
      File "/home/wyy/anaconda3/envs/python36/lib/python3.6/site-packages/scipy/ndimage/filters.py", line 299, in gaussian_filter
        mode, cval, truncate)
      File "/home/wyy/anaconda3/envs/python36/lib/python3.6/site-packages/scipy/ndimage/filters.py", line 217, in gaussian_filter1d
        return correlate1d(input, weights, axis, output, mode, cval, 0)
      File "/home/wyy/anaconda3/envs/python36/lib/python3.6/site-packages/scipy/ndimage/filters.py", line 95, in correlate1d
        origin)
    KeyboardInterrupt
    

    Is the size of the image in my dataset (5000x3000) too large? Or is it something else? I look forward to your reply and would appreciate it.

    opened by TheWangYang 2
Owner
Wu Huikai
Wu Huikai
CoReD: Generalizing Fake Media Detection with Continual Representation using Distillation (ACMMM'21 Oral Paper)

CoReD: Generalizing Fake Media Detection with Continual Representation using Distillation (ACMMM'21 Oral Paper) (Accepted for oral presentation at ACM

Minha Kim 1 Nov 12, 2021
Official implementation of the paper 'Details or Artifacts: A Locally Discriminative Learning Approach to Realistic Image Super-Resolution' in CVPR 2022

LDL Paper | Supplementary Material Details or Artifacts: A Locally Discriminative Learning Approach to Realistic Image Super-Resolution Jie Liang*, Hu

null 150 Dec 26, 2022
《Towards High Fidelity Face Relighting with Realistic Shadows》(CVPR 2021)

Towards High Fidelity Face-Relighting with Realistic Shadows Andrew Hou, Ze Zhang, Michel Sarkis, Ning Bi, Yiying Tong, Xiaoming Liu. In CVPR, 2021. T

null 114 Dec 10, 2022
AOT-GAN for High-Resolution Image Inpainting (codebase for image inpainting)

AOT-GAN for High-Resolution Image Inpainting Arxiv Paper | AOT-GAN: Aggregated Contextual Transformations for High-Resolution Image Inpainting Yanhong

Multimedia Research 214 Jan 3, 2023
Copy Paste positive polyp using poisson image blending for medical image segmentation

Copy Paste positive polyp using poisson image blending for medical image segmentation According poisson image blending I've completely used it for bio

Phạm Vũ Hùng 2 Oct 19, 2021
pytorch implementation for Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network arXiv:1609.04802

PyTorch SRResNet Implementation of Paper: "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network"(https://arxiv.org/abs

Jiu XU 436 Jan 9, 2023
Implementation of 'lightweight' GAN, proposed in ICLR 2021, in Pytorch. High resolution image generations that can be trained within a day or two

512x512 flowers after 12 hours of training, 1 gpu 256x256 flowers after 12 hours of training, 1 gpu Pizza 'Lightweight' GAN Implementation of 'lightwe

Phil Wang 1.5k Jan 2, 2023
Official PyTorch implementation of the paper "Recycling Discriminator: Towards Opinion-Unaware Image Quality Assessment Using Wasserstein GAN", accepted to ACM MM 2021 BNI Track.

RecycleD Official PyTorch implementation of the paper "Recycling Discriminator: Towards Opinion-Unaware Image Quality Assessment Using Wasserstein GAN

Yunan Zhu 23 Nov 5, 2022
This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures

Introduction This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures. @inproceedings{Wa

Jiaqi Wang 42 Jan 7, 2023
FuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space OptimizationFuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space Optimization

FuseDream This repo contains code for our paper (paper link): FuseDream: Training-Free Text-to-Image Generation with Improved CLIP+GAN Space Optimizat

XCL 191 Dec 31, 2022
Official repository for "Restormer: Efficient Transformer for High-Resolution Image Restoration". SOTA for motion deblurring, image deraining, denoising (Gaussian/real data), and defocus deblurring.

Restormer: Efficient Transformer for High-Resolution Image Restoration Syed Waqas Zamir, Aditya Arora, Salman Khan, Munawar Hayat, Fahad Shahbaz Khan,

Syed Waqas Zamir 906 Dec 30, 2022
A Fast and Stable GAN for Small and High Resolution Imagesets - pytorch

A Fast and Stable GAN for Small and High Resolution Imagesets - pytorch The official pytorch implementation of the paper "Towards Faster and Stabilize

Bingchen Liu 455 Jan 8, 2023
【ACMMM 2021】DSANet: Dynamic Segment Aggregation Network for Video-Level Representation Learning

DSANet: Dynamic Segment Aggregation Network for Video-Level Representation Learning (ACMMM 2021) Overview We release the code of the DSANet (Dynamic S

Wenhao Wu 46 Dec 27, 2022
A fast poisson image editing implementation that can utilize multi-core CPU or GPU to handle a high-resolution image input.

Poisson Image Editing - A Parallel Implementation Jiayi Weng (jiayiwen), Zixu Chen (zixuc) Poisson Image Editing is a technique that can fuse two imag

Jiayi Weng 110 Dec 27, 2022
Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging

Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging This repository contains an implementation

Computational Photography Lab @ SFU 1.1k Jan 2, 2023
Pytorch implementation for "Large-Scale Long-Tailed Recognition in an Open World" (CVPR 2019 ORAL)

Large-Scale Long-Tailed Recognition in an Open World [Project] [Paper] [Blog] Overview Open Long-Tailed Recognition (OLTR) is the author's re-implemen

Zhongqi Miao 761 Dec 26, 2022
This is an official implementation of "Polarized Self-Attention: Towards High-quality Pixel-wise Regression"

Polarized Self-Attention: Towards High-quality Pixel-wise Regression This is an official implementation of: Huajun Liu, Fuqiang Liu, Xinyi Fan and Don

DeLightCMU 212 Jan 8, 2023
Official implement of Paper:A deeply supervised image fusion network for change detection in high resolution bi-temporal remote sening images

A deeply supervised image fusion network for change detection in high resolution bi-temporal remote sensing images 深度监督影像融合网络DSIFN用于高分辨率双时相遥感影像变化检测 Of

Chenxiao Zhang 135 Dec 19, 2022
Pytorch implementation for reproducing StackGAN_v2 results in the paper StackGAN++: Realistic Image Synthesis with Stacked Generative Adversarial Networks

StackGAN-v2 StackGAN-v1: Tensorflow implementation StackGAN-v1: Pytorch implementation Inception score evaluation Pytorch implementation for reproduci

Han Zhang 809 Dec 16, 2022