Back to godoc.org

Package nnops

v0.9.14
Latest Go to latest

The latest major version is .

Published: Sep 10, 2020 | License: Apache-2.0 | Module: gorgonia.org/gorgonia

Overview

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

func BatchNorm

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

func CheckConvolutionParams

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

func Conv1d

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

func Conv2d

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

Code:

package main

import (
	"fmt"
	"gorgonia.org/gorgonia"
	nnops "gorgonia.org/gorgonia/ops/nn"
	"gorgonia.org/tensor"
	"log"
	"runtime"
)

func main() {
	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())
}
⎡ 54.0   72.0⎤
⎢144.0  162.0⎥
⎣234.0  252.0⎦

func Dropout

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

func MaxPool2D

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

func Rectify

func Rectify(x *G.Node) (retVal *G.Node, err error)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier