Generative Adversarial Network in Go via Gorgonia

Overview

Generative adversarial networks

Recipe for simple GAN in Golang ecosystem via Gorgonia library

Table of Contents

About

This just a repository with simple example how to build GAN in Gorgonia

What is GAN?

Note: although there is code with some wrappings/aliasing and helping abstractions and functions in repository, this does not pretend to be high-level machine learning framework

Note #2: By the way... Code is ugly since I've decided to handle errors instead of using panic(...) calls. Panicing is considered to be in main functions of examples only

Current examples contain limited set of layer types:

  • Linear
  • Convolutional
  • Maxpool
  • AvgPool

Why

Just want to do that in Golang ecosystem.

Instruments

Code is written on Golang - https://golang.org/

Used machine learning library - Gorgonia

Plotting library - gonum

Usage

  • Get the repo

    git clone https://github.com/LdDl/gan-go.git
  • Navigate to examples folder

    cd gan-go
    cd cmd/examples
  • Pick one of examples. E.g. parabola:

    cd parabola
  • Run example

    go run main.go
    
  • Output

    After programm terminates there should be multiple files:

    1. Single image for reference function - reference_function.png
    2. Multiple images for generated data on N-th epoch - gen_reference_fun_%N-th epoch%.png
    3. Single image for generated data on last epoch - gen_reference_func_final.png

    Example for parabola:

    Actual reference function:

    Reference function

    Generated data on 0-th epoch:

    Generated data on 0-th epoch

    Generated data on 10-th epoch:

    Generated data on 10-th epoch

    Generated data on 60-th epoch:

    Generated data on 60-th epoch

    Generated data on 150-th epoch:

    Generated data on 150-th epoch

    Generated data on last epoch:

    Generated data on last epoch

Code explanation

@TODO

Support and contributing

If you have troubles or questions please open an issue.

If you want to improve this library / fix some bugs and etc. you can make PR

