Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added accuracy_mazin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added loss_mazin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 54 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
"""
This is a starter file to get you going. You may also include other files if you feel it's necessary.
import tensorflow as tf
from sklearn.metrics import confusion_matrix, classification_report
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
import numpy as np

Make sure to follow the code convention described here:
https://github.com/UWARG/computer-vision-python/blob/main/README.md#naming-and-typing-conventions
def plot_sample(X, y, index):
plt.figure(figsize = (15, 2))
plt.imshow(X[index])
plt.xlabel(classes[y[index]])
plt.show()

Hints:
* The internet is your friend! Don't be afraid to search for tutorials/intros/etc.
* We suggest using a convolutional neural network.
* TensorFlow Keras has the CIFAR-10 dataset as a module, so you don't need to manually download and unpack it.
"""
(X_train, y_train), (X_test, y_test) = datasets.cifar10.load_data()

# Import whatever libraries/modules you need
classes = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]

import numpy as np
y_train = y_train.reshape(-1,)

X_train = X_train/255
X_test = X_test/255

cnn = models.Sequential([
layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu', input_shape=(32, 32, 3)),
layers.MaxPooling2D((2, 2)),

layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),

layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(10, activation='softmax')
])

cnn.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model_history = cnn.fit(X_train, y_train, epochs=10)
cnn.evaluate(X_test, y_test)
y_pred = cnn.predict(X_test)
y_class = [np.argmax(element) for element in y_pred]

def plot_loss():
plt.plot(model_history.history['loss'], label='loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend(['Training', 'Test'])
plt.savefig('loss_mazin.png')
plt.close()

def plot_accuracy():
plt.plot(model_history.history['accuracy'], label='accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend(['Training', 'Test'])
plt.savefig('accuracy_mazin.png')
plt.close()

# Your working code here
plot_accuracy()
plot_loss()
Loading