python - 创建一个占位符,其形状是另一个形状的函数

标签 python tensorflow placeholder

假设我们有一个 tensorflow 占位符,如下所示:

x = tf.placeholder(tf.float32, (2, 2, 3 ..., 1))

我想创建另一个张量 y其形状为 x除了第一维和第二维之外,它们是 x 的三倍.

y = tf.placeholder(tf.float32, (6, 6, 3, ..., 1))

x的形状没有预定义,所以我想做的是如下所示:

y = tf.placeholder(tf.float32, (x.shape[0]* 3, x.shape[1] * 3, remaining_are_the_same_as_x_shape))

你能告诉我如何在 tensorflow 中做到这一点吗?

最佳答案

这个怎么样?

x = tf.placeholder(tf.float32, (2, 2, 3 , 1))

shape = x.get_shape().as_list()
shape[0] = shape[0] * 3
shape[1] = shape[1] * 3

y = tf.placeholder(tf.float32, shape=shape)
shape = y.get_shape().as_list()
print(shape)

[6, 6, 3, 1]

关于python - 创建一个占位符,其形状是另一个形状的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52142344/

相关文章:

python - 'SELECT LAST_INSERT_ID()' 处的语法错误

python - 是否有任何计算机语言知道检查不存在的变量和检查是否存在之间的区别?

python - 来自 Azure 计算机视觉 API 的 400 响应

r - Keras R 图像分类模型中的形状错误

Python 从 URL 读取页面?更好的文档?

linux - 没有名为 'tensorflow.python.platform' 的模块

javascript - tfjs-converter html javascript 导入类时遇到问题

html - 如何在不使用 JS/jQuery 的情况下使占位符消失?

html - 是否可以选择最近的 css 选择器或父级

jquery - 拖放到“密码”和“确认密码”字段中的值显示为纯文本