왜 모델 훈련을 위한 단 하나의 시대 때가 언급했 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
)

내가 노력을 분류하는 개와 고양이 여기에. 여기에 대한 링크를 데이터 집합에글 재현하려는 경우 이 일을 직접: https://www.kaggle.com/tongpython/cat-and-dog.

model.fit() 기능,내가 지정 epochs=15. 하지만 실행할 때 이것은,그것은 완료하기 전까지 1/15 시대. 보라:

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 시대의 정확도?

1

최고의 응답

0

이 때문입 batch_size 은 방법으로 높은 훈련을 위해 2000 이미지와 22 steps_per_epoch.

여기에 당신을 이해해야의 계산 steps_per_epochvalidation_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_epochvalidation_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ý
..................................................................................................................