python-3.x - 多层感知器的张量层动态模型如何更新模型的权重
问题描述
这是多层感知器 (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))
完整的例子可以在这里看到
在此代码片段中,您可以看到神经网络的 train_weights 是如何调整的,但我不知道这些权重在 MLP 模型中的每个预测的更新位置和时间MLP(X_batch, foo=1)
解决方案
推荐阅读
- android - 有不同的 admob ID 和不同的 Google Play ID?
- django-models - 如果用户选择“保存”按钮,则 Django save() 表单,如果用户选择“计算”按钮,则保存 (commit=false)
- microsoft-graph-api - 如何使用 com.microsoft.graph.microsoft-graph 登录并获取个人帐户的 Microsoft Graph API 的访问令牌?
- excel - exe上的多次运行和数据输入
- javascript - 单击for循环生成的链接列表中的链接时,选中相应的复选框而不是第一个复选框
- php - laravel excel with upserts 不更新数据
- fortran - 指定 Fortran 中的函数是内在函数
- javascript - 将数据从动态生成的 HTML 表/网格保存到数据库
- sql - 如果两个字符串中都存在子字符串,PLSQL 检查两个字符串
- python - 有没有办法做到这一点?