cnn

package
v0.0.0-...-98db5b7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: CC-BY-4.0 Imports: 13 Imported by: 5

Documentation

Overview

Package cnn contains structs and methods used to do forward, and backward operations for convolution layers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Convolution convolution.Info `json:"convolution,omitempty"`
	Weights     tensor.Info      `json:"weights,omitempty"`
	Bias        tensor.Info      `json:"bias,omitempty"`
}

Info contains the info that is needed to build a CNN layer

type Layer

type Layer struct {
	// contains filtered or unexported fields
}

Layer is a struct that holds filter, bias and convolution descriptors. The memory for w, dw, bias, dbias. The algos for forward, backward (data, filter) and the scalars for those algos. 1

func Setup

func Setup(handle *cudnn.Handler,
	frmt gocudnn.TensorFormat,
	dtype gocudnn.DataType,
	mtype gocudnn.MathType,
	groupcount int32,
	filterdims []int32,
	convmode gocudnn.ConvolutionMode,
	pad,
	stride,
	dilation []int32,
	seed uint64) (*Layer, error)

Setup sets up the speed of the fwd and bwd algos dynamically. guessinputdims is really for setting up the random weights.

func SetupBasic

func SetupBasic(handle *cudnn.Handler,
	frmt gocudnn.TensorFormat,
	dtype gocudnn.DataType,
	mtype gocudnn.MathType,
	groupcount int32,
	w, dw, b, db *layers.Tensor,
	convmode gocudnn.ConvolutionMode,
	pad,
	stride,
	dilation []int32) (*Layer, error)

SetupBasic sets up a convolution layer with the memory for the gpu added to it. This can be used for layers that share the same memory, but might have different convolution properties.

func (*Layer) BAvg

func (c *Layer) BAvg(handle *cudnn.Handler) (float32, error)

BAvg returns the avg weight value for the layer

func (*Layer) BMax

func (c *Layer) BMax(handle *cudnn.Handler) (float32, error)

BMax returns the Max bias value for the layer

func (*Layer) BMin

func (c *Layer) BMin(handle *cudnn.Handler) (float32, error)

BMin returns the Min bias value for the layer

func (*Layer) BNorm1

func (c *Layer) BNorm1(handle *cudnn.Handler) (float32, error)

BNorm1 returns the norm1 bias value for the layer

func (*Layer) BNorm2

func (c *Layer) BNorm2(handle *cudnn.Handler) (float32, error)

BNorm2 returns the norm2 bias value for the layer

func (*Layer) BackPropData

func (c *Layer) BackPropData(handle *cudnn.Handler, wspace *nvidia.Malloced, dx, dy *layers.Tensor) error

BackPropData performs the BackPropData

func (*Layer) BackPropFilter

func (c *Layer) BackPropFilter(handle *cudnn.Handler, wspace *nvidia.Malloced, x, dy *layers.Tensor) error

BackPropFilter does the backward propagation for the filter You will pass a handle workspace memory x,dy layer.io

func (*Layer) BackPropFilterData

func (c *Layer) BackPropFilterData(handle *cudnn.Handler, wspacedata, wspacefilter *nvidia.Malloced, x, dx, dy *layers.Tensor) error

BackPropFilterData does the backprop for the data and the filter

Dx and X can be the same.

func (*Layer) Bias

func (c *Layer) Bias() *layers.Tensor

Bias returns the Bias

func (*Layer) DBAvg

func (c *Layer) DBAvg(handle *cudnn.Handler) (float32, error)

DBAvg returns the avg delta bias value for the layer

func (*Layer) DBMax

func (c *Layer) DBMax(handle *cudnn.Handler) (float32, error)

DBMax returns the Max delta bias value for the layer

func (*Layer) DBMin

func (c *Layer) DBMin(handle *cudnn.Handler) (float32, error)

DBMin returns the Min delta bias value for the layer

func (*Layer) DBNorm1

func (c *Layer) DBNorm1(handle *cudnn.Handler) (float32, error)

DBNorm1 returns the norm1 delta bias value for the layer

func (*Layer) DBNorm2

func (c *Layer) DBNorm2(handle *cudnn.Handler) (float32, error)

DBNorm2 returns the norm2 delta bias value for the layer

func (*Layer) DWAvg

func (c *Layer) DWAvg(handle *cudnn.Handler) (float32, error)

DWAvg returns the avg delta weight value for the layer

func (*Layer) DWMax

func (c *Layer) DWMax(handle *cudnn.Handler) (float32, error)

DWMax returns the Max delta weight value for the layer

func (*Layer) DWMin

func (c *Layer) DWMin(handle *cudnn.Handler) (float32, error)

DWMin returns the Min delta weight value for the layer

func (*Layer) DWNorm1

