Skip to content
Snippets Groups Projects
Commit 1a972d08 authored by Barry Timothee's avatar Barry Timothee
Browse files

feat: exo 1 à 3

parent db21682e
No related branches found
No related tags found
No related merge requests found
*.jpg
.DS_Store
# Data
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
images/audi.jpg

507 KiB

images/cat.jpg

124 KiB

File moved
images/piano.jpg

32.3 KiB

images/rafale.jpg

44.9 KiB

images/spiderweb.webp

138 KiB

images/strawberries.jpg

1.06 MiB

images/sunglasses.webp

82.3 KiB

images/voilier.jpg

42.2 KiB

import numpy as np
def compare_models_accuracy(classes, class_correct_1, class_correct_2, class_total, model_name_1, model_name_2):
# Compare les résultats de deux modèles (accuracy par classe)
print("Overall Accuracy:")
print(
"%2s: %2d%% (%2d/%2d) \t %s: %2d%% (%2d/%2d) --> %s%4s%%"
% (
model_name_1,
100.0 * np.sum(class_correct_1) / np.sum(class_total),
np.sum(class_correct_1),
np.sum(class_total),
model_name_2,
100.0 * np.sum(class_correct_2) / np.sum(class_total),
np.sum(class_correct_2),
np.sum(class_total),
"+" if np.sum(class_correct_2) - np.sum(class_correct_1) > 0 else "",
100.0 * (np.sum(class_correct_2) - np.sum(class_correct_1)) / np.sum(class_total)
)
)
print("\nAccuracy by class:")
for i in range(10):
if class_total[i] > 0:
print(
"%10s \t %2s: %2d%% (%2d/%2d) \t %s: %2d%% (%2d/%2d) --> %s%4s%%"
% (
classes[i],
model_name_1,
100 * class_correct_1[i] / class_total[i],
np.sum(class_correct_1[i]),
np.sum(class_total[i]),
model_name_2,
100 * class_correct_2[i] / class_total[i],
np.sum(class_correct_2[i]),
np.sum(class_total[i]),
"+" if class_correct_2[i] - class_correct_1[i] > 0 else "",
100 * (class_correct_2[i] - class_correct_1[i]) / class_total[i]
)
)
\ No newline at end of file
import matplotlib.pyplot as plt
def plot_performance(train_loss_list, val_loss_list, title = "Performance of Model"):
# Plot the performance of the model (train loss and validation loss)
epochs_list = range(len(train_loss_list))
plt.plot(epochs_list, train_loss_list)
plt.plot(epochs_list, val_loss_list)
plt.legend(["Train Loss", "Validation Loss"])
plt.xlabel("Epoch")
plt.ylabel("Loss")
plt.title(title)
plt.show()
\ No newline at end of file
import os
import torch
def print_size_of_model(model, label=""):
# Print the size of the model
torch.save(model.state_dict(), "temp.p")
size = os.path.getsize("temp.p")
print("model: ", label, " \t", "Size (KB):", size / 1e3)
os.remove("temp.p")
return size
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment