Goro是一个高级机器学习库,用于GO在Gorgonia上建造。它的目的是具有与Keras相同的感觉。
import (
. "github.com/aunum/goro/pkg/v1/model"
"github.com/aunum/goro/pkg/v1/layer"
)
// create the 'x' input e.g. mnist image
x := NewInput ( "x" , [] int { 1 , 28 , 28 })
// create the 'y' or expect output e.g. labels
y := NewInput ( "y" , [] int { 10 })
// create a new sequential model with the name 'mnist'
model , _ := NewSequential ( "mnist" )
// add layers to the model
model . AddLayers (
layer. Conv2D { Input : 1 , Output : 32 , Width : 3 , Height : 3 },
layer. MaxPooling2D {},
layer. Conv2D { Input : 32 , Output : 64 , Width : 3 , Height : 3 },
layer. MaxPooling2D {},
layer. Conv2D { Input : 64 , Output : 128 , Width : 3 , Height : 3 },
layer. MaxPooling2D {},
layer. Flatten {},
layer. FC { Input : 128 * 3 * 3 , Output : 100 },
layer. FC { Input : 100 , Output : 10 , Activation : layer . Softmax },
)
// pick an optimizer
optimizer := g . NewRMSPropSolver ()
// compile the model with options
model . Compile ( xi , yi ,
WithOptimizer ( optimizer ),
WithLoss ( m . CrossEntropy ),
WithBatchSize ( 100 ),
)
// fit the model
model . Fit ( xTrain , yTrain )
// use the model to predict an 'x'
prediction , _ := model . Predict ( xTest )
// fit the model with a batch
model . FitBatch ( xTrainBatch , yTrainBatch )
// use the model to predict a batch of 'x'
prediction , _ = model . PredictBatch ( xTestBatch )
请参阅示例文件夹,例如实现。
加固学习库黄金中有很多例子。
每个包装都包含一个解释用法的读书我,也请参见Godoc。
请为任何问题或功能请求打开MR。
随意在Gopher Slack上ping @pbarker。