Skip to content

V2 cuda #7

Merged
merged 3 commits into from
Jan 1, 2025
Merged
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
5 changes: 0 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 6 additions & 14 deletions tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -121,10 +122,11 @@ 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)
Expand All @@ -135,11 +137,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
Expand All @@ -154,7 +151,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
Expand All @@ -173,12 +170,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()
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]}")
f.close()
170 changes: 86 additions & 84 deletions testlog/log0.txt
Original file line number Diff line number Diff line change
@@ -1,204 +1,206 @@
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


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
Expand Down