Code cleanup
This commit is contained in:
@@ -39,7 +39,7 @@ tensorboard = TensorBoard(log_dir=log_dir)
|
||||
# Configuration
|
||||
# -----------------------
|
||||
shuffle_count=3000
|
||||
dataset_path = 'C:\\boneyard\\DeepLearning\\data'
|
||||
dataset_path = '/home/pi/DeepLearning/Data'
|
||||
image_size = (actualImageDimension, actualImageDimension)
|
||||
batch_size = 16 # try 16 was 32
|
||||
image_size=(actualImageDimension, actualImageDimension)
|
||||
@@ -74,22 +74,7 @@ val_ds = tf.keras.preprocessing.image_dataset_from_directory(
|
||||
# -----------------------
|
||||
# Data Augmentation
|
||||
# -----------------------
|
||||
|
||||
# data_augmentation = tf.keras.Sequential([
|
||||
# layers.RandomFlip("horizontal"),
|
||||
# layers.RandomRotation(0.1)
|
||||
# ])
|
||||
#data_augmentation = tf.keras.Sequential([
|
||||
# layers.RandomFlip("horizontal"),
|
||||
# layers.RandomRotation(0.1),
|
||||
# layers.RandomRotation(0.1, fill_mode="nearest"),
|
||||
# layers.RandomZoom(0.1)
|
||||
#])
|
||||
|
||||
|
||||
# def preprocess_train(x, y):
|
||||
# x = data_augmentation(x, training=True)
|
||||
# return x, y
|
||||
# I do this in c#-land
|
||||
|
||||
def preprocess_val(x, y):
|
||||
return x, y
|
||||
@@ -106,22 +91,6 @@ train_ds = (
|
||||
)
|
||||
|
||||
|
||||
# for images, labels in train_ds.take(1):
|
||||
|
||||
# plt.figure(figsize=(10,10))
|
||||
|
||||
# for i in range(12):
|
||||
# ax = plt.subplot(3,4,i+1)
|
||||
# plt.imshow(images[i].numpy().astype("uint8"))
|
||||
# plt.title(int(labels[i].numpy()))
|
||||
# plt.axis("off")
|
||||
|
||||
# plt.tight_layout()
|
||||
# plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------
|
||||
# ConvNeXt-Tiny Base Model
|
||||
# -----------------------
|
||||
@@ -143,13 +112,6 @@ inputs = tf.keras.Input(shape=(actualImageDimension, actualImageDimension, 3))
|
||||
|
||||
x = preprocess_input(inputs)
|
||||
x = base_model(x)
|
||||
# Dense Head
|
||||
# x = layers.GlobalAveragePooling2D()(x)
|
||||
# x = layers.BatchNormalization()(x)
|
||||
# x = layers.Dense(512, activation="relu")(x)
|
||||
# x = layers.Dropout(0.3)(x)
|
||||
# x = layers.Dense(128, activation="relu")(x)
|
||||
|
||||
x = layers.GlobalAveragePooling2D()(x)
|
||||
x = layers.BatchNormalization()(x)
|
||||
x = layers.Dense(256, activation="relu")(x)
|
||||
@@ -228,36 +190,3 @@ history_fine = model.fit(
|
||||
validation_data=val_ds,
|
||||
callbacks=[tensorboard, lr_scheduler, early_stopping, checkpointer]
|
||||
)
|
||||
|
||||
|
||||
# -----------------------
|
||||
# Plot Results
|
||||
# -----------------------
|
||||
|
||||
def plot_history(hist, title_prefix=""):
|
||||
plt.figure()
|
||||
plt.plot(hist.history['accuracy'], label='Train Accuracy')
|
||||
plt.plot(hist.history['val_accuracy'], label='Val Accuracy')
|
||||
plt.title(f'{title_prefix} Accuracy')
|
||||
plt.xlabel('Epochs')
|
||||
plt.ylabel('Accuracy')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
plt.figure()
|
||||
plt.plot(hist.history['loss'], label='Train Loss')
|
||||
plt.plot(hist.history['val_loss'], label='Val Loss')
|
||||
plt.title(f'{title_prefix} Loss')
|
||||
plt.xlabel('Epochs')
|
||||
plt.ylabel('Loss')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
plot_history(history, "Initial Training")
|
||||
plot_history(history_fine, "Fine-Tuning")
|
||||
|
||||
# -----------------------
|
||||
# Save Final Model
|
||||
# -----------------------
|
||||
|
||||
#model.save(modelname)
|
||||
Reference in New Issue
Block a user