索尼开源神经网络库NNabla
发布时间:2017-07-20 16:25:33 | 来源:选自Sony | 作者:佚名 | 责任编辑:胡俊训练可以通过以下步骤来完成:
importnnabla.solversas S
# Create a solver (parameter updater)
solver =S.Adam(
solver.set_parameters(nn.get_parameters())
# Training iteration
for n inrange(
# Setting data from any data source
x.d=
t.d=
# Initialize gradients
solver.zero_grad()
# Forward and backward execution
loss.forward()
loss.backward()
# Update parameters by computed gradients
solver.update()
动态计算图使网络结构的执行时间变得灵活。NNabla可以使用静态和动态图的模型,在两种情况下都使用相同的 API。
x.d=
t.d=
drop_depth=np.random.rand(
withnn.auto_forward():
h =F.relu(PF.convolution(x,
foriinrange(
ifdrop_depth[i]:
continue # Stochastically drop a layer
h2 =F.relu(PF.convolution(x,
name='conv%d'% (i+1)))
h =F.add2(h, h2)
y =PF.affine(h,
loss=F.mean(F.softmax_cross_entropy(y, t))
# Backward computation (can also be done in dynamically executed graph)
loss.backward()