【问题标题】:Keras not showing progress bar when training modelKeras在训练模型时不显示进度条
【发布时间】:2019-09-24 09:38:22
【问题描述】:

我需要训练一个 CNN 来对一些图像进行分类。我之前在 TF 后端使用 Keras 就这样做过,就像一个魅力一样。现在它不想显示显示准确性和当前时代的进度对话框。

这是我的 CNN 模型的代码:

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Convolution2D, MaxPooling2D, Flatten, Dense
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator

classifier = tf.keras.models.Sequential()

classifier.add(Convolution2D(64, (3, 3), input_shape=(200, 150, 3), activation="relu"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))

classifier.add(Convolution2D(64, (3, 3), activation="relu"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))

classifier.add(Convolution2D(64, (3, 3), activation="relu"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))

classifier.add(Flatten())

classifier.add(Dense(units=200, activation="relu"))
classifier.add(Dense(units=128, activation="relu"))
classifier.add(Dense(units=64, activation="relu"))
classifier.add(Dense(units=1, activation="sigmoid"))

classifier.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])


train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

training_set = train_datagen.flow_from_directory(
    'images/train',
    target_size=(200, 150),
    batch_size=16,
    class_mode='binary')

test_set = test_datagen.flow_from_directory(
    'images/test',
    target_size=(200, 150),
    batch_size=16,
    class_mode='binary')


classifier.fit_generator(
        training_set,
        steps_per_epoch=5604, 
        epochs=10,
        validation_data=test_set,
        validation_steps=1831,
        verbose=1) 

我有什么遗漏吗? 我现在看到的是这样的:

纪元 1/10

谢谢...

【问题讨论】:

  • 会不会是一个epoch需要很长时间才能完成?
  • this 有帮助吗?
  • 当它打印 Found x images belonging to y clases 时你看到了什么?如果你在那里看到 0 张图片,你应该检查你的文件夹结构。在train 中,每个班级都应该有一个文件夹,并且在该文件夹中是图像。 test 文件夹也是如此。

标签: python tensorflow keras


【解决方案1】:

感谢您的建议。问题是由于不正确的 CudNN 版本造成的。必须下载 2017 年的版本,现在可以使用了!

【讨论】:

    猜你喜欢
    • 2017-12-25
    • 2017-10-14
    • 2019-12-14
    • 2020-04-05
    • 2021-05-14
    • 2016-12-31
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    相关资源
    最近更新 更多