我有一个占位符,它的形状依赖于另一个占位符。如何在占位符初始化期间连接它们?
nUsers = tf.placeholder(tf.float32, [None, 1])
p = tf.placeholder(tf.float32, [None, 10 , ???] )...in?我需要将批次中该项目的大小放入nUsers中的数字。
发布于 2017-05-13 18:39:42
你可以很容易地用x.get_shape() (check the difference between tf.shape(x))得到张量的形状。所以你需要这样的东西:
import tensorflow as tf
import numpy as np
nUsers = tf.placeholder(tf.float32, [None, 1])
p = tf.placeholder(tf.float32, [None, 10 , nUsers.get_shape()[0]])
with tf.Session() as sess:
print sess.run(p, {nUsers: np.ones((2, 1)), p: np.ones((3, 10, 2))})https://stackoverflow.com/questions/43951922
复制相似问题