gpt4 book ai didi

python - 使用 Python Keras 训练 CNN 1D 时出现 AttributeError

转载 作者:太空狗 更新时间:2023-10-29 23:56:39 25 4
gpt4 key购买 nike

我曾尝试构建 CNN 1D,但解释器告诉我:

AttributeError: 'ProgbarLogger' object has no attribute 'log_values'

这是代码片段:

model = Sequential()
model.add(Conv1D(200, 20, activation='relu', padding='same',input_shape=(1154,1024))
print(model.summary())
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
history=model.fit(X, y,batch_size=10, epochs=25,validation_split=0.7)

这是错误:

Layer (type)                 Output Shape              Param #   
=================================================================
conv1d_1 (Conv1D) (None, 1154, 200) 4096200
=================================================================
Total params: 4,096,200
Trainable params: 4,096,200
Non-trainable params: 0
_________________________________________________________________
None

Train on 0 samples, validate on 1 samples
Epoch 1/25
Traceback (most recent call last):
File "binary_classification.py", line 59, in <module>
history=model.fit(X, y,batch_size=10, epochs=25,validation_split=0.7)
File "/home/isabella/.local/lib/python3.6/site-packages/keras/engine/training.py",
line 1039, in fit
validation_steps=validation_steps)
File "/home/isabella/.local/lib/python3.6/site-packages/keras/engine/training_arrays.py",
line 217, in fit_loop
callbacks.on_epoch_end(epoch, epoch_logs)
File "/home/isabella/.local/lib/python3.6/site-packages/keras/callbacks.py",
line 79, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "/home/isabella/.local/lib/python3.6/site-packages/keras/callbacks.py",
line 338, in on_epoch_end
self.progbar.update(self.seen, self.log_values)
AttributeError: 'ProgbarLogger' object has no attribute 'log_values'

X shape is :(1,1154,1024),
y shape is :(1,1154, 1 )

最佳答案

如果仔细观察,您会在堆栈跟踪输出之前看到这一行:

Train on 0 samples, validate on 1 samples

没有训练数据!为什么?那是因为您已将 validation_split 设置为 0.7 所以首先 70% 的数据点位于 X(和 y) 留作验证,其余 30% 用于训练。 X 中的数据点数量可能少于 4,因此它的 30% 将小于 1,这意味着零数据点仍用于训练。使用超过 4 个数据点或删除 validation_split 参数(或降低它,以便至少保留一个样本用于训练)。

关于python - 使用 Python Keras 训练 CNN 1D 时出现 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53259434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com