【发布时间】:2021-08-18 18:31:31
【问题描述】:
我正在使用 TensorFlow Keras 做一个简单的 Conv1D 来尝试时间序列数据集。
数据:
train_df = dff[:177] #get train data
tdf = train_df.shape #get shape = (177,4)
test = tf.convert_to_tensor(train_df)
型号:
model = tf.keras.models.Sequential([
tf.keras.layers.Conv1D(filters=32,
kernel_size=1,
strides=1,
padding="causal",
activation="relu",
input_shape=tdf),
tf.keras.layers.MaxPooling1D(pool_size=2, strides=1, padding="valid")
])
lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(5e-4,
decay_steps=1000000,
decay_rate=0.98,
staircase=False)
model.compile(loss=tf.keras.losses.MeanSquaredError(),
optimizer=tf.keras.optimizers.SGD(learning_rate=lr_schedule, momentum=0.8),
metrics=['mae'])
model.summary()
总结:
Model: "sequential_13"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_16 (Conv1D) (None, 177, 32) 160
_________________________________________________________________
max_pooling1d_8 (MaxPooling1 (None, 176, 32) 0
=================================================================
Total params: 160
Trainable params: 160
Non-trainable params: 0
适合:
trainedModel = model.fit(test,
epochs=100,
steps_per_epoch=1,
verbose=1)
@Fit 引发错误:
ValueError: Input 0 of layer sequential_13 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (2, 1)
从各种 SO 来看,据说这是由于输入数据的形状造成的。所以我在 SO 中尝试了一个建议来重塑我的数据并重新输入它
重塑:
X_train=np.reshape(test,(test.shape[0], test.shape[1],1))
重塑后@Fit 引发错误:
ValueError: Input 0 of layer sequential_14 is incompatible with the layer: expected axis -1 of input shape to have value 4 but received input with shape (177, 4, 1)
我在这里不知所措。有什么办法解决这个问题?
【问题讨论】:
-
您能否包含来自
train_df的几行数据,以便我们可以在我们的机器上重现这些数据以提供更好的帮助?
标签: python tensorflow machine-learning keras conv-neural-network