I am doing image classification. I was trying classical methods (GridSearch, Pipeline) for finding the best parameters, but as I imported my images with ImageDataGenerator it was not working very well.
In the searches for a solution, I found KerasTuner (never heard of this before).
The code examples I found on a website seemed to be not hard to implement. So I tried it. But it is taking too long for just a training evaluation (not any result of test data). So I thought maybe I did something wrong in my script (see below)
It is running already for the second day on 2080Ti, and I don't have even val_accuracy. For accuracy I am already having 0.9736 and loss:0.0604 which is great, to be honest. But will it take a lifetime until a real result?
My dataset consists of 12000 images for training and 1600 for testing. (4 classes)
from kerastuner.applications import HyperResNet
from kerastuner.tuners import Hyperband
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
horizontal_flip=True
)
# augmentation configuration for testing, only rescale
test_datagen = ImageDataGenerator(rescale=1./255)
batch_size = 128
train_generator = train_datagen.flow_from_directory(
'/media/data/working_dir/categories/readytotest/train',
target_size=(240, 320),
color_mode="grayscale",
batch_size=batch_size,
shuffle=True,
class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
'/media/data/working_dir/categories/readytotest/test',
target_size=(240, 320),
color_mode="grayscale",
batch_size=batch_size,
shuffle=True,
class_mode='categorical')
hypermodel = HyperResNet(input_shape=(240, 320, 1), classes=4)
tuner = Hyperband(
hypermodel,
objective='val_accuracy',
max_epochs=5,
directory='/media/data/working_dir/scr/models/',
project_name='first_kt')
print("SUMMARY OF THE TASK")
tuner.search_space_summary()
# perform analyses
N_EPOCH_SEARCH = 5
tuner.search(train_generator,
epochs=N_EPOCH_SEARCH,
validation_data=validation_generator)
``