some code cleaning

This commit is contained in:
Zofia Lorenc 2024-05-27 10:38:22 +02:00
parent 58524a59a7
commit 03724c3cf4
2 changed files with 0 additions and 40 deletions

View File

@ -52,7 +52,6 @@ class Tile(pygame.sprite.Sprite):
self.prediction = self.predict(model, image_transforms, self.image_path, classes) self.prediction = self.predict(model, image_transforms, self.image_path, classes)
else: else:
if random.randint(1, 10) % 3 == 0: if random.randint(1, 10) % 3 == 0:
self.set_type('water') self.set_type('water')
@ -79,9 +78,7 @@ class Tile(pygame.sprite.Sprite):
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))] files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
random_file = random.choice(files) random_file = random.choice(files)
#image_path = os.path.join(folder_path, random_file)
image_path = folder_path + "/" + random_file image_path = folder_path + "/" + random_file
#print(image_path)
return image_path return image_path
def set_type(self, type): def set_type(self, type):
@ -110,7 +107,6 @@ class Tile(pygame.sprite.Sprite):
output = model(image) output = model(image)
_, predicted = torch.max(output.data, 1) _, predicted = torch.max(output.data, 1)
#print("Rozpoznano: ", classes[predicted.item()])
result = classes[predicted.item()] result = classes[predicted.item()]
if result == "ziemniak": if result == "ziemniak":
result = 'marchew' result = 'marchew'

View File

@ -1,36 +0,0 @@
# import torch
# import torchvision.transforms as transforms
# from PIL import Image
# classes = [
# "bób", "brokuł", "brukselka", "burak", "cebula",
# "cukinia", "dynia", "fasola", "groch", "jarmuż",
# "kalafior", "kalarepa", "kapusta", "marchew",
# "ogórek", "papryka", "pietruszka", "pomidor",
# "por", "rzepa", "rzodkiewka", "sałata", "seler",
# "szpinak", "ziemniak"]
# model = torch.load("best_model.pth")
# mean = [0.5322, 0.5120, 0.3696]
# std = [0.2487, 0.2436, 0.2531]
# image_transforms = transforms.Compose([
# transforms.Resize((224, 224)),
# transforms.ToTensor(),
# transforms.Normalize(torch.Tensor(mean),torch.Tensor(std))
# ])
# def predict(model, image_transforms, image_path, classes):
# model = model.eval()
# image = Image.open(image_path)
# print(image_path)
# image = image_transforms(image).float()
# image = image.unsqueeze(0)
# output = model(image)
# _, predicted = torch.max(output.data, 1)
# print(classes[predicted.item()])
# predict(model, image_transforms, "veggies/marchew_118.jpg", classes)