Commit f23cafb1 authored by sjjsmuel's avatar sjjsmuel

back to TF Datasets

parent 69ea3d3d
......@@ -4,6 +4,7 @@ from optparse import OptionParser
from PIL import ImageFile
from keras_preprocessing.image import ImageDataGenerator
from classifier.Resnet152 import Resnet152
from classifier.DataLoader import DataLoader
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard, EarlyStopping
......@@ -53,39 +54,35 @@ img_height = options.height
channels = 3
n_classes = 2
batch_size = 16
batch_count_train_dataset = 2000 // batch_size
batch_count_validation_dataset = 800 // batch_size
batch_count_test_dataset = 800 // batch_size
# Load the dataset into TF Datasets
# Training Data
train_loader = DataLoader(data_path=train_dir,
batch_size=options.batch_size,
batch_count_dataset1=batch_count_train_dataset,
img_width=img_width,
img_height=img_height,
channels=channels,
augment=True
)
train_dataset = train_loader.load_dataset()
# Test Data
test_loader = DataLoader( data_path=test_dir,
batch_size=options.batch_size,
batch_count_dataset1=batch_count_validation_dataset,
batch_count_dataset2=batch_count_test_dataset,
img_width=img_width,
img_height=img_height,
channels=channels,
split_size=options.split_size,
augment=True
)
validation_dataset, test_dataset = test_loader.load_dataset()
#FROM: https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
# this is the augmentation configuration we will use for training
train_datagen = ImageDataGenerator(
rotation_range=30,
rescale=1./255,
shear_range=0.2,
zoom_range=0.3,
horizontal_flip=True,
vertical_flip=True,
brightness_range=[0.3, 1.0]
)
# this is the augmentation configuration we will use for testing:
# only rescaling
test_datagen = ImageDataGenerator(rescale=1./255)
# this is a generator that will read pictures found in
# subfolers of 'data/train', and indefinitely generate
# batches of augmented image data
train_generator = train_datagen.flow_from_directory(
train_dir, # this is the target directory
target_size=(img_width, img_height), # all images will be resized to 150x150
batch_size=batch_size,
class_mode='categorical')
# this is a similar generator, for validation data
validation_generator = test_datagen.flow_from_directory(
test_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='categorical')
#END_FROM
# Create Network
network = Resnet152(n_classes, img_width, img_height, channels, resnet_file)
......@@ -123,22 +120,19 @@ callbacks = [
]
print('# Fit model on training data')
history = model.fit(train_generator,
steps_per_epoch=2000 // batch_size,
history = model.fit(train_dataset,
epochs=options.num_epochs,
validation_data=validation_generator,
validation_steps=800 // batch_size,
validation_data=validation_dataset,
callbacks=callbacks,
verbose=2
)
print('\nHistory dict:', history.history)
'''
# Evaluate the model on the test data using `evaluate`
print('\n# Evaluate on test data')
results = model.evaluate(test_dataset
# , batch_size=128
)
print('test loss, test acc:', results)
'''
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment