ทำไมถึงเป็นนางแบบฝึกเพื่อนเดียวที่ epoch ตอนที่ฉันพูดถึง 15 คือสิ่งที่ต้องการ?

0

คำถาม

นี่คือของฉันรหัส:

import tensorflow as tf
from tensorflow.keras.optimizers import RMSprop
from tensorflow.keras.preprocessing.image import ImageDataGenerator
model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(150, 150, 3)),
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Conv2D(32, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(
    loss='binary_crossentropy',
    optimizer=RMSprop(lr=0.001),
    metrics=['accuracy']
)
train_datagen = ImageDataGenerator(rescale=1.0/255.)
train_generator = train_datagen.flow_from_directory('training_set',
                                                    batch_size=250,
                                                    class_mode='binary',
                                                    target_size=(150, 150))
validation_datagen = ImageDataGenerator(rescale=1.0/255.)
validation_generator = validation_datagen.flow_from_directory('test_set',
                                                              batch_size=456,
                                                              class_mode='binary',
                                                              target_size=(150, 150))
history = model.fit(
    train_generator,
    validation_data=validation_generator,
    epochs=15,
    steps_per_epoch=22,
    validation_steps=22,
    verbose=1
)

ฉันกำลังพยายามจำแนกพวกแมวกับหมาอยู่ที่นี่ นี่คือการเชื่อมต่อไปในวันที่บน Kaggle ถ้าคุณต้องการ reproduce มันได้ด้วยตัวเอง: https://www.kaggle.com/tongpython/cat-and-dog.

ใน model.fit() ฟังก์ชันฉันกำหนด epochs=15. แต่เมื่อฉันวิ่งหนีเรื่องนี้มันเกิดขึ้นจนกระทั่งมันเสร็จแล้ว 1/15 epochs. ดู:

Epoch 1/15
WARNING:tensorflow:AutoGraph could not transform <function Model.make_train_function.<locals>.train_function at 0x16882d280> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: unsupported operand type(s) for -: 'NoneType' and 'int'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING: AutoGraph could not transform <function Model.make_train_function.<locals>.train_function at 0x16882d280> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: unsupported operand type(s) for -: 'NoneType' and 'int'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
2021-11-21 19:10:51.086856: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
2021-11-21 19:10:51.087052: W tensorflow/core/platform/profile_utils/cpu_utils.cc:126] Failed to get CPU frequency: 0 Hz
22/22 [==============================] - ETA: 0s - loss: 1.5458 - accuracy: 0.5119 WARNING:tensorflow:AutoGraph could not transform <function Model.make_test_function.<locals>.test_function at 0x1699b7670> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: unsupported operand type(s) for -: 'NoneType' and 'int'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING: AutoGraph could not transform <function Model.make_test_function.<locals>.test_function at 0x1699b7670> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: unsupported operand type(s) for -: 'NoneType' and 'int'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

คุณรู้ว่าทำไมเรื่องนี้เกิดขึ้นและสิ่งที่ฉันสามารถทำให้ของฉัน 15 epochs'มีค่าของความถูกต้อ?

1

คำตอบที่ดีที่สุด

0

นี่คือเพราะ batch_size เป็นทางสูงสำหรับการฝึก 2000 ภาพกับอายุ 22 steps_per_epoch.

นี่คุณต้องเข้าใจว่าการคำนวณขอ steps_per_epoch แล้ว validation_steps.

#Steps_per_epoch = no. of training images/ batch_size   (2000/250)=7.8
#validation_steps= no. of testing images/ batch_size    (1000/456)=2.19

แล้ว batch_size ควรจะอยู่ในหมู่ตัวเลขพวกนี้(8,16,32,64,128,256)แม้ว่าจะไม่มีต่างๆ

train_datagen = ImageDataGenerator(rescale=1.0/255.)
train_generator = train_datagen.flow_from_directory(training_set,
                                                    batch_size=128,
                                                    class_mode='binary',
                                                    target_size=(150, 150))
