gorgonia: gorgonia.org/gorgonia/ops/nn Index | Examples | Files

package nnops

import "gorgonia.org/gorgonia/ops/nn"

Package nnops implements some operators that have both a pure go implementation and a cuda implementation to use the cuda version, assuming that you have the pre-requisites, simply compile or run the code with the `cuda tag`

go run -tags='cuda'

Index

Examples

Package Files

api_nocuda.go doc.go scratch.go utils.go

func BatchNorm Uses

func BatchNorm(x, scale, bias *G.Node, momentum, epsilon float64) (retVal, γ, β *G.Node, op *G.BatchNormOp, err error)

func CheckConvolutionParams Uses

func CheckConvolutionParams(pad, stride, dilation []int) error

func Conv1d Uses

func Conv1d(in, filter *G.Node, kernel, pad, stride, dilation int) (*G.Node, error)

func Conv2d Uses

func Conv2d(im, filter *G.Node, kernelShape tensor.Shape, pad, stride, dilation []int) (retVal *G.Node, err error)

Code:

g := gorgonia.NewGraph()
x := gorgonia.NodeFromAny(g, tensor.New(
    tensor.WithShape(1, 1, 7, 5),
    tensor.WithBacking([]float32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34})))
filter := gorgonia.NodeFromAny(g, tensor.New(
    tensor.WithShape(1, 1, 3, 3),
    tensor.WithBacking([]float32{1, 1, 1, 1, 1, 1, 1, 1, 1})))
y := gorgonia.Must(nnops.Conv2d(x, filter, []int{3, 3}, []int{0, 0}, []int{2, 2}, []int{1, 1}))
m := gorgonia.NewTapeMachine(g)
runtime.LockOSThread()
for i := 0; i < 1000; i++ {
    if err := m.RunAll(); err != nil {
        log.Fatalf("iteration: %d. Err: %v", i, err)
    }
}
runtime.UnlockOSThread()

fmt.Printf("%1.1f", y.Value())

Output:

⎡ 54.0   72.0⎤
⎢144.0  162.0⎥
⎣234.0  252.0⎦

func Dropout Uses

func Dropout(x *G.Node, prob float64) (retVal *G.Node, err error)

func MaxPool2D Uses

func MaxPool2D(x *G.Node, kernel tensor.Shape, pad, stride []int) (*G.Node, error)

func Rectify Uses

func Rectify(x *G.Node) (retVal *G.Node, err error)

Package nnops imports 8 packages (graph) and is imported by 3 packages. Updated 2019-07-04. Refresh now. Tools for package owners.