【发布时间】:2018-01-13 16:10:52
【问题描述】:
我正在阅读this code,我想了解它的实现。
我想知道的第一件事是,一些张量对象(占位符)的形状是什么,例如x_init、xs、h_init、y_init、y_sample、等等。
我写了一行代码,比如print(xs.shape),但它不起作用。
如何理解这些参数(张量)的形状?我可以在 NumPy 中编写类似以下的内容吗?
定义这些张量的代码部分如下所示:
x_init = tf.placeholder(tf.float32, shape=(args.init_batch_size,) + obs_shape)
xs = [tf.placeholder(tf.float32, shape=(args.batch_size, ) + obs_shape)
for i in range(args.nr_gpu)]
# if the model is class-conditional we'll set up label placeholders +
# one-hot encodings 'h' to condition on if args.class_conditional:
num_labels = train_data.get_num_labels()
y_init = tf.placeholder(tf.int32, shape=(args.init_batch_size,))
h_init = tf.one_hot(y_init, num_labels)
y_sample = np.split(
np.mod(np.arange(args.batch_size * args.nr_gpu), num_labels), args.nr_gpu)
h_sample = [tf.one_hot(tf.Variable(
y_sample[i], trainable=False), num_labels) for i in range(args.nr_gpu)]
【问题讨论】:
-
请花时间自己格式化代码。你已经有了一些声誉,你应该知道这个网站上的事情是如何运行的(发布一个格式正确的问题就是其中之一)。
-
您可以用 numpy 编写代码,但如何计算损失函数对所有参数的梯度?还是你已经这样做了?
-
@kmario23 我不是说用 numpy 编写整个程序。只是在 numpy 中对 xs、ys、hs 等的这些定义,所以我可以理解它们为什么使用这些参数。
标签: python python-3.x numpy tensorflow