validation_datagen = ImageDataGenerator(rescale=1.0/255.)
validation_generator = validation_datagen.flow_from_directory(test_set,
                                                              batch_size=128,
                                                              class_mode='binary',
                                                              target_size=(150, 150))

คุณสามารถเห็นเปลี่ยนไป steps_per_epoch แล้ว validation_steps เป็นส่วนหนึ่ง batch_size=128

print(2000/128)  #steps_per_epoch=number of training images/batch_size
print(1000/128)  #validation_steps=number of testing images/batch_size

แสดงผล:

15.625
7.8125

ถ้าคุณไม่กำหนด steps_per_epochรุ่นจะคำนวณ steps_per_epoch ตัวมันเองกับรูปภาพจำนวนแล้ว batch_size เป็นคำนวณทางด้านบน

history = model.fit(train_generator,
                    validation_data=validation_generator,
                    epochs=15,
                    verbose=1)

แสดงผล:

Epoch 1/15
16/16 [==============================] - 23s 2s/step - loss: 0.4897 - accuracy: 0.7725 - val_loss: 0.6596 - val_accuracy: 0.6280
Epoch 2/15
16/16 [==============================] - 36s 2s/step - loss: 0.4133 - accuracy: 0.8060 - val_loss: 0.6691 - val_accuracy: 0.6890
Epoch 3/15
16/16 [==============================] - 21s 1s/step - loss: 0.4430 - accuracy: 0.7950 - val_loss: 0.7110 - val_accuracy: 0.6750
Epoch 4/15
16/16 [==============================] - 19s 1s/step - loss: 0.3299 - accuracy: 0.8560 - val_loss: 0.7929 - val_accuracy: 0.6710
Epoch 5/15
16/16 [==============================] - 14s 905ms/step - loss: 0.3536 - accuracy: 0.8355 - val_loss: 0.6888 - val_accuracy: 0.6440
Epoch 6/15
16/16 [==============================] - 15s 968ms/step - loss: 0.2486 - accuracy: 0.9010 - val_loss: 0.7898 - val_accuracy: 0.6540
Epoch 7/15
16/16 [==============================] - 16s 1s/step - loss: 0.3154 - accuracy: 0.8975 - val_loss: 0.7504 - val_accuracy: 0.6420
Epoch 8/15
16/16 [==============================] - 14s 905ms/step - loss: 0.1612 - accuracy: 0.9505 - val_loss: 1.0349 - val_accuracy: 0.6390
Epoch 9/15
16/16 [==============================] - 14s 907ms/step - loss: 0.1609 - accuracy: 0.9415 - val_loss: 1.1632 - val_accuracy: 0.6350
Epoch 10/15
16/16 [==============================] - 14s 904ms/step - loss: 0.0781 - accuracy: 0.9765 - val_loss: 1.1445 - val_accuracy: 0.7020
Epoch 11/15
16/16 [==============================] - 16s 1s/step - loss: 0.2899 - accuracy: 0.9170 - val_loss: 0.9464 - val_accuracy: 0.6930
Epoch 12/15
16/16 [==============================] - 15s 916ms/step - loss: 0.0563 - accuracy: 0.9855 - val_loss: 1.1374 - val_accuracy: 0.6730
Epoch 13/15
16/16 [==============================] - 16s 1s/step - loss: 0.0347 - accuracy: 0.9930 - val_loss: 1.4902 - val_accuracy: 0.6740
Epoch 14/15
16/16 [==============================] - 16s 990ms/step - loss: 0.1873 - accuracy: 0.9430 - val_loss: 1.1990 - val_accuracy: 0.6940
Epoch 15/15
16/16 [==============================] - 15s 919ms/step - loss: 0.0848 - accuracy: 0.9775 - val_loss: 2.5946 - val_accuracy: 0.5520
2021-12-24 16:29:18

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่