BAI1120 - Assessment - Ipynb - Colaboratory
BAI1120 - Assessment - Ipynb - Colaboratory
BAI1120 - Assessment - Ipynb - Colaboratory
ipynb - Colaboratory
import os
import numpy as np
import tensorflow as tf
from sklearn import svm
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications import vgg16
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import classification_report, accuracy_score
# Create an instance of ImageDataGenerator for data augmentation and to load images in batches
datagen = ImageDataGenerator(rescale=1./255, validation_split=0.2)
validation_batches = datagen.flow_from_directory(
dataset_path,
target_size=(224, 224),
batch_size=batch_size,
class_mode='sparse',
subset='validation'
)
https://colab.research.google.com/drive/1MNTv5uyY6snHRluB7Vbc-tiJc5DqWQL0?authuser=0#scrollTo=arpKjXEgUhO-&printMode=true 1/2
17/03/2024, 22:20 BAI1120_Assessment.ipynb - Colaboratory
# Flatten the features to fit into the SVM classifier
train_features = np.reshape(train_features, (train_features.shape[0], 7 * 7 * 512))
validation_features = np.reshape(validation_features, (validation_features.shape[0], 7 * 7 * 512))
▾ SVC
SVC(C=1, kernel='linear')
accuracy 1.00 78
macro avg 1.00 1.00 1.00 78
weighted avg 1.00 1.00 1.00 78
https://colab.research.google.com/drive/1MNTv5uyY6snHRluB7Vbc-tiJc5DqWQL0?authuser=0#scrollTo=arpKjXEgUhO-&printMode=true 2/2