Coder Social home page Coder Social logo

dbraun / pytorchtop-cpumem Goto Github PK

View Code? Open in Web Editor NEW
50.0 7.0 3.0 24.49 MB

PyTorch / libtorch in TouchDesigner based on the CPUMemoryTOP example.

License: MIT License

CMake 21.03% C++ 58.59% C 0.08% Objective-C 20.30%
touchdesigner pytorch libtorch

pytorchtop-cpumem's Introduction

PyTorchTOP

Update December 27, 2020: a GPU version of PyTorchTOP has been released here. This branch demonstrates Style Transfer.

Installation on Windows (no OSX support)

Download LibTorch

From https://pytorch.org/ download, 1.4 (stable), Windows, LibTorch, C++/Java, CUDA 10.1

TouchDesigner Hack :/

I've tested TouchDesigner 2020.22080. From the place where you downloaded LibTorch, go to libtorch\lib. Then take libiomp5md.dll and overwrite the libiomp5md.dll for your TouchDesigner: C:\Program Files\Derivative\TouchDesigner099\bin.

Download PyTorchTOP.dll from the Releases page of this repo. Place it in this repo's Plugins folder. Copy the DLL files from libtorch\lib into Plugins too. Congrats! You're done and can open PyTorchTOP.toe! The remaining steps are for building PyTorchTOP.dll.

CUDA and CUDNN

From NVIDIA, install CUDA 10.1, which will create C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1. Download cuDNN 7.6.5 for 10.1 and place the files into this folder too.

CMake

I've tested CMake 3.15.1. Inside the root of PyTorchTOP-cpumem:

mkdir build_release
cd build_release
cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch ..

where /path/to/libtorch should be the full path to the unzipped LibTorch distribution. Expected output:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.
x64 architecture in use
-- Caffe2: CUDA detected: 10.1
-- Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe
-- Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1
-- Caffe2: Header version is: 10.1
-- Found cuDNN: v7.6.5  (include: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include, library: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64/cudnn.lib)
-- Autodetected CUDA architecture(s):  7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/PyTorchTOP-cpumem/build_release

If it works, you should end up with a Visual Studio Solution build_release\PyTorchTOP.sln. Open it and select the Release build. Press F5 to build the DLL and launch TouchDesigner.

The steps to build a debug-mode Visual Studio solution are similar. Instead of build_release, make a folder build_debug.

mkdir build_debug
cd build_debug
set DEBUG=1
cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch-debug-version ..

Now you can build build_debug\PyTorchTOP.sln in Debug mode. You should copy the .pdb files from the libtorch-debug-version folder to this repo's Plugins folder in order to help with stack traces during debugging.

Neural Style Transfer

This project uses models that have been exported from Fast Neural Style. These are the steps to creating your own models. Install pytorch for python. Open neural_style\neural_style.py. Look for this line

output = style_model(content_image).cpu()

Before it, write these lines:

traced_script_module = torch.jit.trace(style_model, content_image)
traced_script_module.save("traced_model.pt")

To save a new traced_model.pt, run:

python neural_style/neural_style.py eval --content-image test640x360.jpeg --model saved_models/udnie.pth --output-image myoutput.png --cuda 1

Notice that you've provided a content image of a certain resolution, selected a model path, and enabled cuda. Because test640x360.jpeg is a 640x360 image, the newly created traced_model.pt will work with 640x360 images in TouchDesigner. Export a model for each size resolution you need and rename as necessary. In TouchDesigner, select the model with the custom parameter Modelfilepath.

Extra notes

Use the channel mix TOP to swap your red channel and blue channel before sending to PyTorchTOP.

The Future

  • Fix the clumsiness of the RGBA-BGRA swapping in TouchDesigner.
  • Better handling of input resolution and output resolution. Can it be stored in the pt file?

pytorchtop-cpumem's People

Contributors

dbraun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorchtop-cpumem's Issues

This is awesome

Hi David,

Not an issue at all but this is amazing, and thank you for open sourcing it, as well as all you other awesome TouchDesigner discovering!

  • Barak

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.