Proč je model vzdělávání pro pouze jeden čas, kdy jsem se již zmínil 15 je to, co je požadováno?

0

Otázka

Tady je můj kód:

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
)

Snažím se zařadit psi a kočky. Zde je odkaz na datový soubor na Kaggle pokud chcete reprodukovat to, co sami: https://www.kaggle.com/tongpython/cat-and-dog.

V model.fit() funkce, jsem zadaný epochs=15. Ale když jsem spustit to, to jde dál, dokud je to hotové 1/15 epoch. Podívejte se:

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

Víte, proč se to děje a co můžu udělat, aby se můj 15 epoch za přesnost?

1

Nejlepší odpověď

0

Je to proto, že z batch_size je způsob, jak vysoké pro školení 2000 snímků s 22 steps_per_epoch.

Zde je třeba pochopit, výpočet steps_per_epoch a 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

Také, batch_size měla by být mezi těmito čísly (8,16,32,64,128,256), i když tam je žádná omezení.

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))

Můžete vidět změnil steps_per_epoch a validation_steps dle 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

Výstup:

15.625
7.8125

Pokud nechcete definovat steps_per_epochmodel bude počítat steps_per_epoch sám se dané obrázky, počítat a batch_size vypočítaná výše.

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

Výstup:

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

V jiných jazycích

Tato stránka je v jiných jazycích

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