【发布时间】:2018-11-26 08:56:32
【问题描述】:
我正在使用 Keras 构建一个 CNN,并将以下 Conv1D 作为我的第一层:
cnn.add(Conv1D(
filters=512,
kernel_size=3,
strides=2,
activation=hyperparameters["activation_fn"],
kernel_regularizer=getattr(regularizers, hyperparameters["regularization"])(hyperparameters["regularization_rate"]),
input_shape=(1000, 1),
))
我正在使用函数进行训练:
cnn.fit(
x=train_df["payload"].tolist(),
y=train_df["label"].tolist(),
batch_size=hyperparameters["batch_size"],
epochs=hyperparameters["epochs"],
)
其中 train_df 是一个包含两列的 pandas 数据帧,其中,对于每一行,label 是一个 int(0 或 1),而有效负载是一个用零填充/截断长度为 1000 的浮点 ndarray。 train_df 中的训练示例总数为 15641。
模型编译,但在训练期间,我收到此错误:
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 15641 arrays: [array([[0.09019608],
[0.01176471],
[0.01176471],
[0. ],
[0.30196078],
[0. ],
[0. ],
[0. ],
[0. ],
[0....
我查看了 this post 并尝试将我的输入更改为 1000 个浮点长列表的 ndarray,但最终出现另一个错误:
ValueError: Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (15641, 1000)
有什么想法吗?
【问题讨论】:
-
试试 input_shape=(1000,)
标签: python keras conv-neural-network