python-2.7 - TensorFlow scatter_nd 函数不适用于占位符和复杂输入
问题描述
我tf.scatter_nd
用来更新某个索引处的复杂值。这个函数似乎将实部和虚部以某种方式加在一起。我的问题是如何使它与占位符一起使用。这是变量b
和e
应该具有相同值的最小工作示例。
import tensorflow as tf
import numpy as np
tf.reset_default_graph()
update=np.asarray([1.+2j])
idx=tf.constant( [[0]])
shp=tf.constant([1])
# works with constants
a=tf.constant(update)
b=tf.scatter_nd(idx,a,shp)
with tf.Session() as sess:
print sess.run(b) # correct output: 1.+2j
#Does not work with placeholders
d=tf.placeholder(tf.complex128)
e=tf.scatter_nd(idx,d,shp)
with tf.Session() as sess:
print sess.run(e,feed_dict={d:update}) # WRONG output: 3.+0j
我正在使用使用 conda 命令安装的 Anaconda python 2.7 + TensorFlow 1.7 GPU 版本。
编辑:
在 GPU 上运行代码时会出现此问题。CPU 版本正常工作。这是使用 Anaconda Python 2.7 安装的 TensorFlow-GPU 1.8 中重现该问题的更新代码。
import tensorflow as tf
import numpy as np
tf.reset_default_graph()
update=np.asarray([1.+2j])
idx=tf.constant( [[0]])
shp=tf.constant([1])
a=tf.placeholder(tf.complex128)
with tf.device("/cpu:0"):
b=tf.scatter_nd(idx,a,shp)
with tf.device("/gpu:0"):
c=tf.scatter_nd(idx,a,shp)
with tf.Session() as sess:
print 'Correct output on CPU', sess.run(b,feed_dict={a:update})
print 'Wrong output on GPU',sess.run(c,feed_dict={a:update})
解决方案
推荐阅读
- nginx - 如何缓存 mp4 文件(媒体文件)。按范围缓存视频
- java - 为什么我会为 >> 运算符得到这个意外的结果?
- java - Java:如何访问项目文件之外的图像?
- autodesk-forge - 加载模型时有没有办法在网络浏览器中使用更少的内存?
- python - Numpy数组,选择行,同时将零附加到未选择的行
- javascript - 将鼠标悬停在单个菜单项上时如何使整个菜单出现?
- angular - 使用 Angular 11 进行动态表单输入验证
- c++ - 如何从文本文件中读取数据并将其存储到C++中的数组中
- python - 就地修改文本文件(读写文本文件)
- php - 如何创建像 WordPress 一样的自定义 sanitize_title() 函数?