From f722ffbde38365505eb54a59a9b4bf4bff959023 Mon Sep 17 00:00:00 2001 From: "Seb Douse (douses)" Date: Wed, 1 Jan 2025 22:39:20 +0000 Subject: [PATCH 1/3] Remove unnecessary code --- tester.py | 12 +----------- testlog/log1.txt | 0 2 files changed, 1 insertion(+), 11 deletions(-) create mode 100644 testlog/log1.txt diff --git a/tester.py b/tester.py index 35a207e..e5b75a3 100644 --- a/tester.py +++ b/tester.py @@ -135,11 +135,6 @@ def __getitem__(self, idx): image = self.transform(image) return image, label - -# Test with dummy data -img = mpimg.imread(path) -plt.imshow(img) -plt.show() #Cleans input # Define your transformations (e.g., resize, normalization) in case an image or not the correct format @@ -176,9 +171,4 @@ def __getitem__(self, idx): f.write(f"\nAccuracy: {round((correct / test_loader.__len__()) * 100, 1)}%") for key, value in BigCatAccuracy.items(): f.write(f"{BigCatLabel[key]} guessed correctly {(value / 5) * 100}% of the time\n") -f.close() -image = Image.open(path).convert('RGB') -test_input = transform(image).unsqueeze(0) # Add batch dimension: [1, 3, 224, 224] -output = model(test_input) -predicted_class = torch.argmax(output, dim=1).item() -print(f"Predicted class: {BigCatLabel[predicted_class]}") \ No newline at end of file +f.close() \ No newline at end of file diff --git a/testlog/log1.txt b/testlog/log1.txt new file mode 100644 index 0000000..e69de29 From 4cdf20d8a535018f520e0b4e186af1f47341d4d3 Mon Sep 17 00:00:00 2001 From: "Seb Douse (douses)" Date: Wed, 1 Jan 2025 22:58:32 +0000 Subject: [PATCH 2/3] Timestamp added to logs and slight cleanup to tester --- main.py | 5 -- tester.py | 11 +-- testlog/log0.txt | 170 ++++++++++++++++++++++++----------------------- testlog/log1.txt | 0 4 files changed, 92 insertions(+), 94 deletions(-) delete mode 100644 testlog/log1.txt diff --git a/main.py b/main.py index 6a16edd..2c5e4bc 100644 --- a/main.py +++ b/main.py @@ -44,11 +44,6 @@ def __getitem__(self, idx): img_name = os.path.join(self.root_dir, self.data_frame.iloc[idx, 1]) # grabs the filepath column from the csv image = Image.open(img_name).convert('RGB') # Load image and converts into RGB values from grabbed filepath label = torch.tensor(self.data_frame.iloc[idx]['numeric_label'], dtype=torch.long) # gets the numeric version of the label from the label column of the csv - - #For debugging and measuring progress in an epoch in a human readable way - length = self.__len__() - if (idx+1) % 16 == 0: - print(f"Batch: {int((idx+1)/16)} / {length // 16}") #Displays progress in number of batches per epoch completed #If the image is not the correct size and format, reshape it so it is as such if self.transform: diff --git a/tester.py b/tester.py index e5b75a3..1326ceb 100644 --- a/tester.py +++ b/tester.py @@ -8,6 +8,7 @@ import time import matplotlib.pyplot as plt import matplotlib.image as mpimg +from datetime import datetime lognum = 0 filename = rf"testlog\log{lognum}.txt" @@ -121,14 +122,14 @@ def __getitem__(self, idx): img_name = os.path.join(self.root_dir, self.data_frame.iloc[idx, 1]) # grabs the filepath column from the csv image = Image.open(img_name).convert('RGB') # Load image and converts into RGB values from grabbed filepath label = torch.tensor(self.data_frame.iloc[idx]['numeric_label'], dtype=torch.long) # gets the numeric version of the label from the label column of the csv - + print("") print("") print(f"Animal: {self.data_frame.iloc[idx]['labels']}") img = mpimg.imread(img_name) plt.imshow(img) plt.show(block = False) - plt.pause(2) + #plt.pause(2) plt.close() if self.transform: @@ -149,7 +150,7 @@ def __getitem__(self, idx): test_loader = DataLoader(test_dataset, batch_size=1, shuffle=True) correct = 0 f = open(filename, "w") - +f.write(f"Compiled on: {datetime.now().strftime('%Y-%m-%d')} at {datetime.now().strftime('%H:%M:%S')}") for image, labels in test_loader: #Cleans input @@ -157,7 +158,7 @@ def __getitem__(self, idx): output = model(test_input) predicted_class = torch.argmax(output, dim=1).item() print(f"Predicted class: {BigCatLabel[predicted_class]}") - time.sleep(2) + #time.sleep(2) if predicted_class == labels: correct+=1 BigCatAccuracy[predicted_class] += 1 @@ -168,7 +169,7 @@ def __getitem__(self, idx): print(f"Percentage Correct: {round((correct / test_loader.__len__()) * 100, 1)}%") f.write("") -f.write(f"\nAccuracy: {round((correct / test_loader.__len__()) * 100, 1)}%") +f.write(f"\nAccuracy: {round((correct / test_loader.__len__()) * 100, 1)}%\n") for key, value in BigCatAccuracy.items(): f.write(f"{BigCatLabel[key]} guessed correctly {(value / 5) * 100}% of the time\n") f.close() \ No newline at end of file diff --git a/testlog/log0.txt b/testlog/log0.txt index 9872168..e3359af 100644 --- a/testlog/log0.txt +++ b/testlog/log0.txt @@ -1,22 +1,30 @@ +Compiled on: 2025-01-01 at 22:54:14 +Animal: CLOUDED LEOPARD +Predicted class: Clouded Leopard -Animal: OCELOT + +Animal: TIGER Predicted class: Tiger -Animal: CARACAL -Predicted class: Caracal +Animal: JAGUAR +Predicted class: Ocelot -Animal: JAGUAR -Predicted class: African Leopard +Animal: AFRICAN LEOPARD +Predicted class: Jaguar -Animal: OCELOT -Predicted class: Ocelot +Animal: TIGER +Predicted class: Tiger -Animal: SNOW LEOPARD +Animal: CARACAL +Predicted class: Caracal + + +Animal: OCELOT Predicted class: Clouded Leopard @@ -24,181 +32,175 @@ Animal: JAGUAR Predicted class: Ocelot -Animal: CHEETA -Predicted class: Cheeta - - Animal: SNOW LEOPARD Predicted class: Ocelot -Animal: JAGUAR -Predicted class: African Leopard +Animal: OCELOT +Predicted class: Tiger -Animal: CLOUDED LEOPARD -Predicted class: Clouded Leopard +Animal: PUMA +Predicted class: Puma -Animal: CLOUDED LEOPARD -Predicted class: Tiger +Animal: LIONS +Predicted class: Lions -Animal: AFRICAN LEOPARD -Predicted class: African Leopard +Animal: PUMA +Predicted class: Caracal + + +Animal: OCELOT +Predicted class: Clouded Leopard Animal: JAGUAR Predicted class: African Leopard -Animal: LIONS +Animal: CARACAL +Predicted class: Lions + + +Animal: PUMA Predicted class: Puma -Animal: AFRICAN LEOPARD -Predicted class: Jaguar +Animal: LIONS +Predicted class: Lions -Animal: AFRICAN LEOPARD -Predicted class: Jaguar +Animal: JAGUAR +Predicted class: African Leopard -Animal: CLOUDED LEOPARD +Animal: OCELOT Predicted class: Ocelot -Animal: LIONS -Predicted class: Lions +Animal: SNOW LEOPARD +Predicted class: Snow Leopard -Animal: OCELOT -Predicted class: Clouded Leopard +Animal: TIGER +Predicted class: Tiger -Animal: PUMA -Predicted class: Caracal +Animal: TIGER +Predicted class: Tiger -Animal: PUMA -Predicted class: Puma +Animal: SNOW LEOPARD +Predicted class: Snow Leopard -Animal: PUMA -Predicted class: Caracal +Animal: SNOW LEOPARD +Predicted class: Clouded Leopard -Animal: AFRICAN LEOPARD -Predicted class: African Leopard +Animal: OCELOT +Predicted class: Ocelot -Animal: JAGUAR -Predicted class: Ocelot +Animal: AFRICAN LEOPARD +Predicted class: Cheeta -Animal: TIGER -Predicted class: Tiger +Animal: CLOUDED LEOPARD +Predicted class: Ocelot -Animal: CARACAL +Animal: PUMA Predicted class: Caracal -Animal: LIONS -Predicted class: Lions +Animal: CLOUDED LEOPARD +Predicted class: Clouded Leopard -Animal: SNOW LEOPARD -Predicted class: Snow Leopard +Animal: CHEETA +Predicted class: Ocelot Animal: CHEETA Predicted class: Cheeta -Animal: OCELOT -Predicted class: Clouded Leopard - - Animal: CARACAL -Predicted class: Lions +Predicted class: Caracal Animal: TIGER Predicted class: Tiger -Animal: LIONS -Predicted class: Lions +Animal: CHEETA +Predicted class: Tiger -Animal: CARACAL +Animal: PUMA Predicted class: Puma -Animal: TIGER -Predicted class: Tiger - - -Animal: CARACAL -Predicted class: Caracal +Animal: AFRICAN LEOPARD +Predicted class: Jaguar -Animal: SNOW LEOPARD -Predicted class: Snow Leopard +Animal: JAGUAR +Predicted class: African Leopard Animal: CHEETA -Predicted class: Tiger +Predicted class: African Leopard -Animal: TIGER -Predicted class: Tiger +Animal: AFRICAN LEOPARD +Predicted class: African Leopard Animal: LIONS Predicted class: Lions -Animal: CHEETA -Predicted class: African Leopard +Animal: CARACAL +Predicted class: Caracal -Animal: TIGER +Animal: CLOUDED LEOPARD Predicted class: Tiger -Animal: CHEETA -Predicted class: Ocelot +Animal: AFRICAN LEOPARD +Predicted class: African Leopard + + +Animal: LIONS +Predicted class: Lions Animal: CLOUDED LEOPARD Predicted class: Clouded Leopard -Animal: PUMA +Animal: LIONS Predicted class: Puma -Animal: AFRICAN LEOPARD -Predicted class: Cheeta +Animal: CARACAL +Predicted class: Puma Animal: SNOW LEOPARD Predicted class: Ocelot -Animal: OCELOT -Predicted class: Ocelot - - -Animal: CLOUDED LEOPARD -Predicted class: Clouded Leopard - +Animal: CHEETA +Predicted class: Cheeta -Animal: PUMA -Predicted class: Puma -Accuracy: 52.0%African Leopard guessed correctly 40.0% of the time +Accuracy: 52.0% +African Leopard guessed correctly 40.0% of the time Caracal guessed correctly 60.0% of the time Cheeta guessed correctly 40.0% of the time Clouded Leopard guessed correctly 60.0% of the time diff --git a/testlog/log1.txt b/testlog/log1.txt deleted file mode 100644 index e69de29..0000000 From ccbb82c294c0d16a04ae3b9b2bdb2d038fb8411f Mon Sep 17 00:00:00 2001 From: "Seb Douse (douses)" Date: Wed, 1 Jan 2025 22:59:04 +0000 Subject: [PATCH 3/3] Update tester.py --- tester.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tester.py b/tester.py index 1326ceb..c760dea 100644 --- a/tester.py +++ b/tester.py @@ -126,10 +126,11 @@ def __getitem__(self, idx): print("") print("") print(f"Animal: {self.data_frame.iloc[idx]['labels']}") + img = mpimg.imread(img_name) plt.imshow(img) plt.show(block = False) - #plt.pause(2) + plt.pause(2) plt.close() if self.transform: @@ -158,7 +159,7 @@ def __getitem__(self, idx): output = model(test_input) predicted_class = torch.argmax(output, dim=1).item() print(f"Predicted class: {BigCatLabel[predicted_class]}") - #time.sleep(2) + time.sleep(2) if predicted_class == labels: correct+=1 BigCatAccuracy[predicted_class] += 1