nnops

package
v0.9.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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
package main

import (
	"fmt"
	"log"
	"runtime"

	"gorgonia.org/gorgonia"
	nnops "gorgonia.org/gorgonia/ops/nn"
	"gorgonia.org/tensor"
)

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())
}
Output:

⎡ 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)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL