GithubHelp home page GithubHelp logo

josephcatrambone / pytorchonnxrustgodot Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 12 KB

A prototype to add a trained PyTorch model to Godot via Onnx and Rust+GDNative.

License: MIT License

GDScript 12.66% Python 51.45% Rust 35.88%

pytorchonnxrustgodot's Introduction

PyTorchOnnxRustGodot

A prototype to add a trained PyTorch model to Godot via Onnx and Rust+GDNative.

Directory Structure and files:

The root folder (/) is a Rust Project (made via cargo new pix2cat --lib). Inside of it a new Godot Project is created.

/models/pix2cat.onnx would normally reside in the models folder and be packaged into the GDNative library at Rust build time. It has been replaced by two files, copied straight from https://github.com/JosephCatrambone/unet just so the whole project is self contained.

src/lib.rs and Cargo.toml are the required pieces to build the interface and wrap the ONNX model in a form that's usable. When cargo build --release is invoked, a DLL is created in the targets folder which can be linked into Godot by the GDNative script. The lib.rs uses GDNative to specify a Node subclass called Pix2Cat, which can be invoked through GDScript.

MainGame.tscn sets up the UI for the application, two TextureImages and a few buttons. MainGame.gd has all of the logic, which is 90% simply supporting drawing to the frame and copy data, with two lines actually dedicated to calling the ONNX model.

As a nice advantage to this setup, the lib.rs file uses include_bytes!, so there's no need to manage a standalone resource alongside the game. This should work if one is building for mobile platforms, too, but this is untested.

pytorchonnxrustgodot's People

Contributors

josephcatrambone avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.