多层感知器张量层动态模型如何更新模型权重

时间:2019-11-20 06:57:09

标签: python-3.x tensorflow machine-learning tensorlayer

这是来自多层感知器(MNIST)示例的代码片段,具有张量层的动态模型。

## the following code can help you understand SGD deeply
for epoch in range(n_epoch):  ## iterate the dataset n_epoch times
    start_time = time.time()
    ## iterate over the entire training set once (shuffle the data via training)
    for X_batch, y_batch in tl.iterate.minibatches(X_train, y_train, batch_size, shuffle=True):
        MLP.train()  # enable dropout
        with tf.GradientTape() as tape:
            ## compute outputs
            _logits = MLP(X_batch, foo=1)
            ## compute loss and update model
            _loss = tl.cost.cross_entropy(_logits, y_batch, name='train_loss')
        grad = tape.gradient(_loss, train_weights)
        optimizer.apply_gradients(zip(grad, train_weights))

完整示例可见here

在此代码段中,您可以看到如何调整神经网络的train_weights,但是我不知道在MLP模型中针对每个预测MLP(X_batch, foo=1)这些权重在何时何地更新

0 个答案:

没有答案