python - Tensorflow:动态地将值附加到张量
问题描述
我一直在使用 Tensorflow 中的 CNN,并希望在每次训练迭代时跟踪损失值如何在运行时将值连接到张量,并在每次迭代时输出损失值?这是python代码的模拟版本 - 这会引发错误
# mocked up example to mimick 4 iterations
sample=[1,2,3,4]
# this is a dummy function to return loss values
def check(x):
return x*2
# the code below iteratively feeds loss values to concatenate in the loss_list tensor
def tf_check():
with tf.device(device):
loss = tf.placeholder(tf.float32)
loss_np = check(loss)
loss_list = tf.placeholder(tf.float32,shape=[])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for t in sample:
feed_dict = {loss:t}
y1=sess.run(loss_np,feed_dict)
loss_list=sess.run(tf.stack([loss_list,y1],axis=0))
tf_check()
解决方案
推荐阅读
- python - GroupBy 对象内的数据处理。如何添加列?
- nginx - Nginx:避免 nginx:[警告] 在 0.0.0.0:80 上冲突的服务器名称“索引”,忽略
- sprite-kit - SpriteKit:绕一圈顺时针旋转船
- azure - 没有 Azure 应用服务计划的 Azure SQL 数据库?
- rust - 当关联类型没有大小时,如何避免需要`std::marker::Sized`?
- php - Codeigniter 也在重定向上加载相同的视图
- javascript - 为什么我的 web 应用程序在发出几个请求将项目推送到我的 mongodb 数据库后暂停?
- java - 2D Checker Board Java 数组打印不正确
- visual-studio - Visual Studio Code - 无法在此平台上使用映像操作系统“linux”错误
- ios - 如何在用户默认值中保存对象列表?