对 rank1 张量的 20 个元素进行切片,然后重塑抛出 "Input to reshape is tensor with 10272 values, but requested shape requires multiple of 20"
Slice of 20 elements of rank1 tensor then reshaping throws "Input to reshape is tensor with 10272 values, but requested shape requires multiple of 20"
我的输入张量 Data = Input(shape=(856,))
是一个由许多不同设备串联而成的 float32 值向量。我正在尝试将不同的 TensorFlow 函数应用于每个输入块的不同子切片。其中一些函数包括需要重塑的一维卷积。
slice = Data[:20]
reshape = tf.reshape(slice, (-1, 20, 1))
...
尝试拟合我的模型后执行此操作会崩溃。它抛出以下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 10272 values, but the requested shape requires a multiple of 20
[[node model/tf.reshape_1/Reshape
(defined at /home/.local/lib/python3.8/site-packages/keras/layers/core/tf_op_layer.py:261)
]] [Op:__inference_train_function_1858]
Errors may have originated from an input operation.
Input Source operations connected to node model/tf.reshape_1/Reshape:
In[0] model/tf.__operators__.getitem_1/strided_slice:
In[1] model/tf.reshape_1/Reshape/shape:
我不确定如何将 856 张量中的 20 个元素分割成 10272 个值的张量。
我也尝试过使用 tf.slice
函数的几种不同方式;都失败了。参考文档:https://www.tensorflow.org/guide/tensor_slicing
slice = tf.slice(Data, begin=[0], size=[20])
...
失败,说明:
Shape must be rank 1 but is rank 2 for '{{node tf.slice/Slice}} = Slice[Index=DT_INT32, T=DT_FLOAT](Placeholder, tf.slice/Slice/begin, tf.slice/Slice/size)' with input shapes: [?,856], [1], [1].
供参考,下面是输入数据中的一些值
array([-9.55784683e+01, -1.70557899e+01, 2.95967350e+01, 7.81378937e+00,
9.02729130e+00, 5.49621725e+00, 4.19811630e+00, 5.84186697e+00,
4.90438080e+00, 3.73845983e+00, 5.12300587e+00, 2.61530232e+00,
2.67061424e+00, 3.91038632e+00, 2.31110978e+00, 4.20644665e+00,
4.50000000e+00, 9.87345278e-01, 1.59740388e+00, 6.30727148e+00,
...
当您像 Data[:20]
那样对数据进行切片时,它会生成一个长度为 min(20, len(Data))
的序列。所以我猜你的数据长度小于 20.
其他消息说它有等级 2,所以我猜它有以下形状之一
1 10272
2 5136
3 3424
4 2568
6 1712
8 1284
12 856
16 642
如您的第一条消息所示,其中任何一个都会产生具有 10272
个元素的张量,并且这不是 20 的倍数。
我的输入张量 Data = Input(shape=(856,))
是一个由许多不同设备串联而成的 float32 值向量。我正在尝试将不同的 TensorFlow 函数应用于每个输入块的不同子切片。其中一些函数包括需要重塑的一维卷积。
slice = Data[:20]
reshape = tf.reshape(slice, (-1, 20, 1))
...
尝试拟合我的模型后执行此操作会崩溃。它抛出以下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 10272 values, but the requested shape requires a multiple of 20
[[node model/tf.reshape_1/Reshape
(defined at /home/.local/lib/python3.8/site-packages/keras/layers/core/tf_op_layer.py:261)
]] [Op:__inference_train_function_1858]
Errors may have originated from an input operation.
Input Source operations connected to node model/tf.reshape_1/Reshape:
In[0] model/tf.__operators__.getitem_1/strided_slice:
In[1] model/tf.reshape_1/Reshape/shape:
我不确定如何将 856 张量中的 20 个元素分割成 10272 个值的张量。
我也尝试过使用 tf.slice
函数的几种不同方式;都失败了。参考文档:https://www.tensorflow.org/guide/tensor_slicing
slice = tf.slice(Data, begin=[0], size=[20])
...
失败,说明:
Shape must be rank 1 but is rank 2 for '{{node tf.slice/Slice}} = Slice[Index=DT_INT32, T=DT_FLOAT](Placeholder, tf.slice/Slice/begin, tf.slice/Slice/size)' with input shapes: [?,856], [1], [1].
供参考,下面是输入数据中的一些值
array([-9.55784683e+01, -1.70557899e+01, 2.95967350e+01, 7.81378937e+00,
9.02729130e+00, 5.49621725e+00, 4.19811630e+00, 5.84186697e+00,
4.90438080e+00, 3.73845983e+00, 5.12300587e+00, 2.61530232e+00,
2.67061424e+00, 3.91038632e+00, 2.31110978e+00, 4.20644665e+00,
4.50000000e+00, 9.87345278e-01, 1.59740388e+00, 6.30727148e+00,
...
当您像 Data[:20]
那样对数据进行切片时,它会生成一个长度为 min(20, len(Data))
的序列。所以我猜你的数据长度小于 20.
其他消息说它有等级 2,所以我猜它有以下形状之一
1 10272
2 5136
3 3424
4 2568
6 1712
8 1284
12 856
16 642
如您的第一条消息所示,其中任何一个都会产生具有 10272
个元素的张量,并且这不是 20 的倍数。