python - 如何在神经网络训练进行时显示预测值
问题描述
我正在训练一个模型来将视频剪辑从两个标签中分类出来,而模型损失保持不变,所以我想知道训练进行时的预测值,我做了一些尝试,然后出现错误:
Cannot assign a device for operation 'replica_1_5/model_12/activation_7/Softmax': Could not satisfy explicit device specification '/device:GPU:1' because no supported kernel for GPU devices is available.
Registered kernels:
device='CPU'; T in [DT_HALF]
device='CPU'; T in [DT_FLOAT]
device='CPU'; T in [DT_DOUBLE]
[[Node: replica_1_5/model_12/activation_7/Softmax = Softmax[T=DT_FLOAT, _device="/device:GPU:1"](replica_1_5/model_12/dense_21/BiasAdd)]]
During handling of the above exception, another exception occurred:
...
...
<ipython-input-29-a6bbc0e2d9db> in tf_loss(gen, ground)
110 def tf_loss(gen,ground):
111 with tf.Session() as sess:
--> 112 print(' gen:',sess.run(gen),' ground:',sess.run(ground))
113 return K.binary_crossentropy(gen,ground)
114
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
898 try:
899 result = self._run(None, fetches, feed_dict, options_ptr,
--> 900 run_metadata_ptr)
901 if run_metadata:
902 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1133 if final_fetches or final_targets or (handle and feed_dict_tensor):
1134 results = self._do_run(handle, final_targets, final_fetches,
-> 1135 feed_dict_tensor, options, run_metadata)
1136 else:
1137 results = []
...
这是发生错误的地方:
parallel_model.compile(loss=tf_loss, optimizer=Adam(lr=1e-4), metrics=['accuracy'])
def tf_loss(gen,ground):
with tf.Session() as sess:
print(' gen:',sess.run(gen),' ground:',sess.run(ground))
return K.binary_crossentropy(gen,ground)
可能是因为GPU不支持tf.Session(),我不确定~~
解决方案
推荐阅读
- javascript - socket.io 自定义错误未正确显示
- python - 这个张量流消息是什么意思?有什么副作用吗?安装成功了吗?
- mysql - 尝试选择最大数量的唯一事件
- opencart-3 - 新手 OCMOD 问题 - 使用“添加”是否会对搜索字符串的每个实例或仅一个实例进行更改?
- reactjs - 在我的功能组件中反应测试 3rd 方组件
- javascript - Vue:如何在 Vuex getter 中使用 Per-Route Guard?
- amazon-s3 - 出现 CloudFront 错误的 AWS S3 部署(此 XML 文件似乎没有任何关联的样式信息)
- r - 过滤依赖于两列的逻辑
- javascript - JS:为什么点击事件不会冒泡?
- spring-boot - 如何使用 Spring Data Rest 在 JPA 查询中使用列表参数?