0
我想了解tf.strided_slice如何工作。为了做到这一点,我已经写了下面的代码:Tensorflow tf_strided_slice详细说明
import numpy as np
import tensorflow as tf
# parameters
record_size = 841
# create a random vector of 1682 integers in range [0.255]
content = np.random.randint(255,size=[1682])
depth_major = tf.reshape(
tf.strided_slice(content, [0],
[record_size]),
[1, 29, 29])
depth_major1 = tf.reshape(
tf.strided_slice(content, [record_size+1],
[2*record_size]),
[1, 29, 29])
# Initializing the variables
init = tf.global_variables_initializer()
with tf.Session as sess:
sess.run(depth_major)
print("depth_major", depth_major.shape)
当我执行上面的例子中,我得到以下错误:
ValueError: Cannot reshape a tensor with 840 elements to shape [1,29,29] (841 elements) for 'Reshape_1' (op: 'Reshape') with input shapes: [840], [3] and with input tensors computed as partial shapes: input[1] = [1,29,29].
我根本无法理解,为什么元素的数量自从我在[0]开始并以[record_size]结束后,是840?