I have a database of 9000+ thin-section images of pottery, each in separate folders divided into their 7 periods (iron age, bronze age, etc) and each looking like something like this https://i.imgur.com/0kNzItI.jpeg.
Archaeologists can look at these thin sections and make out which period they were likely in based on their composition. But I was wondering if a deep learning model could save them time and try to classify new pottery into their period.
This is my code but it’s getting terrible results, like into the 30% validation which is almost guessing at random. Any ideas to improve my model or is it an impossible task. My images do have different image styles depending on the person taking the thin-section image which might affect the model.
import matplotlib.pyplot as plt
import numpy as np
import PIL
import tensorflow as tf
from sklearn.metrics import confusion_matrix
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
batch_size = 32
img_height = 1024
img_width = 1024
data_dir = r'C:\MajorProject\data'
train_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
val_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
num_classes = len(class_names)
model = Sequential([
layers.Rescaling(1./255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(16, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(32, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(64, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(num_classes)
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
epochs=10
history = model.fit(
train_ds,
validation_data=val_ds,
epochs=epochs
)