https://github.com/ai-forever/controllednst

An implementation of Neural Style Transfer in PyTorch.

https://github.com/ai-forever/controllednst

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.4%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

An implementation of Neural Style Transfer in PyTorch.

Basic Info
  • Host: GitHub
  • Owner: ai-forever
  • Language: Jupyter Notebook
  • Default Branch: v1.0
  • Homepage:
  • Size: 8.94 MB
Statistics
  • Stars: 8
  • Watchers: 4
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 5 years ago · Last pushed over 5 years ago
Metadata Files
Readme

README.md

Pytorch-Neural-Style-Transfer

A PyTorch implementation of neural style transfer with color control described in the papers: * A Neural Algorithm of Artistic Style * Controlling Perceptual Factors in Neural Style Transfer

Examples

The Neckarfront in Tübingen, Germany

The results were obtained with the default settings except scale_img=0.5. Tested on Ubuntu 18.04 and python 3.6.9

When you reduce the image size, the style becomes more rough. Images from left to right: original image, scale_img=1.0, scale_img=0.4

Also you can control color preservation. Set preserve_colors=True to keep original content image colors. Example: original image, preserve_colors=False, preserve_colors=True

Requirements

  • PyTorch >=1.7.0, torchvision >=0.7.0
  • numpy, matplotlib, Pillow

You can install this with the command: pip install -r requirements.txt

Usage

python run.py --content <content_file> --style <style_file> Example : python run.py --content images/tubingen.jpg --style images/starry-night.jpg

Arguments

Required : * --content: Path to content image. * --style: Path to style image.

Optional : * --output: Filename of the output image. Default : result.jpg * --iters: The number of iterations to run. Default : 500 * --preserve_colors: Save colors of the content image. Default: False * --img_size: Size of the output image (set None to match to the size of content image). Default : None. Example : 512 or 768 1024 * --scale_img: Scaling factor of the image size. When img_size is not None, the new size will be scaled. Default : 1.0 * --print_every: The number of iterations to show info (set 0 to not show info). Default : 0 * --content_layers: VGG19 layers used for content loss. Default: r42 * --style_layers: VGG19 layers used for style loss. Default: r11 r21 r31 r41 r51 * --content_weights: Content loss weights for each content layer. Default: 1.0 * --style_weights: Style loss weights for each style layer. Default: 0.2 0.2 0.2 0.2 0.2

Using in code

Single image prediction. predict() method receives a path to image, a pillow image or a numpy array and returns pillow image. You can use all the parameters mentioned above. python from style_transfer import StyleTransfer from PIL import Image content = Image.open('images/tubingen.jpg') style = Image.open('images/starry-night.jpg') st = StyleTransfer() img = st.predict(content, style, scale_img=0.5, print_every=100) You can create a generator and set yield_every parameter as any number to get images during style transfer process. python gen = st.predict_iterator(content, style, yield_every=50) images = [] for image in gen: images.append(image) Also there is a predict_hr() method, that applies style transfer two times to the same image, but in different scaling, which allows you to get an image with better quality.

Parameters: - hr_scale - scaling factor of the image relative to original content image after first style transfer. Default : 1.0 - hr_iters - the number of iteration to run second style transfer. Default : 400

python img_hr = st.predict_hr(content,style,iters=300,scale_img=0.5,hr_scale=0.9) See more in example.ipynb

References

The implementation is based on the projects:

  • https://github.com/leongatys/PytorchNeuralStyleTransfer
  • https://github.com/leongatys/NeuralImageSynthesis/
  • https://github.com/hwalsuklee/tensorflow-style-transfer

Owner

  • Name: AI Forever
  • Login: ai-forever
  • Kind: organization
  • Location: Armenia

Creating ML for the future. AI projects you already know. We are non-profit organization with members from all over the world.

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels