All Projects → sugarme → Gotch

sugarme / Gotch

Licence: apache-2.0
Go binding for Pytorch C++ API (libtorch)

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gotch

Homie Esp8266
💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
Stars: ✭ 1,241 (+1310.23%)
Mutual labels:  framework
Lockstepplatform
Stars: ✭ 84 (-4.55%)
Mutual labels:  framework
Wire
Reactive data processing framework for visual programming tools
Stars: ✭ 86 (-2.27%)
Mutual labels:  framework
Framework
The Tastphp Framework Core
Stars: ✭ 82 (-6.82%)
Mutual labels:  framework
Casing
The UI Framework for Framer Classic. Manages data, components and views
Stars: ✭ 83 (-5.68%)
Mutual labels:  framework
Python Lambdarest
Flask like web framework for AWS Lambda
Stars: ✭ 84 (-4.55%)
Mutual labels:  framework
Infima
A UI framework that provides websites with the minimal CSS and JS needed to get started with building a modern responsive beautiful website
Stars: ✭ 82 (-6.82%)
Mutual labels:  framework
Pastepwn
Python framework to scrape Pastebin pastes and analyze them
Stars: ✭ 87 (-1.14%)
Mutual labels:  framework
Shellkit
Objective-C framework for running shell scripts.
Stars: ✭ 83 (-5.68%)
Mutual labels:  framework
Jsonapiframework
JsonApiFramework is a fast, extensible, and portable .NET framework for the reading and writing of JSON API documents. Currently working on ApiFramework 1.0 which is a new framework that supports the many enhancements documented in the 2.0 milestone of this project while being media type agnostic but will support media types like {json:api} and GraphQL for serialization/deserialization purposes.
Stars: ✭ 85 (-3.41%)
Mutual labels:  framework
Typetron
Modern Node.js framework for creating fully-featured apps
Stars: ✭ 82 (-6.82%)
Mutual labels:  framework
Qiankun
📦 🚀 Blazing fast, simple and complete solution for micro frontends.
Stars: ✭ 11,497 (+12964.77%)
Mutual labels:  framework
Spring Data Mongodb
Provide support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
Stars: ✭ 1,253 (+1323.86%)
Mutual labels:  framework
Unity Experiment Framework
UXF - Framework for creating human behaviour experiments in Unity
Stars: ✭ 81 (-7.95%)
Mutual labels:  framework
Lile
Easily generate gRPC services in Go ⚡️
Stars: ✭ 1,271 (+1344.32%)
Mutual labels:  framework
Enduro2d
Yet another 2d game engine of dreams (work in progress)
Stars: ✭ 82 (-6.82%)
Mutual labels:  framework
Opaline
NextJS for CLI tools
Stars: ✭ 84 (-4.55%)
Mutual labels:  framework
El Bot
🤖 基于 mirai-ts,运行于 Node.js,可配置、可自定义插件的 QQ 机器人框架。
Stars: ✭ 88 (+0%)
Mutual labels:  framework
Reazy
Reazy Framework - A simple services-based framework for React and React Native
Stars: ✭ 86 (-2.27%)
Mutual labels:  framework
Maze
Maze Applied Reinforcement Learning Framework
Stars: ✭ 85 (-3.41%)
Mutual labels:  framework

Gotch LicenseGo.Dev referenceTravis CIGo Report Card

Overview

Gotch creates a thin wrapper to Pytorch C++ APIs (Libtorch) to make use of its already optimized C++ tensor APIs (~ over 1400) and dynamic graph computation with CUDA support and provides idiomatic Go APIs for developing and implementing Deep Learning in Go.

Some features are

  • [x] Comprehensive Pytorch tensor APIs (~ 1404)
  • [x] Fully featured Pytorch dynamic graph computation
  • [x] JIT interface to run model trained/saved using PyTorch Python API
  • [x] Load pretrained Pytorch models and run inference
  • [x] Pure Go APIs to build and train neural network models with both CPU and GPU support
  • [x] Most recent image models
  • [ ] NLP Language models - Transformer in separate package built with GoTch and pure Go Tokenizer.

Gotch is in active development mode and may have API breaking changes. Feel free to pull request, report issues or discuss any concerns. All contributions are welcome.

Dependencies

  • Libtorch C++ v1.7.0 library of Pytorch

Installation

  • Default CUDA version is 10.1 if CUDA is available otherwise using CPU version.
  • Default Pytorch C++ API version is 1.7.0
    wget https://raw.githubusercontent.com/sugarme/gotch/v0.3.8/setup.sh
    chmod +x setup.sh

    # Default
    bash setup.sh

    # Specify CUDA version
    export CUDA_VER=YOUR_PC_CUDA_VERSION && bash setup.sh

    # CPU
    export CUDA_VER=cpu && bash setup.sh

Examples

Basic tensor operations

import (
	"fmt"

	"github.com/sugarme/gotch"
	ts "github.com/sugarme/gotch/tensor"
)

func basicOps() {

xs := ts.MustRand([]int64{3, 5, 6}, gotch.Float, gotch.CPU)
fmt.Printf("%8.3f\n", xs)
fmt.Printf("%i", xs)

/*
(1,.,.) =
   0.391     0.055     0.638     0.514     0.757     0.446  
   0.817     0.075     0.437     0.452     0.077     0.492  
   0.504     0.945     0.863     0.243     0.254     0.640  
   0.850     0.132     0.763     0.572     0.216     0.116  
   0.410     0.660     0.156     0.336     0.885     0.391  

(2,.,.) =
   0.952     0.731     0.380     0.390     0.374     0.001  
   0.455     0.142     0.088     0.039     0.862     0.939  
   0.621     0.198     0.728     0.914     0.168     0.057  
   0.655     0.231     0.680     0.069     0.803     0.243  
   0.853     0.729     0.983     0.534     0.749     0.624  

(3,.,.) =
   0.734     0.447     0.914     0.956     0.269     0.000  
   0.427     0.034     0.477     0.535     0.440     0.972  
   0.407     0.945     0.099     0.184     0.778     0.058  
   0.482     0.996     0.085     0.605     0.282     0.671  
   0.887     0.029     0.005     0.216     0.354     0.262  



TENSOR INFO:
        Shape:          [3 5 6]
        DType:          float32
        Device:         {CPU 1}
        Defined:        true
*/

// Basic tensor operations
ts1 := ts.MustArange(ts.IntScalar(6), gotch.Int64, gotch.CPU).MustView([]int64{2, 3}, true)
defer ts1.MustDrop()
ts2 := ts.MustOnes([]int64{3, 4}, gotch.Int64, gotch.CPU)
defer ts2.MustDrop()

mul := ts1.MustMatmul(ts2, false)
defer mul.MustDrop()

fmt.Printf("ts1:\n%2d", ts1)
fmt.Printf("ts2:\n%2d", ts2)
fmt.Printf("mul tensor (ts1 x ts2):\n%2d", mul)

/*
ts1:
 0   1   2  
 3   4   5  

ts2:
 1   1   1   1  
 1   1   1   1  
 1   1   1   1  

mul tensor (ts1 x ts2):
 3   3   3   3  
12  12  12  12  
*/


// In-place operation
ts3 := ts.MustOnes([]int64{2, 3}, gotch.Float, gotch.CPU)
fmt.Printf("Before:\n%v", ts3)
ts3.MustAdd1_(ts.FloatScalar(2.0))
fmt.Printf("After (ts3 + 2.0):\n%v", ts3)

/*
Before:
1  1  1  
1  1  1  

After (ts3 + 2.0):
3  3  3  
3  3  3  
*/
}

Simplified Convolutional neural network

import (
    "fmt"

    "github.com/sugarme/gotch"
    "github.com/sugarme/gotch/nn"
    ts "github.com/sugarme/gotch/tensor"
)

type Net struct {
    conv1 *nn.Conv2D
    conv2 *nn.Conv2D
    fc    *nn.Linear
}

func newNet(vs *nn.Path) *Net {
    conv1 := nn.NewConv2D(vs, 1, 16, 2, nn.DefaultConv2DConfig())
    conv2 := nn.NewConv2D(vs, 16, 10, 2, nn.DefaultConv2DConfig())
    fc := nn.NewLinear(vs, 10, 10, nn.DefaultLinearConfig())

    return &Net{
        conv1,
        conv2,
        fc,
    }
}

func (n Net) ForwardT(xs *ts.Tensor, train bool) *ts.Tensor {
    xs = xs.MustView([]int64{-1, 1, 8, 8}, false)

    outC1 := xs.Apply(n.conv1)
    outMP1 := outC1.MaxPool2DDefault(2, true)
    defer outMP1.MustDrop()

    outC2 := outMP1.Apply(n.conv2)
    outMP2 := outC2.MaxPool2DDefault(2, true)
    outView2 := outMP2.MustView([]int64{-1, 10}, true)
    defer outView2.MustDrop()

    outFC := outView2.Apply(n.fc)
    return outFC.MustRelu(true)
}

func main() {

    vs := nn.NewVarStore(gotch.CPU)
    net := newNet(vs.Root())

    xs := ts.MustOnes([]int64{8, 8}, gotch.Float, gotch.CPU)

    logits := net.ForwardT(xs, false)
    fmt.Printf("Logits: %0.3f", logits)
}

//Logits: 0.000  0.000  0.000  0.225  0.321  0.147  0.000  0.207  0.000  0.000

Play with gotch on Google Colab or locally

More coming soon...

Getting Started

License

Gotch is Apache 2.0 licensed.

Acknowledgement

  • This project has been inspired and used many concepts from tch-rs Libtorch Rust binding.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].