diff --git a/source/NN/__pycache__/model.cpython-311.pyc b/source/NN/__pycache__/model.cpython-311.pyc index 6e6c934..d666349 100644 Binary files a/source/NN/__pycache__/model.cpython-311.pyc and b/source/NN/__pycache__/model.cpython-311.pyc differ diff --git a/source/NN/__pycache__/neural_network.cpython-311.pyc b/source/NN/__pycache__/neural_network.cpython-311.pyc index e36880c..2dc9bae 100644 Binary files a/source/NN/__pycache__/neural_network.cpython-311.pyc and b/source/NN/__pycache__/neural_network.cpython-311.pyc differ diff --git a/source/NN/neural_network.py b/source/NN/neural_network.py index 8336d9c..be60774 100644 --- a/source/NN/neural_network.py +++ b/source/NN/neural_network.py @@ -4,10 +4,10 @@ from torch.utils.data import DataLoader from torchvision import datasets, transforms, utils from torchvision.transforms import Compose, Lambda, ToTensor import matplotlib.pyplot as plt -from model import * +from NN.model import * from PIL import Image -device = torch.device('cuda') +device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') #data transform to tensors: data_transformer = transforms.Compose([ @@ -56,12 +56,12 @@ def accuracy(model, dataset): return correct.float() / len(dataset) -model = Conv_Neural_Network_Model() -model.to(device) +# model = Conv_Neural_Network_Model() +# model.to(device) #loading the already saved model: -model.load_state_dict(torch.load('CNN_model.pth')) -model.eval() +# model.load_state_dict(torch.load('CNN_model.pth')) +# model.eval() # #training the model: # train(model, train_set) @@ -72,13 +72,13 @@ model.eval() def load_model(): model = Conv_Neural_Network_Model() - model.load_state_dict(torch.load('CNN_model.pth')) + model.load_state_dict(torch.load('CNN_model.pth', map_location=torch.device('cpu'))) model.eval() return model def load_image(image_path): - testImage = Image.open(image_path) + testImage = Image.open(image_path).convert('RGB') testImage = data_transformer(testImage) testImage = testImage.unsqueeze(0) return testImage @@ -98,17 +98,17 @@ def guess_image(model, image_tensor): # print(f"The predicted image is: {prediction}") #TEST - loading the image and getting results: -testImage_path = 'resources/images/plant_photos/1c76aa4d-11f4-47d1-8bdd-2cb78deeeccf.jpg' -testImage = Image.open(testImage_path) -testImage = data_transformer(testImage) -testImage = testImage.unsqueeze(0) -testImage = testImage.to(device) +# testImage_path = 'resources/images/plant_photos/1c76aa4d-11f4-47d1-8bdd-2cb78deeeccf.jpg' +# testImage = Image.open(testImage_path) +# testImage = data_transformer(testImage) +# testImage = testImage.unsqueeze(0) +# testImage = testImage.to(device) -model.load_state_dict(torch.load('CNN_model.pth')) -model.to(device) -model.eval() +# model.load_state_dict(torch.load('CNN_model.pth')) +# model.to(device) +# model.eval() -testOutput = model(testImage) -_, predicted = torch.max(testOutput, 1) -predicted_class = train_set.classes[predicted.item()] -print(f'The predicted class is: {predicted_class}') \ No newline at end of file +# testOutput = model(testImage) +# _, predicted = torch.max(testOutput, 1) +# predicted_class = train_set.classes[predicted.item()] +# print(f'The predicted class is: {predicted_class}') \ No newline at end of file diff --git a/source/__pycache__/astar.cpython-311.pyc b/source/__pycache__/astar.cpython-311.pyc index 92d68bd..c791e81 100644 Binary files a/source/__pycache__/astar.cpython-311.pyc and b/source/__pycache__/astar.cpython-311.pyc differ diff --git a/source/__pycache__/bfs.cpython-311.pyc b/source/__pycache__/bfs.cpython-311.pyc index b236869..94f1cb7 100644 Binary files a/source/__pycache__/bfs.cpython-311.pyc and b/source/__pycache__/bfs.cpython-311.pyc differ diff --git a/source/__pycache__/crop_protection_product.cpython-311.pyc b/source/__pycache__/crop_protection_product.cpython-311.pyc index 997f2be..855581b 100644 Binary files a/source/__pycache__/crop_protection_product.cpython-311.pyc and b/source/__pycache__/crop_protection_product.cpython-311.pyc differ diff --git a/source/__pycache__/ground.cpython-311.pyc b/source/__pycache__/ground.cpython-311.pyc index 903dc8e..071c593 100644 Binary files a/source/__pycache__/ground.cpython-311.pyc and b/source/__pycache__/ground.cpython-311.pyc differ diff --git a/source/__pycache__/plant.cpython-311.pyc b/source/__pycache__/plant.cpython-311.pyc index 9fc979d..5c9ef66 100644 Binary files a/source/__pycache__/plant.cpython-311.pyc and b/source/__pycache__/plant.cpython-311.pyc differ diff --git a/source/__pycache__/tile.cpython-311.pyc b/source/__pycache__/tile.cpython-311.pyc index 4be75d3..1777104 100644 Binary files a/source/__pycache__/tile.cpython-311.pyc and b/source/__pycache__/tile.cpython-311.pyc differ diff --git a/source/area/__pycache__/__init__.cpython-311.pyc b/source/area/__pycache__/__init__.cpython-311.pyc index a3d75da..b4b15ec 100644 Binary files a/source/area/__pycache__/__init__.cpython-311.pyc and b/source/area/__pycache__/__init__.cpython-311.pyc differ diff --git a/source/area/__pycache__/constants.cpython-311.pyc b/source/area/__pycache__/constants.cpython-311.pyc index ae86f18..99fb7fd 100644 Binary files a/source/area/__pycache__/constants.cpython-311.pyc and b/source/area/__pycache__/constants.cpython-311.pyc differ diff --git a/source/area/__pycache__/field.cpython-311.pyc b/source/area/__pycache__/field.cpython-311.pyc index 5ce4b04..b01eaf3 100644 Binary files a/source/area/__pycache__/field.cpython-311.pyc and b/source/area/__pycache__/field.cpython-311.pyc differ diff --git a/source/area/__pycache__/tractor.cpython-311.pyc b/source/area/__pycache__/tractor.cpython-311.pyc index 9101335..eea7c32 100644 Binary files a/source/area/__pycache__/tractor.cpython-311.pyc and b/source/area/__pycache__/tractor.cpython-311.pyc differ diff --git a/source/main.py b/source/main.py index 5b4b62a..7d5461f 100644 --- a/source/main.py +++ b/source/main.py @@ -13,6 +13,7 @@ from plant import Plant from bfs import graphsearch, Istate, succ from astar import a_star from NN.neural_network import load_model, load_image, guess_image +from PIL import Image WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('Intelligent tractor') diff --git a/source/plant.py b/source/plant.py index 770ffcc..d0c1228 100644 --- a/source/plant.py +++ b/source/plant.py @@ -21,17 +21,17 @@ class Plant: def update_name(self, predicted_class): if predicted_class == "Apple": - self.name = "Apple" - self.plant_type = "fruit" + self.name = "apple" + self.plant_type = 'fruit' elif predicted_class == "Radish": - self.name = "Radish" - self.plant_type = "vegetable" + self.name = "radish" + self.plant_type = 'vegetable' elif predicted_class == "Cauliflower": - self.name = "Cauliflower" - self.plant_type = "vegetable" + self.name = "cauliflower" + self.plant_type = 'vegetable' elif predicted_class == "Wheat": - self.name = "Wheat" - self.plant_type = "cereal" \ No newline at end of file + self.name = "wheat" + self.plant_type = 'cereal' \ No newline at end of file diff --git a/source/tile.py b/source/tile.py index e0d8d4a..40ccc34 100644 --- a/source/tile.py +++ b/source/tile.py @@ -1,4 +1,5 @@ import random +import time import os import numpy as np import matplotlib.pyplot as plt @@ -54,6 +55,9 @@ class Tile: def display_photo(self): image_path = self.photo img = Image.open(image_path) + plt.ion() plt.imshow(img) plt.axis('off') plt.show() + time.sleep(5) + plt.close()