新力開源神經網路庫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()