Issues
  • [FEATURE REQUEST] Dropout option

    [FEATURE REQUEST] Dropout option

    Is your feature request related to a problem? Please describe. There is no dropout property for layer - https://en.wikipedia.org/wiki/Dilution_(neural_networks)

    Describe the solution you'd like and provide pseudocode examples if you can Implement this feature as option for any layer

    Describe alternatives you've considered and provide pseudocode examples if you can Implement this feature as separate layer (I prefer this option)

    Additional context nope

    enhancement 
    opened by LdDl 1
  • [FEATURE REQUEST] Variadic inputs

    [FEATURE REQUEST] Variadic inputs

    Is your feature request related to a problem? Please describe. It's possible to provide only single input per Fwd(input *gorgonia.Node, batchSize int) call currently For some RNN/LSTM/GRU need would be nice to have Fwd(inputs ...*gorgonia.Node, batchSize int) with variadic *gorgonia.Node paramters.

    Describe the solution you'd like and provide pseudocode examples if you can

    • Just do simple code replaces
    • Don't forget to check inputs slice len
    • Instead of input call _inputs[0]
    • Variadic parameter should be last (final) in function call. So move batch size to first position.

    Describe alternatives you've considered and provide pseudocode examples if you can nope

    Additional context nope

    enhancement hacktoberfest hacktoberfest-2021 hacktoberfest-accepted 
    opened by LdDl 0
  • [FEATURE REQUEST] Implement Embedded layer type

    [FEATURE REQUEST] Implement Embedded layer type

    Is your feature request related to a problem? Please describe. Create embedding layer for NLP purposes. Related links:

    • https://en.wikipedia.org/wiki/Word_embedding
    • https://stats.stackexchange.com/questions/270546/how-does-keras-embedding-layer-work
    • https://pytorch.org/docs/stable/generated/torch.nn.Embedding.html
    • https://keras.io/api/layers/core_layers/embedding/

    Describe the solution you'd like and provide pseudocode examples if you can Create new 'case' entity and fill it with (pseudo):

    x = flatten(input)
    x = indicex(weights, x)
    x = reshape(x, [input.shape..., embedding_size])
    

    Describe alternatives you've considered and provide pseudocode examples if you can nope

    Additional context Parameter for Fwd() function is only one: embedding_size Parameters for layer construction: number of clasess, shape of input

    enhancement 
    opened by LdDl 0
  • Activation opts + Softmax

    Activation opts + Softmax

    1. Added Softmax function from Gorgonia - https://github.com/gorgonia/gorgonia/blob/d77dcd9135e961ba5f477e209aa057b3cf437a58/operations.go#L182
    2. Now every activation function accepts both gorgonia.Node and variadic Option struct (read further)
    3. Added Option struct.
    // Options Struct for holding options for certain activation functions.
    type Options struct {
    	Axis []int
    }
    

    Current fields: Axis. Possible usage: Due the introducing of Softmax function, it's needed to add axis=0,1,...,N option for some reasons. 4. Added WithActivationOptions

    // WithActivationOptions Wrap function with custom options
    func WithActivationOptions(f ActivationFunc, opts ...Options) ActivationFunc {
    	newF := func(a *gorgonia.Node, opts_ignored ...Options) (*gorgonia.Node, error) {
    		// Apply parent-scoped options to function call
    		return f(a, opts...)
    	}
    	return newF
    }
    

    Possible usage:

    // While building single layer of []*gan.Layer slice:
    {
        WeightNode: /* some weights node */,
        BiasNode:   /* some bias node */,
        Type:       gan.LayerLinear,
    
        // Use softmax for user defined axis
        Activation: gan.WithActivationOptions(gan.Softmax, gan.Options{Axis: []int{1, 2}}),
    }
    
    enhancement 
    opened by LdDl 0
  • Layer interface

    Layer interface

    1. Reduce duplicating of code for .Fwd() method of each neural network type (GAN/Discriminator/Generator) by introducing Network structure - https://github.com/LdDl/gan-go/commit/a6db912b700e9c528d03db00aca1d420ce213e1f
    2. Updated README.md
    3. Updated example for symbol generation: moved from normal distribution to uniform one
    4. Prepared aliases to Gorgonia's gen-functions. It could reduce confusion between 'gan.Sigmoid and gorgonia.Sigmoid'. It is on same namespace scope now.
    enhancement 
    opened by LdDl 0
  • Layers types

    Layers types

    1. Added Convolutional layer type
    2. Added Flatten layer type
    3. Added Maxpool layer type
    4. Added Reshape layer type
    5. Added Flatten layer type
    6. Added example of training simple CNN to classify character (not as GAN, only Discriminator) + README.md
    7. Added example of smiley face generator + README.md
    8. Added some if/else statements for broadcast and batch processing
    9. Updated main README.md
    10. Change GenerateTestSamples to GenerateUniformTestSamples for uniform distribution and GenerateNormTestSamples for normal distribution
    11. Added reshape option into GenerateUniformTestSamples and GenerateNormTestSamples functions
    12. Added MSELoss function
    enhancement 
    opened by LdDl 0
  • [FEATURE REQUEST] Implement LSTM layer type

    [FEATURE REQUEST] Implement LSTM layer type

    Is your feature request related to a problem? Please describe. There is not LSTM layer type (LSTM - Long Short Term Memory).

    Describe the solution you'd like and provide pseudocode examples if you can Implement it and create proper docs

    Describe alternatives you've considered and provide pseudocode examples if you can nope

    Additional context It would be cool to have an example of LSTM also.

    enhancement help wanted hacktoberfest hacktoberfest-2021 hacktoberfest-accepted 
    opened by LdDl 2
  • [FEATURE REQUEST] Would be great to see benchmarks against Python/CUDA/PyTorch

    [FEATURE REQUEST] Would be great to see benchmarks against Python/CUDA/PyTorch

    Is your feature request related to a problem? Please describe. There is no any benchmarks

    Describe the solution you'd like and provide pseudocode examples if you can Benchmarks against:

    1. Python/CPU/PyTorch
    2. Python/GPU(CUDA)/PyTorch
    3. Python/CPU/Tensorflow v2
    4. Python/GPU(CUDA)/Tensorflow v2

    Describe alternatives you've considered and provide pseudocode examples if you can nope

    Additional context nope

    enhancement help wanted good first issue 
    opened by nikolaydubina 0
