[英]What is the meaning of this output in the console when I run model.fit_generator in Keras?
I am new working with Keras. 我和Keras一起工作了。 The code works correctly, but I would like to know the meaning of the values shown in the epochs. 代码工作正常,但我想知道时代中显示的值的含义。 I am using the following code. 我使用以下代码。
Where it says 46/46
and 226/277
, what is the meaning of these numbers? 如果它说46/46
和226/277
,这些数字的含义是什么? Why 2 appear when normally only appears for example 100/100
? 为什么2出现时通常只出现例如100/100
?
import sys
import os
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras import optimizers
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dropout, Flatten, Dense, Activation
from tensorflow.python.keras.layers import Convolution2D, MaxPooling2D
from tensorflow.python.keras import backend as K
K.clear_session()
data_entrenamiento = '/content/DatosEntrenamiento' #images
"""
Parameters
"""
epocas=20
longitud, altura = 28, 28
batch_size = 32
pasos = 1000
validation_steps = 300
filtrosConv1 = 32
filtrosConv2 = 64
tamano_filtro1 = (3, 3)
tamano_filtro2 = (2, 2)
tamano_pool = (2, 2)
clases = 3
lr = 0.0004
##Preparamos nuestras imagenes
generator = ImageDataGenerator(
rescale=1. / 255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
)
test_datagen = ImageDataGenerator(rescale=1. / 255,validation_split=0.2)
entrenamiento_generador = generator.flow_from_directory(
data_entrenamiento,
target_size=(altura, longitud),
batch_size=batch_size,
class_mode='categorical',
subset='training')
validacion_generador = test_datagen.flow_from_directory(
data_entrenamiento,
target_size=(altura, longitud),
batch_size=batch_size,
class_mode='categorical',
subset='validation')
cnn = Sequential()
cnn.add(Convolution2D(filtrosConv1, tamano_filtro1, padding ="same", input_shape=(longitud, altura, 3), activation='relu'))
cnn.add(MaxPooling2D(pool_size=tamano_pool))
cnn.add(Convolution2D(filtrosConv2, tamano_filtro2, padding ="same"))
cnn.add(MaxPooling2D(pool_size=tamano_pool))
cnn.add(Flatten())
cnn.add(Dense(256, activation='relu'))
cnn.add(Dropout(0.5))
cnn.add(Dense(clases, activation='softmax'))
cnn.compile(loss='categorical_crossentropy',
optimizer=optimizers.Adam(lr=lr),
metrics=['accuracy'])
his = cnn.fit_generator(
entrenamiento_generador,
steps_per_epoch=pasos,
epochs=epocas,
validation_data=validacion_generador,
validation_steps=validation_steps)
The output is : 输出是:
Found 7230 images belonging to 3 classes.
Found 1446 images belonging to 3 classes.
Epoch 1/20
46/46 [=========] - 1s 21ms/step...
226/226 [======] - 8s 36ms/step...
Epoch 2/20
46/46 [=========] - 1s 21ms/step ...
226/226 [=======] - 8s 35ms/step ...
steps_per_epoch: Total number of steps (batches of samples) to yield from generator before declaring one epoch finished and starting the next epoch. steps_per_epoch:在声明一个纪元完成并开始下一个纪元之前从发生器产生的步骤(样本批次)的总数。 It should typically be equal to the number of unique samples of your dataset divided by the batch size. 它通常应等于数据集的唯一样本数除以批量大小。
For training you have 7230 images, it means 226 batches of 32 images. 对于训练你有7230张图像,它意味着226批32张图像。 It is also the steps_per_epoch
which is normally calculated by steps_per_epoch = train_generator.n/batch_size
. 它也是steps_per_epoch
,通常由steps_per_epoch = train_generator.n/batch_size
计算。 But here you declare steps_per_epoch=pasos (=1000)
which is larger than available training batches so it will take 226. 但是在这里你声明了steps_per_epoch=pasos (=1000)
,它比可用的训练批次大,所以需要226。
validation_steps: Total number of steps (batches of samples) to yield from validation_data generator before stopping at the end of every epoch. validation_steps:在每个纪元结束之前停止之前从validation_data生成器产生的步骤(样本批次)的总数。 It should typically be equal to the number of samples of your validation dataset divided by the batch size. 它通常应等于验证数据集的样本数除以批量大小。 Optional for Sequence: if unspecified, will use the len(validation_data) as a number of steps. Sequence的可选:如果未指定,将使用len(validation_data)作为若干步骤。
Here again, you declare a validation_steps=300
which is higher than available validation batches (1446/32=46 batches). 在这里,您再次声明validation_steps=300
,它高于可用的验证批次(1446/32 = 46批次)。 If you dont use validation_steps
, you'll only see the training 226/226 [======] - 8s 36ms/step...
every epoch. 如果你不使用validation_steps
,你将只看到训练226/226 [======] - 8s 36ms/step...
每个时代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.