Compare commits
3 Commits
9667655a2a
...
df7c553c59
Author | SHA1 | Date | |
---|---|---|---|
|
df7c553c59 | ||
|
8ddba0c828 | ||
|
35d7a6ab6e |
BIN
source/CNN_model.pth
Normal file
@ -10,19 +10,15 @@ class Conv_Neural_Network_Model(nn.Module):
|
||||
self.conv1 = nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, stride=1, padding=1)
|
||||
self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
|
||||
self.conv2 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1, padding=1)
|
||||
self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
|
||||
self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1)
|
||||
self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
|
||||
|
||||
self.fc1 = nn.Linear(128*12*12,hidden_layer1)
|
||||
self.fc1 = nn.Linear(64*25*25,hidden_layer1)
|
||||
self.fc2 = nn.Linear(hidden_layer1,hidden_layer2)
|
||||
self.out = nn.Linear(hidden_layer2,num_classes)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.pool1(F.relu(self.conv1(x)))
|
||||
x = self.pool2(F.relu(self.conv2(x)))
|
||||
x = self.pool3(F.relu(self.conv3(x)))
|
||||
x = x.view(-1, 128*12*12) #<----flattening the image
|
||||
x = self.pool1(F.relu(self.conv2(x)))
|
||||
x = x.view(-1, 64*25*25) #<----flattening the image
|
||||
x = self.fc1(x)
|
||||
x = torch.relu(x)
|
||||
x = self.fc2(x)
|
||||
|
@ -29,7 +29,7 @@ test_set = datasets.ImageFolder(root='resources/test', transform=data_transforme
|
||||
|
||||
#function for training model
|
||||
def train(model, dataset, iter=100, batch_size=64):
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=0.001)
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
|
||||
criterion = nn.NLLLoss()
|
||||
train_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True)
|
||||
model.train()
|
||||
@ -60,13 +60,13 @@ model = Conv_Neural_Network_Model()
|
||||
model.to(device)
|
||||
|
||||
#loading the already saved model:
|
||||
# model.load_state_dict(torch.load('model.pth'))
|
||||
# model.eval()
|
||||
model.load_state_dict(torch.load('CNN_model.pth'))
|
||||
model.eval()
|
||||
|
||||
#training the model:
|
||||
# #training the model:
|
||||
# train(model, train_set)
|
||||
# print(f"Accuracy of the network is: {100*accuracy(model, test_set)}%")
|
||||
# torch.save(model.state_dict(), 'model.pth')
|
||||
# torch.save(model.state_dict(), 'CNN_model.pth')
|
||||
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ 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/pexels-justus-menke-3490295-5213970.jpg'
|
||||
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)
|
||||
|
@ -62,15 +62,35 @@ def main():
|
||||
while run:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
#small test of work_on_field method:
|
||||
run = False
|
||||
time.sleep(1)
|
||||
tile1 = tiles[0]
|
||||
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
|
||||
|
||||
# movement based on route-planning (test):
|
||||
|
||||
tractor.draw_tractor(WIN)
|
||||
time.sleep(1)
|
||||
if moves != False:
|
||||
do_actions(tractor, WIN, moves)
|
||||
|
||||
|
||||
#guessing the image under the tile:
|
||||
goalTile = tiles[tile_index]
|
||||
goalTile.display_photo()
|
||||
image_path = goalTile.photo
|
||||
image_tensor = load_image(image_path)
|
||||
prediction = guess_image(load_model(), image_tensor)
|
||||
print(f"The predicted image is: {prediction}")
|
||||
|
||||
|
||||
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
|
||||
goalTile.plant = p1
|
||||
d1 = Dirt(random.randint(1, 100), random.randint(1,100))
|
||||
d1.pests_and_weeds()
|
||||
tile1.ground=d1
|
||||
goalTile.ground=d1
|
||||
#getting the name and type of the recognized plant:
|
||||
p1.update_name(prediction)
|
||||
|
||||
#decission tree test:
|
||||
if d1.pest:
|
||||
pe = 1
|
||||
else:
|
||||
@ -117,25 +137,12 @@ def main():
|
||||
|
||||
model = joblib.load('model.pkl')
|
||||
nowe_dane = pd.read_csv('model_data.csv')
|
||||
|
||||
predykcje = model.predict(nowe_dane)
|
||||
|
||||
# movement based on route-planning (test):
|
||||
|
||||
tractor.draw_tractor(WIN)
|
||||
time.sleep(1)
|
||||
if moves != False:
|
||||
do_actions(tractor, WIN, moves)
|
||||
print(predykcje)
|
||||
if predykcje == 'work':
|
||||
tractor.work_on_field(tile1, d1, p1)
|
||||
|
||||
#guessing the image under the tile:
|
||||
tiles[tile_index].display_photo()
|
||||
image_path = tiles[tile_index].photo
|
||||
image_tensor = load_image(image_path)
|
||||
prediction = guess_image(load_model(), image_tensor)
|
||||
print(f"The predicted image is: {prediction}")
|
||||
#work on field:
|
||||
if predykcje == 'work':
|
||||
tractor.work_on_field(goalTile, d1, p1)
|
||||
time.sleep(30)
|
||||
print("\n")
|
||||
|
||||
|
BIN
source/model.pth
@ -19,7 +19,19 @@ class Plant:
|
||||
else:
|
||||
print("Unable to grow due to bad condition of the ground")
|
||||
|
||||
# more properties
|
||||
def update_name(self, predicted_class):
|
||||
if predicted_class == "Apple":
|
||||
self.name = "Apple"
|
||||
self.plant_type = "fruit"
|
||||
|
||||
elif predicted_class == "Radish":
|
||||
self.name = "Radish"
|
||||
self.plant_type = "vegetable"
|
||||
|
||||
# add init, getters,setters
|
||||
elif predicted_class == "Cauliflower":
|
||||
self.name = "Cauliflower"
|
||||
self.plant_type = "vegetable"
|
||||
|
||||
elif predicted_class == "Wheat":
|
||||
self.name = "Wheat"
|
||||
self.plant_type = "cereal"
|
BIN
source/resources/images/plant_photos/0000000004079.webp
Normal file
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 190 KiB |
After Width: | Height: | Size: 245 KiB |
After Width: | Height: | Size: 281 KiB |
After Width: | Height: | Size: 234 KiB |
After Width: | Height: | Size: 190 KiB |
After Width: | Height: | Size: 266 KiB |
BIN
source/resources/images/plant_photos/5243790-apples-c-rex.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
source/resources/images/plant_photos/91FfdTLrL7L.jpg
Normal file
After Width: | Height: | Size: 542 KiB |
After Width: | Height: | Size: 64 KiB |
BIN
source/resources/images/plant_photos/apple.jpeg
Normal file
After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 743 KiB |
After Width: | Height: | Size: 93 KiB |
BIN
source/resources/images/plant_photos/ccc.jpeg
Normal file
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 37 KiB |
BIN
source/resources/images/plant_photos/honeycrisp2_5184x.webp
Normal file
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 130 KiB |
BIN
source/resources/images/plant_photos/images.jpeg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
source/resources/images/plant_photos/imawes.jpeg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
source/resources/images/plant_photos/imewges.jpeg
Normal file
After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 341 KiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 888 KiB |
BIN
source/resources/images/plant_photos/pexels-photo-12801993.jpeg
Normal file
After Width: | Height: | Size: 197 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 305 KiB |
BIN
source/resources/images/plant_photos/radd.jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
source/resources/images/plant_photos/s-l1200.webp
Normal file
After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 17 KiB |