Releases(v0.2.0)
  • v0.2.0(Sep 8, 2021)

    What's new

    1. Added LayerEmbedding. This layer very helpful for NLP tasks. Implementation is inspired by this SO question: https://stats.stackexchange.com/questions/182775/what-is-an-embedding-layer-in-a-neural-network
    2. Added example where Embedding has been used: https://github.com/LdDl/gan-go/tree/master/cmd/examples/train_embedding
    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Jul 19, 2021)

    What's new

    • Added next loss functions:

      • Cross entropy - https://en.wikipedia.org/wiki/Cross_entropy#Cross-entropy_loss_function_and_logistic_regression
      • Binary cross entropy - Its is cross entropy basically, but for two training classes.
      • L1 (least absolute deviations) - https://en.wikipedia.org/wiki/Least_absolute_deviations
      • Huber (pseudo) - https://en.wikipedia.org/wiki/Huber_loss#Pseudo-Huber_loss_function
    • Updated MSE loss function

    • Updated state of ToDo list in README.md

    • Minor cleanups

    Now we are moving to implement RNN stuff for LSTM purposes.

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Jul 12, 2021)

    What's new

    • Added Convolutional layer type
    • Added Flatten layer type
    • Added Maxpool layer type
    • Added Reshape layer type
    • Added Flatten layer type
    • Added example of training simple CNN to classify character (not as GAN, only Discriminator) - https://github.com/LdDl/gan-go/tree/master/cmd/examples/train_cnn
    • Added example of smiley face generator - https://github.com/LdDl/gan-go/tree/master/cmd/examples/generate_smiley_face
    • Added some if/else statements for broadcast and batch processing
    • Added reshape option into GenerateUniformTestSamples and GenerateNormTestSamples functions
    • Added MSELoss function
    • Added Network structure to reduce duplicating of code for .Fwd() method of each neural network type (GAN/Discriminator/Generator)
    • Prepared aliases to Gorgonia's gen-functions. It could reduce confusion between 'gan.Sigmoid and gorgonia.Sigmoid'. It is on same namespace scope now.
    • Updated main README.md

    For more informatino see these PR's: https://github.com/LdDl/gan-go/pull/1 https://github.com/LdDl/gan-go/pull/2

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Apr 25, 2021)

Owner
Dimitrii Lopanov
Golang dev (computer vision / telemetry) Mail: [email protected] Telegram: https://t.me/sexyk
Dimitrii Lopanov
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia 4.5k May 16, 2022
A multilayer perceptron network implemented in Go, with training via backpropagation.

Neural Go I'm in the process of making significant changes to this package, particularly, to make it more modular, and to base it around an actual lin

Schuyler Erle 63 Mar 5, 2022
fonet is a deep neural network package for Go.

fonet fonet is a deep neural network package for Go. It's mainly created because I wanted to learn about neural networks and create my own package. I'

Barnabás Pataki 67 May 13, 2022
Artificial Neural Network

go-deep Feed forward/backpropagation neural network implementation. Currently supports: Activation functions: sigmoid, hyperbolic, ReLU Solvers: SGD,

Patrik Ehrencrona 365 May 15, 2022
Neural Network for Go.

gonet gonet is a Go module implementing multi-layer Neural Network. Install Install the module with: go get github.com/dathoangnd/gonet Import it in

Dat Hoang 74 Apr 21, 2022
onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.

This is a Go Interface to Open Neural Network Exchange (ONNX). Overview onnx-go contains primitives to decode a onnx binary model into a computation b

Olivier Wulveryck 388 May 1, 2022
Golang Neural Network

Varis Neural Networks with GO About Package Some time ago I decided to learn Go language and neural networks. So it's my variation of Neural Networks

Artem Filippov 44 Mar 20, 2022
A neural network library built in Go

