【发布时间】:2022-01-12 18:20:52
【问题描述】:
我的输入张量 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最初的形状是什么,你想用它做什么?
标签: python numpy tensorflow machine-learning keras