Skip to content

Implementation of Neural Art in PyTorch using C++ and Python

Notifications You must be signed in to change notification settings

adityak2920/NeuralArt-in-pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Neural Art in PyTorch

Open In Colab

This repository cotains implementation of Neural Art using PyTorch. Neural Art is also famous with the name of Neural Style Transfer. In this repository , I have used VGG16 pretrained model for extracting features. You can read the paper here

Instructions for using C++ scipts

For using this project you need to follow some steps:

  1. First clone this repository in your system and then navigate to repository folder

    git clone https://github.com/adityak2920/NeuralArt-in-pytorch.git
    cd NeuralArt-in-pytorch/cpp
    
  2. Create a folder build

    mkdir build && cd build
    
  3. Before procedding further we need to download latest distribution of libtorch to build our application which you can download from here. After downloading, unzip the folder and your libtorch directory should looks like this:

    libtorch/
            bin/
            include/
            lib/
            share/
            build-hash
            build-version
    
  4. Now run these commands to build the application

    cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch ..
    cmake --build . --config Release
    
  5. To run our app, we will need vgg19 to torchscript form:

        import torchvision
        import torch
        model = torchvision.models.vgg19(pretrained=True)
        x = torch.rand(1, 3, 448, 448)
        traced_cell = torch.jit.trace(model, x)
        traced_cell.save('model.pt')
    

    Now use the path of saved model in neural.cpp .

  6. Now you can run your app with(you can specify name of app in cmake file)

      ./your_app
    
  7. From next time you can recompile and run your app using

    make
    ./your_app
    

Here, are some of the results after training for some time using Tesla K80 GPU on Google Collab:

Here are some other images generated using same content image but with different style images and the results are pretty good.

neural2 neural3 neural4

About

Implementation of Neural Art in PyTorch using C++ and Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages