neural_network #25
12
Image.py
12
Image.py
@ -56,14 +56,24 @@ class Image:
|
|||||||
def return_gasStation(self):
|
def return_gasStation(self):
|
||||||
return self.gasStation_image
|
return self.gasStation_image
|
||||||
|
|
||||||
|
# losowanie zdjęcia z testowego datasetu bez powtórzeń
|
||||||
|
imagePathList = []
|
||||||
def getRandomImageFromDataBase():
|
def getRandomImageFromDataBase():
|
||||||
label = random.choice(neuralnetwork.labels)
|
label = random.choice(neuralnetwork.labels)
|
||||||
|
|
||||||
folderPath = f"dataset/test/{label}"
|
folderPath = f"dataset/test/{label}"
|
||||||
files = os.listdir(folderPath)
|
files = os.listdir(folderPath)
|
||||||
random_image = random.choice(files)
|
random_image = random.choice(files)
|
||||||
imgPath = os.path.join(folderPath, random_image)
|
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.image.load(imgPath)
|
||||||
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||||
return image, label, imgPath
|
return image, label, imgPath
|
||||||
|
@ -198,7 +198,7 @@ class Tractor:
|
|||||||
for j in range(initPos[0], dCon.NUM_X):
|
for j in range(initPos[0], dCon.NUM_X):
|
||||||
if self.slot.imagePath != None:
|
if self.slot.imagePath != None:
|
||||||
predictedLabel = nn.predictLabel(self.slot.imagePath, model)
|
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)
|
self.move_forward(pole, False)
|
||||||
if i % 2 == 0 and i != dCon.NUM_Y - 1:
|
if i % 2 == 0 and i != dCon.NUM_Y - 1:
|
||||||
self.turn_right()
|
self.turn_right()
|
||||||
|
@ -9,8 +9,8 @@ from PIL import Image
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
imageSize = (128, 128)
|
imageSize = (128, 128)
|
||||||
labels = ['beetroot', 'potato', 'carrot']
|
labels = ['beetroot', 'carrot', 'potato'] # musi być w kolejności alfabetycznej
|
||||||
labels.sort()
|
fertilizer = {labels[0]: 'kompost', labels[1]: 'saletra amonowa', labels[2]: 'superfosfat'}
|
||||||
|
|
||||||
torch.manual_seed(42)
|
torch.manual_seed(42)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user