diff --git a/Animals/animal.py b/Animals/animal.py index f8293b6..6df7cee 100644 --- a/Animals/animal.py +++ b/Animals/animal.py @@ -13,11 +13,12 @@ class Animal: path = f'images/{name}2.png' return path - def __init__(self, x, y,name, image, food_image, food, environment, activity, ill=False, adult=False,): + def __init__(self, x, y,name, image_path, food_image, food, environment, activity, ill=False, adult=False,): self.x = x - 1 self.y = y - 1 self.name = name - self.image = image + self.image_path = image_path + self.image = pygame.image.load(image_path) self.adult = adult self.food = food self.food_image = food_image diff --git a/Animals/bat.py b/Animals/bat.py index 766eace..83dc661 100644 --- a/Animals/bat.py +++ b/Animals/bat.py @@ -5,12 +5,12 @@ from datetime import datetime class Bat(Animal): def __init__(self, x, y, adult=False): name = 'bat' - Bat_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "medium" food_image = 'images/grains.png' parrot_food = 'grains' activity = 'nocturnal' - super().__init__(x, y,name, Bat_image, food_image,parrot_food, environment, adult) + super().__init__(x, y,name, image_path, food_image,parrot_food, environment, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/bear.py b/Animals/bear.py index a940095..2950042 100644 --- a/Animals/bear.py +++ b/Animals/bear.py @@ -5,13 +5,13 @@ from datetime import datetime class Bear(Animal): def __init__(self, x, y, adult=False): name = 'bear' - Bear_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "cold" activity = 'nocturnal' ill = self.is_ill() bear_food = 'meat' food_image = 'images/meat.png' - super().__init__(x, y,name, Bear_image, food_image,bear_food,environment, activity, ill, adult) + super().__init__(x, y,name, image_path, food_image,bear_food,environment, activity, ill, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/elephant.py b/Animals/elephant.py index 1486605..701b40d 100644 --- a/Animals/elephant.py +++ b/Animals/elephant.py @@ -5,7 +5,7 @@ from datetime import datetime class Elephant(Animal): def __init__(self, x, y, adult=False): name = 'elephant' - Elephant_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "hot" activity = 'diurnal' ill = self.is_ill() @@ -16,7 +16,7 @@ class Elephant(Animal): elephant_food = 'milk' food_image = 'images/milk.png' - super().__init__(x, y,name, Elephant_image, food_image,elephant_food, environment, activity, ill, adult) + super().__init__(x, y,name, image_path, food_image,elephant_food, environment, activity, ill, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/giraffe.py b/Animals/giraffe.py index 4a4e3c8..93479bb 100644 --- a/Animals/giraffe.py +++ b/Animals/giraffe.py @@ -5,13 +5,13 @@ from datetime import datetime class Giraffe(Animal): def __init__(self, x, y, adult=False): name = 'giraffe' - Giraffe_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "hot" activity = 'diurnal' ill = self.is_ill() food_image = 'images/leaves.png' giraffe_food = 'leaves' - super().__init__(x, y, name, Giraffe_image, food_image,giraffe_food, environment, activity, ill, adult) + super().__init__(x, y, name, image_path, food_image,giraffe_food, environment, activity, ill, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/owl.py b/Animals/owl.py index 08ecfc9..fb6125f 100644 --- a/Animals/owl.py +++ b/Animals/owl.py @@ -5,12 +5,12 @@ from datetime import datetime class Owl(Animal): def __init__(self, x, y, adult=False): name = 'owl' - Owl_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "medium" food_image = 'images/grains.png' parrot_food = 'grains' activity = 'nocturnal' - super().__init__(x, y,name, Owl_image, food_image,parrot_food, environment, adult) + super().__init__(x, y,name, image_path, food_image,parrot_food, environment, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/parrot.py b/Animals/parrot.py index e925c5f..e675e8d 100644 --- a/Animals/parrot.py +++ b/Animals/parrot.py @@ -5,13 +5,13 @@ from datetime import datetime class Parrot(Animal): def __init__(self, x, y, adult=False): name = 'parrot' - Parrot_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "medium" activity = 'diurnal' ill = self.is_ill() food_image = 'images/grains.png' parrot_food = 'grains' - super().__init__(x, y, name, Parrot_image, food_image, parrot_food, environment, activity, ill, adult) + super().__init__(x, y, name, image_path, food_image, parrot_food, environment, activity, ill, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/Animals/penguin.py b/Animals/penguin.py index 84a7550..33a885c 100644 --- a/Animals/penguin.py +++ b/Animals/penguin.py @@ -5,13 +5,13 @@ from datetime import datetime class Penguin(Animal): def __init__(self, x, y, adult=False): name = 'penguin' - Penguin_image = pygame.image.load(self.choose_picture(name)) + image_path = self.choose_picture(name) environment = "cold" activity = 'diurnal' ill = self.is_ill() food_image = 'images/fish.png' penguin_food = 'fish' - super().__init__(x, y, name, Penguin_image, food_image, penguin_food, environment, activity, ill, adult) + super().__init__(x, y, name, image_path, food_image, penguin_food, environment, activity, ill, adult) self._starttime = datetime.now() def getting_hungry(self, const): diff --git a/agent.py b/agent.py index c8be38c..4aec681 100644 --- a/agent.py +++ b/agent.py @@ -80,7 +80,7 @@ class Agent: def feed_animal(self, animals, goal,const): goal_x, goal_y = goal - guess = AnimalClassifier('./model/best_model.pth', classes) + neuron = AnimalClassifier('./model/best_model.pth', classes) if self.x == goal_x and self.y == goal_y: for animal in animals: if animal.x == goal_x and animal.y == goal_y: @@ -89,7 +89,11 @@ def feed_animal(self, animals, goal,const): else: activity_time = False guests = random.randint(1, 15) - guess.classify(animal.image) + guess = neuron.classify(animal.image_path) + if guess == animal.name: + print(f"I'm sure this is {guess}") + else: + print(f"I was wrong, this is not a {guess} but a {animal.name}") decision = feed_decision(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood) if decision != [1]: if decision == [2]: diff --git a/classification.py b/classification.py index 9071876..5545b7d 100644 --- a/classification.py +++ b/classification.py @@ -6,7 +6,7 @@ class AnimalClassifier: def __init__(self, model_path, classes, image_size=224, mean=None, std=None): self.classes = classes self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') - self.model = torch.load(model_path) + self.model = torch.load(model_path, map_location=torch.device('cpu')) self.model = self.model.to(self.device) self.model = self.model.eval() self.image_size = image_size @@ -34,7 +34,6 @@ class AnimalClassifier: return self.classes[predicted.item()] -# Define the classes classes = [ "bat", "bear", diff --git a/constants.py b/constants.py index 4af7956..fe715ee 100644 --- a/constants.py +++ b/constants.py @@ -6,7 +6,7 @@ class Constants: def __init__(self): self.BLACK = (0, 0, 0) self.RED = (255, 0, 0) - self.GRID_SIZE = 50 + self.GRID_SIZE = 70 self.GRID_WIDTH = 30 self.GRID_HEIGHT = 15 self.WINDOW_SIZE = (self.GRID_WIDTH * self.GRID_SIZE, self.GRID_HEIGHT * self.GRID_SIZE) diff --git a/images/elephant.png b/images/elephant.png index 86c15e1..6a9125c 100644 Binary files a/images/elephant.png and b/images/elephant.png differ diff --git a/images/giraffe.png b/images/giraffe.png index 8247a89..cbfe5a2 100644 Binary files a/images/giraffe.png and b/images/giraffe.png differ diff --git a/tree.png b/tree.png index b2bac13..0c2c985 100644 Binary files a/tree.png and b/tree.png differ