tensorflow - 如何将张量重塑为占位符的形状?
问题描述
如何将张量重塑为占位符的形状?
a = tf.placeholder(shape=[None, None, 48])
h, w, c = a.shape
b = tf.reshape(a, shape=[-1, 4, 4, 3]) # flatten the first two dimension and expand the last dimension
# do something
c = tf.reshape(b, shape=[h, w, 3]) # reshape back to the shape of a, but error occurs
我想将张量b
恢复为 placeholder 的形状a
。
解决方案
a
具有在图构建时未知的动态形状,因此您需要转向张量流操作,更具体地说,tf.shape
它会(动态地)返回张量的形状。
所以在你的例子中你可以使用例如
s = tf.shape(a)
c = tf.reshape(b, shape=[s[0], s[1], 3])
推荐阅读
- java - 警报不会停止响铃 - 取消按钮不起作用
- java - 尝试使用junit中的反射访问私有方法时,模拟对象不起作用
- javascript - 使用cssgrid时,pageYOffset在滚动时不起作用
- spring - 在 Websphere 上部署应用程序时出现 ClassCastException
- javascript - 春季项目中 kendo.drawing.pdf.saveAs(...) 无法使用 unicode 字符生成 pdf
- java - 带有链式 sql 查询的 JdbcTemplate?
- rabbitmq - 集群上节点的 RabbitMQ 问题
- php - PHP从单个stdClass对象数组中的关联数组中获取/检查值
- javascript - 防止 insertBefore 复制内容
- angular - Get 方法来不及从服务器拉取数据