changed animals to hold image path and implemented neuron model into app
This commit is contained in:
parent
07270d54d4
commit
cda769872b
@ -13,11 +13,12 @@ class Animal:
|
|||||||
path = f'images/{name}2.png'
|
path = f'images/{name}2.png'
|
||||||
return path
|
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.x = x - 1
|
||||||
self.y = y - 1
|
self.y = y - 1
|
||||||
self.name = name
|
self.name = name
|
||||||
self.image = image
|
self.image_path = image_path
|
||||||
|
self.image = pygame.image.load(image_path)
|
||||||
self.adult = adult
|
self.adult = adult
|
||||||
self.food = food
|
self.food = food
|
||||||
self.food_image = food_image
|
self.food_image = food_image
|
||||||
|
@ -5,12 +5,12 @@ from datetime import datetime
|
|||||||
class Bat(Animal):
|
class Bat(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'bat'
|
name = 'bat'
|
||||||
Bat_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "medium"
|
environment = "medium"
|
||||||
food_image = 'images/grains.png'
|
food_image = 'images/grains.png'
|
||||||
parrot_food = 'grains'
|
parrot_food = 'grains'
|
||||||
activity = 'nocturnal'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,13 +5,13 @@ from datetime import datetime
|
|||||||
class Bear(Animal):
|
class Bear(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'bear'
|
name = 'bear'
|
||||||
Bear_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "cold"
|
environment = "cold"
|
||||||
activity = 'nocturnal'
|
activity = 'nocturnal'
|
||||||
ill = self.is_ill()
|
ill = self.is_ill()
|
||||||
bear_food = 'meat'
|
bear_food = 'meat'
|
||||||
food_image = 'images/meat.png'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,7 +5,7 @@ from datetime import datetime
|
|||||||
class Elephant(Animal):
|
class Elephant(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'elephant'
|
name = 'elephant'
|
||||||
Elephant_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "hot"
|
environment = "hot"
|
||||||
activity = 'diurnal'
|
activity = 'diurnal'
|
||||||
ill = self.is_ill()
|
ill = self.is_ill()
|
||||||
@ -16,7 +16,7 @@ class Elephant(Animal):
|
|||||||
elephant_food = 'milk'
|
elephant_food = 'milk'
|
||||||
food_image = 'images/milk.png'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,13 +5,13 @@ from datetime import datetime
|
|||||||
class Giraffe(Animal):
|
class Giraffe(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'giraffe'
|
name = 'giraffe'
|
||||||
Giraffe_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "hot"
|
environment = "hot"
|
||||||
activity = 'diurnal'
|
activity = 'diurnal'
|
||||||
ill = self.is_ill()
|
ill = self.is_ill()
|
||||||
food_image = 'images/leaves.png'
|
food_image = 'images/leaves.png'
|
||||||
giraffe_food = 'leaves'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,12 +5,12 @@ from datetime import datetime
|
|||||||
class Owl(Animal):
|
class Owl(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'owl'
|
name = 'owl'
|
||||||
Owl_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "medium"
|
environment = "medium"
|
||||||
food_image = 'images/grains.png'
|
food_image = 'images/grains.png'
|
||||||
parrot_food = 'grains'
|
parrot_food = 'grains'
|
||||||
activity = 'nocturnal'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,13 +5,13 @@ from datetime import datetime
|
|||||||
class Parrot(Animal):
|
class Parrot(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'parrot'
|
name = 'parrot'
|
||||||
Parrot_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "medium"
|
environment = "medium"
|
||||||
activity = 'diurnal'
|
activity = 'diurnal'
|
||||||
ill = self.is_ill()
|
ill = self.is_ill()
|
||||||
food_image = 'images/grains.png'
|
food_image = 'images/grains.png'
|
||||||
parrot_food = 'grains'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
@ -5,13 +5,13 @@ from datetime import datetime
|
|||||||
class Penguin(Animal):
|
class Penguin(Animal):
|
||||||
def __init__(self, x, y, adult=False):
|
def __init__(self, x, y, adult=False):
|
||||||
name = 'penguin'
|
name = 'penguin'
|
||||||
Penguin_image = pygame.image.load(self.choose_picture(name))
|
image_path = self.choose_picture(name)
|
||||||
environment = "cold"
|
environment = "cold"
|
||||||
activity = 'diurnal'
|
activity = 'diurnal'
|
||||||
ill = self.is_ill()
|
ill = self.is_ill()
|
||||||
food_image = 'images/fish.png'
|
food_image = 'images/fish.png'
|
||||||
penguin_food = 'fish'
|
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()
|
self._starttime = datetime.now()
|
||||||
|
|
||||||
def getting_hungry(self, const):
|
def getting_hungry(self, const):
|
||||||
|
8
agent.py
8
agent.py
@ -80,7 +80,7 @@ class Agent:
|
|||||||
|
|
||||||
def feed_animal(self, animals, goal,const):
|
def feed_animal(self, animals, goal,const):
|
||||||
goal_x, goal_y = goal
|
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:
|
if self.x == goal_x and self.y == goal_y:
|
||||||
for animal in animals:
|
for animal in animals:
|
||||||
if animal.x == goal_x and animal.y == goal_y:
|
if animal.x == goal_x and animal.y == goal_y:
|
||||||
@ -89,7 +89,11 @@ def feed_animal(self, animals, goal,const):
|
|||||||
else:
|
else:
|
||||||
activity_time = False
|
activity_time = False
|
||||||
guests = random.randint(1, 15)
|
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)
|
decision = feed_decision(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood)
|
||||||
if decision != [1]:
|
if decision != [1]:
|
||||||
if decision == [2]:
|
if decision == [2]:
|
||||||
|
@ -6,7 +6,7 @@ class AnimalClassifier:
|
|||||||
def __init__(self, model_path, classes, image_size=224, mean=None, std=None):
|
def __init__(self, model_path, classes, image_size=224, mean=None, std=None):
|
||||||
self.classes = classes
|
self.classes = classes
|
||||||
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
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.to(self.device)
|
||||||
self.model = self.model.eval()
|
self.model = self.model.eval()
|
||||||
self.image_size = image_size
|
self.image_size = image_size
|
||||||
@ -34,7 +34,6 @@ class AnimalClassifier:
|
|||||||
|
|
||||||
return self.classes[predicted.item()]
|
return self.classes[predicted.item()]
|
||||||
|
|
||||||
# Define the classes
|
|
||||||
classes = [
|
classes = [
|
||||||
"bat",
|
"bat",
|
||||||
"bear",
|
"bear",
|
||||||
|
@ -6,7 +6,7 @@ class Constants:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.BLACK = (0, 0, 0)
|
self.BLACK = (0, 0, 0)
|
||||||
self.RED = (255, 0, 0)
|
self.RED = (255, 0, 0)
|
||||||
self.GRID_SIZE = 50
|
self.GRID_SIZE = 70
|
||||||
self.GRID_WIDTH = 30
|
self.GRID_WIDTH = 30
|
||||||
self.GRID_HEIGHT = 15
|
self.GRID_HEIGHT = 15
|
||||||
self.WINDOW_SIZE = (self.GRID_WIDTH * self.GRID_SIZE, self.GRID_HEIGHT * self.GRID_SIZE)
|
self.WINDOW_SIZE = (self.GRID_WIDTH * self.GRID_SIZE, self.GRID_HEIGHT * self.GRID_SIZE)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 642 KiB After Width: | Height: | Size: 373 KiB |
Binary file not shown.
Before Width: | Height: | Size: 444 KiB After Width: | Height: | Size: 161 KiB |
Loading…
Reference in New Issue
Block a user