Git Product home page Git Product logo

collagerl's Introduction

Neural Collage Transfer: Artistic Reconstruction via Material Manipulation (ICCV 2023)

Ganghun Lee, Minji Kim, Yunsu Lee, Minsu Lee, and Byoung-Tak Zhang

Description

An official implementation of the paper Neural Collage Transfer: Artistic Reconstruction via Material Manipulation.

Examples

Requirements

  • Python 3.8.5 (Conda)
  • PyTorch 1.11.0

We recommend using the following instruction after making a new Python 3.8.5 environment:
$ pip install -r requirements.txt

Inference

You can find infer.sh for testing your own image.

Goal image

The goal image should be placed in samples/goal/.
ex) samples/goal/boat.jpg

Material images

The materials are a set of images, so please make your own folder (e.g., newspaper/) containing all your material images.
Then move the folder to the directory samples/materials/.
ex) samples/materials/newspaper/

To make it quick, you can download a prepared set of newspapers from here.
(Vilkin,Aleksey and Safonov,Ilia. (2014). Newspaper and magazine images segmentation dataset. UCI Machine Learning Repository. https://doi.org/10.24432/C5N60V.)
There would be some kinds of files, but we only need the .jpgs (please delete the other files).

Instruction

Please make sure to set your goal/material path in infer.sh.
GOAL_PATH='samples/goals/your_own_goal.jpg' (not necessarily .jpg extension)
SOURCE_DIR='samples/materials/your_own_material_folder'

Now you can run the code.
$ bash infer.sh
It will take some time, and the results will be saved at samples/results/.

Configuration

  • GOAL_RESOLUTION - result image resolution
  • GOAL_RESOLUTION_FIT - fit the resolution as (horizontal | vertical | square)
  • SOURCE_RESOLUTION_RATIO - material image casting size (0-1)
  • SOURCE_LOAD_LIMIT - max num of material images to load (prevent RAM overloaded)
  • SOURCE_SAMPLE_SIZE - num of material images agent will see at each step
  • MIN_SOURCE_COMPLEXITY - minimum allowed complexity for materials (prevent using too simple ones) (>=0)
  • SCALE_ORDER - scale sequence for multi-scale collage
  • NUM_CYCLES - num of steps for each sliding window
  • WINDOW_RATIO - stride ratio of sliding window (0-1) (0.5 for stride = window_size x 0.5)
  • MIN_SCRAP_SIZE - the minimum allowed scrap size (prevent too small scraps) (0-1)
  • SENSITIVITY - complexity-sensitivity value for multi-scale collage
  • FIXED_T - fixed value of t_channel for multi-scale collage
  • FPS - fps for result video

You can also toggle the following options:

  • skip_negative_reward - Whether to undo actions that led to a negative MSE reward
  • paper_like - Whether to use the torn paper effect
  • disallow_duplicate - Whether to disallow duplicate usage of materials

We recommend trying adjusting SENSITIVITY first, in a range of about 1-5.

Training

Dataset

Goals and materials should be prepared for training.

Goal set

This code supports the following datasets for goals:

Material set

This code properly supports Describable Textures Dataset (DTD) for training only.

Please make your datasets be placed in the same data directory.
As an example, you can see our example tree of ~/Datasets.

Datasets/
├── dtd
│   ├── images
│   ├── imdb
│   └── labels
├── flowers-102
│   ├── imagelabels.mat
│   ├── jpg
│   └── setid.mat
├── imagenet
│   ├── meta.bin
│   ├── train
│   └── val
├── IntelScene
│   ├── train
│   └── val
└── MNIST
    └── raw

Then set --data_path in train.sh to your data directory.
ex) --data_path ~/Datasets

Wandb

Before training, please set up and log in to your wandb account for logging.

Instruction

Set --goal in train.sh to right name (imagenet | mnist | flower | scene).
Tip: imagenet is for general use.

--source means material, and it basically supports dtd only.
But you can use other materials for specific goal-material cases: (imagenet-imagenet, mnist-mnist, flower-flower, scene-scene).

Now just run the code to train:
$ bash train.sh

The progress and result will be saved at outputs/.
If your RAM get overloaded, you can decrease the replay memory size --replay_size.

Renderer (Shaper)

To make the rendering process differentiable, we implemented and pretrained shaper network as in shaper/shaper_training.ipynb.
We also used Kornia library for differentiable image translation.

Citation

If you find this work useful, please cite the paper as follows:

@inproceedings{lee2023neural,
  title={Neural Collage Transfer: Artistic Reconstruction via Material Manipulation},
  author={Lee, Ganghun and Kim, Minji and Lee, Yunsu and Lee, Minsu and Zhang, Byoung-Tak},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={2394--2405},
  year={2023}
}

Acknowledgements

Many thanks to the authors of Learning to Paint for inspiring this work. They also inspired our other work From Scratch to Sketch.
We also appreciate the contributors of Kornia for providing useful differentiable image processing operators.

collagerl's People

Contributors

northadventure avatar glebmachine avatar

Stargazers

Taicham avatar  avatar  avatar Egor Lynov avatar Ülgen Sarıkavak avatar  avatar  avatar J avatar Hergen Lehmann avatar  avatar Matt Shaffer avatar  avatar Tokarev Igor avatar junslog avatar Andrey Vlasenko avatar Sean Stevens avatar David Marx avatar  avatar Hoagy avatar  avatar  avatar Utkarsh Doshi avatar  avatar  avatar Sean avatar proxima centauri b avatar Matthew Butler avatar Doron Adler avatar DevinL avatar DAR avatar Julian Yap avatar lee daehee avatar  avatar Lu Ming avatar  avatar Minjung Kim avatar  avatar  avatar

Watchers

Matt Shaffer avatar  avatar

collagerl's Issues

Windows: Directory creation error due to invalid characters in the name

Error occurs when trying to create a directory with a name that contains invalid characters (->)

Preparing Test
Building Env
Traceback (most recent call last):
  File "infer.py", line 158, in <module>
    os.makedirs(sequence_path, exist_ok=True)
  File "C:\Users\glebm\AppData\Local\Programs\Python\Python38\lib\os.py", line 213, in makedirs 
    makedirs(head, exist_ok=exist_ok)
  File "C:\Users\glebm\AppData\Local\Programs\Python\Python38\lib\os.py", line 223, in makedirs 
    mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'samples/results/boat512horizontal_512->256->128->64->32->_newspaperx0.6_sensitivity3.0_cycle8_fixt9.0_mcskip20_nodup'

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.