I am currently attempting to create a CNN which utilises both numerical and image data. The structure of the CNN currently is only image processing, though I need to add the numerical data ontop.
For each image I have I also have an uncatagorised CSV reprenting numerical data about this image:
eg. subject-1.jpg
has an equivalent subject-1.csv
. As stated I currently have a CNN which creates a model using only the images, though I am wondering how I can encorperate the numerical data to improve the accuracy of the CNN.
If anyone could assist me or point me in the right direction it would be much appreciated.
My current process looks like this:
Create datasets for image testing and image validation, numerical testing and numerical validation, utilising this function body:
dataset = tf.keras.preprocessing.image_dataset_from_directory(
path,
validation_split=0.2,
subset=setType,
seed=123,
image_size=(IMG_SIZE, IMG_SIZE),
batch_size=8)
Configuration:
AUTOTUNE = tf.data.AUTOTUNE
train_image_data = train_image_data .cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)
test_iamge_data = test_iamge_data .cache().prefetch(buffer_size=AUTOTUNE)
train_num_data = train_num_data .cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)
test_num_data = test_num_data .cache().prefetch(buffer_size=AUTOTUNE)
Normalise:
normalization_layer = layers.experimental.preprocessing.Rescaling(1./255)
norm_img_ds = train_image_data .map(lambda x, y: (normalization_layer(x), y))
norm_num_ds = train_num_data .map(lambda x, y: (normalization_layer(x), y))
Then creating the model:
num_classes = len(CATAGORIES)
model = Sequential([
layers.experimental.preprocessing.Rescaling(1./255, input_shape=(IMG_SIZE, IMG_SIZE, 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'])