Пример #1
0
test_datagen = ImageDataGenerator(rescale=1./255)

train = train_datagen.flow_from_directory(
                                        'Dataset Path',          # Directory Name
                                        target_size=(256, 256),  # Size of the image expected in our mode
                                        batch_size=32,           # Size of the batch after which batch will be updated
                                        class_mode='binary')     # Show the class mode of the result

test = test_datagen.flow_from_directory(
                                        'Dataset Path',         # Directory Name
                                        target_size=(256, 256), # Image of our test set
                                        batch_size=32,          # Size of the batch after which batch will be updated
                                        class_mode='binary')    # Show the class mode of the result

model.fit_generator(
                    train,
                    steps_per_epoch=2000,  # Number of images in our train dataset
                    epochs=25,             # Number of epoch we need
                    validation_data= test, # Test set 
                    validation_steps=800)  # Number of images in our test dataset
                    

""" To improve the model you can
Add a convolution Layer
Increase the target size in train and test dataset so that more information of the pixel pattern is captured 
"""


                    

Пример #2
0
classifier.add(Dense(output_dim=1, activation='sigmoid'))

#compliling
classifier.compile(optimizer='adam',
                   loss='binary_crossentropy',
                   metrics=['accuracy'])

from keras.preprosessing.image import ImageDataGenerator

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('dataset/training_set',
                                                 target_size=(64, 64),
                                                 batch_size=32,
                                                 class_mode='binary')

test_set = test_datagen.flow_from_directory('data/validation',
                                            target_size=(64, 64),
                                            batch_size=32,
                                            class_mode='binary')

classifier.fit_generator(training_set,
                         steps_per_epoch=8000,
                         epochs=25,
                         validation_data=test_set,
                         validation_steps=2000)