diff --git a/Image.py b/Image.py index a2adfe5..b4fb11b 100644 --- a/Image.py +++ b/Image.py @@ -55,15 +55,25 @@ class Image: def return_gasStation(self): return self.gasStation_image - + +# losowanie zdjęcia z testowego datasetu bez powtórzeń +imagePathList = [] def getRandomImageFromDataBase(): label = random.choice(neuralnetwork.labels) - folderPath = f"dataset/test/{label}" files = os.listdir(folderPath) random_image = random.choice(files) imgPath = os.path.join(folderPath, random_image) + while imgPath in imagePathList: + label = random.choice(neuralnetwork.labels) + folderPath = f"dataset/test/{label}" + files = os.listdir(folderPath) + random_image = random.choice(files) + imgPath = os.path.join(folderPath, random_image) + + imagePathList.append(imgPath) + image = pygame.image.load(imgPath) image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE)) return image, label, imgPath diff --git a/Tractor.py b/Tractor.py index 4a5d10e..1312092 100644 --- a/Tractor.py +++ b/Tractor.py @@ -198,7 +198,7 @@ class Tractor: for j in range(initPos[0], dCon.NUM_X): if self.slot.imagePath != None: predictedLabel = nn.predictLabel(self.slot.imagePath, model) - print(str("Coords: ({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis), "real: ", self.slot.label, "predicted: ", predictedLabel, "correct" if (self.slot.label == predictedLabel) else "incorrect") + print(str("Coords: ({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis), "real:", self.slot.label, "predicted:", predictedLabel, "correct" if (self.slot.label == predictedLabel) else "incorrect", 'nawożę za pomocą:', nn.fertilizer[predictedLabel]) self.move_forward(pole, False) if i % 2 == 0 and i != dCon.NUM_Y - 1: self.turn_right() diff --git a/neuralnetwork.py b/neuralnetwork.py index aa21ffa..5e424e0 100644 --- a/neuralnetwork.py +++ b/neuralnetwork.py @@ -9,8 +9,8 @@ from PIL import Image import random imageSize = (128, 128) -labels = ['beetroot', 'potato', 'carrot'] -labels.sort() +labels = ['beetroot', 'carrot', 'potato'] # musi być w kolejności alfabetycznej +fertilizer = {labels[0]: 'kompost', labels[1]: 'saletra amonowa', labels[2]: 'superfosfat'} torch.manual_seed(42)