“!pip install keras-tuner
def build_model(hp):
model = Sequential()
# Conv Block 1
model.add(Conv2D(
filters=hp.Int('conv_1_filter', min_value=32, max_value=128, step=16),
kernel_size=hp.Choice('conv_1_kernel', values=[3, 5]),
padding='same',
activation='relu',
input_shape=(224,224,3)
))
model.add(Conv2D(
filters=hp.Int('conv_1_filter', min_value=32, max_value=128, step=16),
kernel_size=hp.Choice('conv_1_kernel', values=[3, 5]),
activation='relu'
))
model.add(MaxPooling2D(pool_size=(2, 2), strides=2))
# Conv Block 2
model.add(Conv2D(
filters=hp.Int('conv_2_filter', min_value=32, max_value=128, step=16),
kernel_size=hp.Choice('conv_2_kernel', values=[3, 5]),
padding='same',
activation='relu'
))
model.add(Conv2D(
filters=hp.Int('conv_2_filter', min_value=32, max_value=128, step=16),
kernel_size=hp.Choice('conv_2_kernel', values=[3, 5]),
activation='relu'
))
model.add(MaxPooling2D(pool_size=(2, 2), strides=2))
# Conv Block 3
model.add(Conv2D(
filters=hp.Int('conv_3_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_3_kernel', values=[3, 5]),
padding='same',
activation='relu'
))
model.add(Conv2D(
filters=hp.Int('conv_3_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_3_kernel', values=[3, 5]),
activation='relu'
))
model.add(MaxPooling2D(pool_size=(2, 2), strides=2))
# Conv Block 3
model.add(Conv2D(
filters=hp.Int('conv_3_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_3_kernel', values=[3, 5]),
padding='same',
activation='relu'
))
model.add(Conv2D(
filters=hp.Int('conv_3_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_3_kernel', values=[3, 5]),
activation='relu'
))
model.add(MaxPooling2D(pool_size=(2, 2), strides=2))
# Conv Block 4
model.add(Conv2D(
filters=hp.Int('conv_4_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_4_kernel', values=[3, 5]),
padding='same',
activation='relu'
))
model.add(Conv2D(
filters=hp.Int('conv_4_filter', min_value=64, max_value=256, step=32),
kernel_size=hp.Choice('conv_4_kernel', values=[3, 5]),
activation='relu'
))
model.add(MaxPooling2D(pool_size=(2, 2), strides=2))
model.add(Flatten())
# Fully Connected Layer
model.add(Dense(
units=hp.Int('dense_units', min_value=64, max_value=512, step=32),
activation='relu'
))
model.add(Dense(
units=hp.Int('additional_dense_units', min_value=64, max_value=256, step=32),
activation='relu'
))
model.add(Dropout(rate=hp.Float('dropout_rate', min_value=0.1, max_value=0.5, step=0.1)))
model.add(Dense(3, activation='softmax'))
model.compile(
optimizer=keras.optimizers.Adam(hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])),
loss='categorical_crossentropy',
metrics=['accuracy']
)
return model
train_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
zoom_range=0.5
)
train_generator = train_datagen.flow_from_directory(
'/content/drive/MyDrive/DataSet/train',
target_size=(224,224),
color_mode='rgb',
batch_size=32,
shuffle=True
)
validation_datagen = ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_directory(
'/content/drive/MyDrive/DataSet/val',
target_size=(224,224),
color_mode='rgb',
batch_size=32,
shuffle=True
)
tuner = kt.RandomSearch(
build_model,
objective='val_accuracy',
max_trials=5,
directory='output',
project_name='Image_Classification_Tuning'
)
tuner.search(train_generator, epochs=5, validation_data=validation_generator)
# Get the best model
best_model = tuner.get_best_models(num_models=1)[0]
best_model.summary()
# Train the best model
history = best_model.fit(
x=train_generator,
epochs=20,
validation_data=validation_generator
)`
This is my code for skin disease prediction , which has 3 classes and i have divided my dataset into 80% for training which has 2307 images and , 10% validation which has 657 images and 10% for test , but my accuracy is not increasing , it is between 70% to 75% , what can I do to increase it.
I’m trying to improve my model accuracy
New contributor
Danster DEX1998 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.