本文整理匯總了Golang中github.com/unixpickle/autofunc.Result類的典型用法代碼示例。如果您正苦於以下問題:Golang Result類的具體用法?Golang Result怎麽用?Golang Result使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Result類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Apply
func (u *UnstackLayer) Apply(in autofunc.Result) autofunc.Result {
return &unstackLayerResult{
OutputVector: u.unstack(in.Output()),
Input: in,
Layer: u,
}
}
示例2: Apply
func (b *BorderLayer) Apply(in autofunc.Result) autofunc.Result {
return &borderResult{
OutputVec: b.addBorder(in.Output()),
Input: in,
Info: b,
}
}
示例3: Apply
func (d *DropoutLayer) Apply(in autofunc.Result) autofunc.Result {
if d.Training {
return autofunc.Mul(in, d.dropoutMask(len(in.Output())))
} else {
return autofunc.Scale(in, d.KeepProbability)
}
}
示例4: Apply
func (g *GaussNoiseLayer) Apply(in autofunc.Result) autofunc.Result {
if g.Training {
return autofunc.Add(in, g.noise(len(in.Output())))
} else {
return in
}
}
示例5: networkOutput
func networkOutput(r autofunc.Result) int {
out := r.Output()
var maxIdx int
var max float64
for i, x := range out {
if i == 0 || x > max {
max = x
maxIdx = i
}
}
return maxIdx
}
示例6: Apply
func (_ ReLU) Apply(r autofunc.Result) autofunc.Result {
inVec := r.Output()
vec := make(linalg.Vector, len(inVec))
for i, x := range inVec {
if x > 0 {
vec[i] = x
}
}
return &reLUResult{
OutputVec: vec,
Input: r,
}
}
示例7: Apply
func (s *LogSoftmaxLayer) Apply(in autofunc.Result) autofunc.Result {
return autofunc.Pool(in, func(in autofunc.Result) autofunc.Result {
// Compute the log of the sum of the exponents by
// factoring out the largest exponent so that all
// the exponentials fit nicely inside floats.
maxIdx := maxVecIdx(in.Output())
maxValue := autofunc.Slice(in, maxIdx, maxIdx+1)
exponents := autofunc.AddFirst(in, autofunc.Scale(maxValue, -1))
expSum := autofunc.SumAll(autofunc.Exp{}.Apply(exponents))
expLog := autofunc.Log{}.Apply(expSum)
denomLog := autofunc.Add(expLog, maxValue)
return autofunc.AddFirst(in, autofunc.Scale(denomLog, -1))
})
}
示例8: Batch
// Batch applies the layer to inputs in batch.
func (m *MaxPoolingLayer) Batch(in autofunc.Result, n int) autofunc.Result {
outSize := m.OutputWidth() * m.OutputHeight() * m.InputDepth
inSize := m.InputWidth * m.InputHeight * m.InputDepth
if len(in.Output()) != n*inSize {
panic("invalid input size")
}
res := &maxPoolingResult{
OutputVec: make(linalg.Vector, outSize*n),
Input: in,
Layer: m,
}
for i := 0; i < n; i++ {
outTensor := m.outputTensor(res.OutputVec[i*outSize : (i+1)*outSize])
inTensor := m.inputTensor(in.Output()[i*inSize : (i+1)*inSize])
choices := m.evaluate(inTensor, outTensor)
res.Choices = append(res.Choices, choices)
}
return res
}
示例9: Batch
func (l *lstmGate) Batch(in autofunc.Result, n int) autofunc.Result {
if l.Peephole == nil {
return l.Activation.Apply(l.Dense.Batch(in, n))
}
return autofunc.Pool(in, func(in autofunc.Result) autofunc.Result {
vecSize := len(in.Output()) / n
var weightedInputs []autofunc.Result
var peepholed []autofunc.Result
for i := 0; i < n; i++ {
start := vecSize * i
weightedEnd := start + vecSize - len(l.Peephole.Vector)
weightedInputs = append(weightedInputs, autofunc.Slice(in, start, weightedEnd))
peepholeMe := autofunc.Slice(in, weightedEnd, (i+1)*vecSize)
peepholed = append(peepholed, autofunc.Mul(l.Peephole, peepholeMe))
}
weighted := l.Dense.Batch(autofunc.Concat(weightedInputs...), n)
return l.Activation.Apply(autofunc.Add(autofunc.Concat(peepholed...), weighted))
})
}
示例10: Batch
// Batch applies the layer to inputs in batch.
func (c *ConvLayer) Batch(in autofunc.Result, n int) autofunc.Result {
if c.Filters == nil || c.Biases == nil || c.FilterVar == nil {
panic(uninitPanicMessage)
}
outSize := c.OutputWidth() * c.OutputHeight() * c.OutputDepth()
inSize := c.InputWidth * c.InputHeight * c.InputDepth
if len(in.Output()) != n*inSize {
panic("invalid input size")
}
res := &convLayerResult{
OutputVec: make(linalg.Vector, outSize*n),
Input: in,
N: n,
Layer: c,
}
for i := 0; i < n; i++ {
subIn := in.Output()[i*inSize : (i+1)*inSize]
subOut := res.OutputVec[i*outSize : (i+1)*outSize]
c.convolve(subIn, c.outputToTensor(subOut))
}
return res
}