func (c *Layer) DWNorm1(handle *cudnn.Handler) (float32, error)

DWNorm1 returns the norm1 delta weight value for the layer

func (*Layer) DWNorm2

func (c *Layer) DWNorm2(handle *cudnn.Handler) (float32, error)

DWNorm2 returns the norm2 delta weight value for the layer

func (*Layer) DeltaWeights

func (c *Layer) DeltaWeights() *layers.Tensor

DeltaWeights returns the deltaweights

func (*Layer) DeltaWeightsFillSlice

func (c *Layer) DeltaWeightsFillSlice(h *cudnn.Handler, input interface{}, length int) error

DeltaWeightsFillSlice will fill the weights with values

func (*Layer) FilterProps

func (c *Layer) FilterProps() (gocudnn.TensorFormat, gocudnn.DataType, []int32, error)

FilterProps returns the filter properties of the Convolution Layer

func (*Layer) FindOutputDims

func (c *Layer) FindOutputDims(input *layers.Tensor) (dims []int32, err error)

FindOutputDims finds the outputdims fo the cnn

func (*Layer) ForwardProp

func (c *Layer) ForwardProp(handle *cudnn.Handler, wspace *nvidia.Malloced, x, y *layers.Tensor) error

ForwardProp performs the ForwardProp

func (*Layer) GetBwdDataAlgoPerfList

func (c *Layer) GetBwdDataAlgoPerfList(handle *cudnn.Handler, x, y *layers.Tensor, workspace *nvidia.Malloced) ([]convolution.BackDataPerformance, error)

GetBwdDataAlgoPerfList gets a list of backward performance algos

func (*Layer) GetBwdFiltAlgoPerfList

func (c *Layer) GetBwdFiltAlgoPerfList(handle *cudnn.Handler, x, y *layers.Tensor, workspace *nvidia.Malloced) ([]convolution.BackFilterPerformance, error)

GetBwdFiltAlgoPerfList gets a list of forward performance algos

func (*Layer) GetFwdAlgoPerfList

func (c *Layer) GetFwdAlgoPerfList(handle *cudnn.Handler, x, y *layers.Tensor, workspace *nvidia.Malloced) ([]convolution.ForwardPerformance, error)

GetFwdAlgoPerfList gets a list of forward performance algos

func (*Layer) Info

func (l *Layer) Info() (Info, error)

Info returns the info struct for the convolution

func (*Layer) L1L2Loss

func (c *Layer) L1L2Loss() (L1 float32, L2 float32)

L1L2Loss will return the L1 loss and L2 loss for the layer

func (*Layer) LoadBiasValues

func (c *Layer) LoadBiasValues(handle *cudnn.Handler, slice interface{}, length int) error

LoadBiasValues will load a slice into cuda memory for the Weights.

func (*Layer) LoadBiasValuesEX

func (c *Layer) LoadBiasValuesEX(handle *cudnn.Handler, r io.Reader) error

LoadBiasValuesEX takes a reader and coppies the bytes over to the bias

func (*Layer) LoadTrainer

func (c *Layer) LoadTrainer(handle *cudnn.Handler, forweights, forbias trainer.Trainer) error

LoadTrainer sets up the momentum trainer

func (*Layer) LoadWValues

func (c *Layer) LoadWValues(handle *cudnn.Handler, slice interface{}, length int) error

LoadWValues will load a slice into cuda memory for the Weights.

func (*Layer) LoadWvaluesEX

func (c *Layer) LoadWvaluesEX(handle *cudnn.Handler, r io.Reader) error

LoadWvaluesEX takes a reader and coppies the bytes over to the weights

func (*Layer) MakeOutputTensor

func (c *Layer) MakeOutputTensor(handle *cudnn.Handler, input *layers.Tensor) (*layers.Tensor, error)

MakeOutputTensor makes the output tensor of the layer

func (*Layer) MakeOutputTensorInference

func (c *Layer) MakeOutputTensorInference(handle *cudnn.Handler, input *layers.Tensor) (*layers.Tensor, error)

MakeOutputTensorInference makes the output tensor of the layer

func (*Layer) MakeRandom

func (c *Layer) MakeRandom(h *cudnn.Handler, inputdims []int32) error

MakeRandom does what it says it will make the weights random considering the fanin

func (*Layer) OutputDims

func (c *Layer) OutputDims(inputdims []int32) []int32

OutputDims will return the dims for the output

func (*Layer) SetBackwardScalars

func (c *Layer) SetBackwardScalars(alpha, beta float64)

SetBackwardScalars sets the alpha and beta scalars, the defaults are alpha, 1, beta=0 and are initialized in the function FilterSetup

func (*Layer) SetBestAlgosConsidering

func (c *Layer) SetBestAlgosConsidering(handle *cudnn.Handler, x, y *layers.Tensor, wspacelimit int, fastest bool) (uint, error)

SetBestAlgosConsidering this method will set the best algos for the fwd, bwddata, and bwdfilter algos. and return the workspace size along with an error if an error is found the function will not set any values, Here are some simple rules to the function if fastest is marked true. Then it will find the fastest algo no mater what worksize is. if fastest is set to false. It will check if wspace is greater than zero then it will set the algos to the fastest algo considering the workspace size, and return the largest wspacesize in all the algos else it will find and set the fastest algos with no workspace size and return 0

func (*Layer) SetBestAlgosConsideringDims4d

func (c *Layer) SetBestAlgosConsideringDims4d(handle *cudnn.Handler, x, y, w []int32, wspacelimit int, fastest bool) (uint, error)

SetBestAlgosConsideringDims4d this method will set the best algos for the fwd, bwddata, and bwdfilter algos. and return the workspace size along with an error if an error is found the function will not set any values, Here are some simple rules to the function if fastest is marked true. Then it will find the fastest algo no mater what worksize is. if fastest is set to false. It will check if wspace is greater than zero then it will set the algos to the fastest algo considering the workspace size, and return the largest wspacesize in all the algos else it will find and set the fastest algos with no workspace size and return 0

func (*Layer) SetBwdDataAlgoPerformance

func (c *Layer) SetBwdDataAlgoPerformance(bwddata convolution.BackDataPerformance)

SetBwdDataAlgoPerformance sets the Performance Values

func (*Layer) SetBwdFiltAlgoPerformance

func (c *Layer) SetBwdFiltAlgoPerformance(bwdfilt convolution.BackFilterPerformance)

SetBwdFiltAlgoPerformance sets the Performance Values

func (*Layer) SetForwardScalars

func (c *Layer) SetForwardScalars(alpha, beta float64)

SetForwardScalars sets the alpha and beta scalars, the defaults are alpha, 1, beta=0 and are initialized in the function FilterSetup

func (*Layer) SetFwdAlgoPerformance

func (c *Layer) SetFwdAlgoPerformance(fwd convolution.ForwardPerformance)

SetFwdAlgoPerformance sets the Performance Values

func (*Layer) SetMathType

func (c *Layer) SetMathType(mtype gocudnn.MathType) error

SetMathType sets the mathtype

func (*Layer) SetOtherScalars

func (c *Layer) SetOtherScalars(alpha, beta float64)

SetOtherScalars sets the alpha and beta scalars for the weights, the defaults are alpha, 1, beta=1 and are initialized in the function FilterSetup

func (*Layer) String

func (c *Layer) String() string

func (*Layer) ToggleBiasPrintValueForStringer

func (c *Layer) ToggleBiasPrintValueForStringer()

ToggleBiasPrintValueForStringer toggles if Bias values will be printed

func (*Layer) ToggleDBiasPrintValueForStringer

func (c *Layer) ToggleDBiasPrintValueForStringer()

ToggleDBiasPrintValueForStringer toggles if dBias values will be printed

func (*Layer) ToggleDWeightsPrintValueForStringer

func (c *Layer) ToggleDWeightsPrintValueForStringer()

ToggleDWeightsPrintValueForStringer toggles if DWeight values will be printed

func (*Layer) ToggleWeightsPrintValueForStringer

func (c *Layer) ToggleWeightsPrintValueForStringer()

ToggleWeightsPrintValueForStringer toggles if Weight values will be printed

func (*Layer) UpdateWeights

func (c *Layer) UpdateWeights(handle *cudnn.Handler, batch, epoch int) error

UpdateWeights does the weight update

func (*Layer) WAvg

func (c *Layer) WAvg(handle *cudnn.Handler) (float32, error)

WAvg returns the avg weight value for the layer

func (*Layer) WMax

func (c *Layer) WMax(handle *cudnn.Handler) (float32, error)

WMax returns the Max weight value for the layer.

func (*Layer) WMin

func (c *Layer) WMin(handle *cudnn.Handler) (float32, error)

WMin returns the Min weight value for the layer

func (*Layer) WNorm1

func (c *Layer) WNorm1(handle *cudnn.Handler) (float32, error)

WNorm1 returns the norm1 weight value for the layer

func (*Layer) WNorm2

func (c *Layer) WNorm2(handle *cudnn.Handler) (float32, error)

WNorm2 returns the norm2 weight value for the layer

func (*Layer) Weights

func (c *Layer) Weights() *layers.Tensor

Weights returns the weights

func (*Layer) WeightsFillSlice

func (c *Layer) WeightsFillSlice(h *cudnn.Handler, input interface{}, length int) error

WeightsFillSlice will fill a slice with the weight values

Jump to

Keyboard shortcuts

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