go-mind A neural network library built in Go. Usage import "github.com/stevenmiller888/go-mind" m := mind.New(0.7, 10000, 3, "sigmoid") m.Learn([][]

Steven Miller 165 Mar 16, 2022
Example of Neural Network models of social and personality psychology phenomena

SocialNN Example of Neural Network models of social and personality psychology phenomena This repository gathers a collection of neural network models

null 6 Jan 15, 2022
Neural network in Go

network Package network is a simple implementation of a nonbiased neural network. The networks created by this package can be trained with backpropaga

Shingirai Chanakira 0 Nov 25, 2021
Go (Golang) encrypted deep learning library; Fully homomorphic encryption over neural network graphs

DC DarkLantern A lantern is a portable case that protects light, A dark lantern is one who's light can be hidden at will. DC DarkLantern is a golang i

Raven 1 Dec 2, 2021
Tpu-traffic-classifier - This small program creates ipsets and iptables rules for nodes in the Solana network

TPU traffic classifier This small program creates ipsets and iptables rules for

Triton One 7 May 16, 2022
Go-Generative-Art-A - Generate PNG art from source images! GOLang Generative Art

GO Lang Generative Art Tool A Take source images and generate art utilizing sour

null 2 Mar 20, 2022
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia 4.5k May 16, 2022
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia 4.5k May 16, 2022
:triangular_ruler: Create beautiful generative image patterns from a string in golang.

geopattern Create beautiful generative image patterns from a string in golang. Go port of Jason Long's awesome GeoPattern library. Read geopattern's d

Pravendra Singh 1.2k May 5, 2022
Generative Julia Set Image in Go

julia Generative Julia Set Image in Go In general terms, a Julia set is the boundary between points in the complex number plane or the Riemann sphere

null 19 Mar 20, 2022
generativeart is a Go package to generate many kinds of generative art.

generativeart is a Go package to generate many kinds of generative art. The goal is to collect some excellent generative art (implemented in R or Processing), and rewrite them in Go again

null 733 May 11, 2022
A suite of tools for NFT generative art.

nftool A suite of tools for NFT generative art. Features Traits/Attributes/Properties Generation Configure custom rarity Generate collection attribute

Aleph Retamal 123 May 16, 2022
Webserver I built to serve Infura endpoints. Deployable via k8s and AWS EKS. Load testable via k6 tooling, and montiorable via prometheus and grafana

Infura Web Server Welcome to my verion of the take home project. I've created a webserver written in go to serve Infura api data over 3 possible data

Jacob Elias 1 Mar 25, 2022
network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.

Network Node Manager network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of ku

kakao 95 May 9, 2022
K8s-network-config-operator - Kubernetes network config operator to push network config to switches

Kubernetes Network operator Will add more to the readme later :D Operations The

Daniel Hertzberg 6 May 16, 2022
A multilayer perceptron network implemented in Go, with training via backpropagation.

Neural Go I'm in the process of making significant changes to this package, particularly, to make it more modular, and to base it around an actual lin

Schuyler Erle 63 Mar 5, 2022
scrapligo -- is a Go library focused on connecting to devices, specifically network devices (routers/switches/firewalls/etc.) via SSH and NETCONF.

scrapligo -- scrap(e c)li (but in go!) -- is a Go library focused on connecting to devices, specifically network devices (routers/switches/firewalls/etc.) via SSH and NETCONF.

null 124 May 8, 2022
Aidos Kuneen (v2 network) daemon program that is controlled through the command line and remotely via RPC calls

adk-daemon: aidosd.v2 aidosd (v2) is a deamon which acts as bitcoind for adk. This version has been built specifically for network mesh version 2+ For

Aidos Kuneen 0 Dec 1, 2021
Uniform interface for interacting with network hardware via telnet/ssh

jgivc/console This package provides a uniform interface for interacting with network hardware via telnet/ssh This package uses part of reiver/go-telne

null 0 Dec 9, 2021
Helps you to send ssh commands to target machine in your local network from outside via gRPC

rpc-ssh In case, you don't want to make your ssh port accessible from outside local network. This repository helps you to send ssh commands to target

Berkay Akyazı 1 Dec 8, 2021
A Go library for communicating with Tesla Powerwall appliances via the local-network API

go-powerwall A Go library for communicating with Tesla Powerwall appliances via the local-network API. Many thanks to Vince Loschiavo and other contri

Foogod 3 May 4, 2022
Wg-configurator - This project makes it easier to configure a fleet of servers interconnected via the WireGuard point-to-point virtual private network.

WireGuard Configurator This project makes it easier to configure a fleet of servers interconnected via the WireGuard point-to-point virtual private ne

Caleb L. Power 1 Mar 29, 2022