działający

This commit is contained in:
Tomasz Adamczyk 2021-06-01 02:00:55 +02:00
parent a43f35d179
commit 66c1bcd563
5648 changed files with 86 additions and 86 deletions

0
.gitignore vendored Normal file
View File

View File

@ -3,13 +3,9 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment=""> <list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/astar.py" beforeDir="false" afterPath="$PROJECT_DIR$/astar.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cart.py" beforeDir="false" afterPath="$PROJECT_DIR$/cart.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/neuralnetwork.py" beforeDir="false" afterPath="$PROJECT_DIR$/neuralnetwork.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/neuralnetwork.py" beforeDir="false" afterPath="$PROJECT_DIR$/neuralnetwork.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/treelearn.py" beforeDir="false" afterPath="$PROJECT_DIR$/treelearn.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -161,6 +157,13 @@
<workItem from="1622471028909" duration="34000" /> <workItem from="1622471028909" duration="34000" />
<workItem from="1622471098158" duration="2320000" /> <workItem from="1622471098158" duration="2320000" />
<workItem from="1622474297862" duration="2475000" /> <workItem from="1622474297862" duration="2475000" />
<workItem from="1622482225447" duration="322000" />
<workItem from="1622483723661" duration="2000" />
<workItem from="1622484196227" duration="4095000" />
<workItem from="1622490223156" duration="88000" />
<workItem from="1622490315073" duration="1038000" />
<workItem from="1622491366806" duration="5374000" />
<workItem from="1622499624637" duration="5901000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -168,65 +171,69 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="414" y="195" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1622365181713"> <state x="414" y="195" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1622503192333">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="414" y="195" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622365181713" /> <state x="414" y="195" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622503192333" />
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1622475063488"> <state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1622475063488">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622475063488" /> <state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622475063488" />
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1621109431051" /> <state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1621109431051" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1622413487618"> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1622503875969">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622413487618" /> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622503875969" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621429221570" /> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621429221570" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1622477545943"> <state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1622505570694">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" /> <state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622505570694" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1622477545943"> <state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1622505570694">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" /> <state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622505570694" />
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1622477545943"> <state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1622505570694">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" /> <state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622505570694" />
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389326" /> <state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389326" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1622477545943"> <state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1622505570694">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" /> <state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622505570694" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1619289752045"> <state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1622496797346">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622496797346" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" /> <state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1619289752045"> <state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1622496797346">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622496797346" />
<state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" /> <state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1619289752045"> <state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1622496797346">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622496797346" />
<state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" /> <state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1619289752045"> <state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1622496797346">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622496797346" />
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" /> <state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1622474297784"> <state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1622499624475">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622474297784" /> <state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622499624475" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621439087317" /> <state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621439087317" />
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1622475419309"> <state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1622494466933">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622475419309" /> <state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622494466933" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -240,7 +247,9 @@
</breakpoint-manager> </breakpoint-manager>
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartCart$copy.coverage" NAME="copy Coverage Results" MODIFIED="1622503170538" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$glue.coverage" NAME="glue Coverage Results" MODIFIED="1622501306368" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1622469837941" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1622469837941" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1622475876802" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1622505478603" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component> </component>
</project> </project>

Binary file not shown.

View File

@ -4,12 +4,12 @@ from torch.optim import Adam
from torch.utils.data import DataLoader from torch.utils.data import DataLoader
from torchvision.transforms import transforms from torchvision.transforms import transforms
import glob import glob
import numpy as np
import os import os
import pathlib import pathlib
import torch import torch
import torch.nn as nn import torch.nn as nn
import torchvision import torchvision
transformer1 = transforms.Compose([transforms.Resize((150, 150)), transforms.ToTensor(), transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])
class ConvNet(nn.Module): class ConvNet(nn.Module):
def __init__(self, num_classes=6): def __init__(self, num_classes=6):
super(ConvNet, self).__init__() super(ConvNet, self).__init__()
@ -36,34 +36,27 @@ class ConvNet(nn.Module):
output = output.view(-1, 32 * 75 * 75) output = output.view(-1, 32 * 75 * 75)
output = self.fc(output) output = self.fc(output)
return output return output
def create_neural_network(): def create_neural_network(): #tworzenie sieci neuronowej
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') #użyj cuda jeśli możliwe
transformer = transforms.Compose([transforms.Resize((150, 150)), transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])]) transformer = transforms.Compose([transforms.Resize((150, 150)), transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])
train_path = os.path.join('resources/neural_network/train/') train_path = os.path.join('resources/neural_network/train/') #ścieżka do obrazków do treningu
test_path = os.path.join('resources/neural_network/test/') test_path = os.path.join('resources/neural_network/test/') #ścieżka do obrazków do testu
pred_path = os.path.join('resources/neural_network/pred/')
train_loader = DataLoader(torchvision.datasets.ImageFolder(train_path, transform=transformer), batch_size=64, shuffle=True) train_loader = DataLoader(torchvision.datasets.ImageFolder(train_path, transform=transformer), batch_size=64, shuffle=True)
test_loader = DataLoader(torchvision.datasets.ImageFolder(test_path, transform=transformer), batch_size=32, shuffle=True) test_loader = DataLoader(torchvision.datasets.ImageFolder(test_path, transform=transformer), batch_size=32, shuffle=True)
root = pathlib.Path(train_path) root = pathlib.Path(train_path)
classes = sorted([j.name.split('/')[-1] for j in root.iterdir()]) classes = sorted([j.name.split('/')[-1] for j in root.iterdir()])
if os.path.exists("resources/neural_network/checkpoint.model"): if os.path.exists("resources/neural_network/checkpoint.model"): #jeżeli istnieje model to wczytaj
checkpoint = torch.load(os.path.join('resources/neural_network', 'checkpoint.model')) checkpoint = torch.load(os.path.join('resources/neural_network', 'checkpoint.model'))
model = ConvNet(num_classes=6) model = ConvNet(num_classes=6)
model.load_state_dict(checkpoint) model.load_state_dict(checkpoint)
model.eval() model.eval()
transformer1 = transforms.Compose([transforms.Resize((150, 150)), transforms.ToTensor(), transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])]) else: #w przeciwnym razie utwórz nowy model
images_path = glob.glob(pred_path+'/*.jpg')
pred_dict = {}
for i in images_path:
pred_dict[i[i.rfind('/') + 1:]] = prediction1(classes, i, model, transformer1)
print(pred_dict)
else:
model = ConvNet(num_classes=6).to(device) model = ConvNet(num_classes=6).to(device)
optimizer = Adam(model.parameters(), lr=0.001, weight_decay=0.0001) optimizer = Adam(model.parameters(), lr=0.001, weight_decay=0.0001)
loss_function = nn.CrossEntropyLoss() loss_function = nn.CrossEntropyLoss()
num_epochs = 10 num_epochs = 10
train_count = len(glob.glob(train_path + '/**/*.jpg')) train_count = len(glob.glob(train_path + '/**/*.png')) #liczba obrazków treningowych
test_count = len(glob.glob(test_path + '/**/*.jpg')) test_count = len(glob.glob(test_path + '/**/*.png')) #liczba obrazków testowych
best_accuracy = 0.0 best_accuracy = 0.0
for epoch in range(num_epochs): for epoch in range(num_epochs):
model.train() model.train()
@ -97,8 +90,39 @@ def create_neural_network():
if test_accuracy > best_accuracy: if test_accuracy > best_accuracy:
torch.save(model.state_dict(), 'resources/neural_network/checkpoint.model') torch.save(model.state_dict(), 'resources/neural_network/checkpoint.model')
best_accuracy = test_accuracy best_accuracy = test_accuracy
def prediction1(classes, img_path, model, transformer): checkpoint = torch.load(os.path.join('resources/neural_network', 'checkpoint.model'))
image = Image.open(img_path) model = ConvNet(num_classes=6)
model.load_state_dict(checkpoint)
model.eval()
return classes, model
def predfield(classes, model): #zwraca miejsce pola z wyrośniętą rośliną na podstawie wykrywania obrazu
pred_path = os.path.join('resources/neural_network/sliced/') #ścieżka do obrazków do sprawdzenia
pred_dict = {}
images_path = glob.glob(pred_path + '/*.png')
x = None #x'owa pola
y = None#y'kowa pola
for i in images_path: #dodajemy pocięte obrazki do listy i ustawiamy im przewidywaną metkę
pred_dict[i[i.rfind('/') + 1:]] = prediction1(classes, i, model, transformer1)
for img_name, field in pred_dict.items():
if field != "random": #jeżeli metka nie jest 'random' to przypisz do x'a i y'a miejsce wyrośniętej rośliny
x = img_name[15]
y = img_name[18]
x = int(x)
y = int(y)
if x == 0:
x = 9
else:
x = x - 1
if y == 0:
y = 9
else:
y = y - 1
if x == None and y == None: #jeżeli nie ma wyrośniętej rośliny to zwróć False
return False
else:
return y, x
def prediction1(classes, img_path, model, transformer): #zwraca predykcję dla danego obrazka
image = Image.open(img_path).convert('RGB')
image_tensor = transformer(image).float() image_tensor = transformer(image).float()
image_tensor = image_tensor.unsqueeze_(0) image_tensor = image_tensor.unsqueeze_(0)
if torch.cuda.is_available(): if torch.cuda.is_available():

View File

@ -12,30 +12,6 @@ class Plant:
def set_state(self, state): def set_state(self, state):
self.state = state self.state = state
@staticmethod @staticmethod
def get_mature_plant(map): #pobiera współrzędne jakiejś dojrzałej rośliny
x = -1
y = -1
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
x = i
y = j
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
x = i
y = j
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
x = i
y = j
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
x = i
y = j
if x == -1 and y == -1:
return False
else:
return x, y
@staticmethod
def grow_plants(map): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1 def grow_plants(map): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
for i in range(definitions.WIDTH_AMOUNT): for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT):
@ -47,18 +23,4 @@ class Plant:
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE: elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1) field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE: elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1) field.get_plant().set_state(field.get_plant().get_state() + 1)
@staticmethod
def if_any_mature_plant(map): #sprawdza czy na polu występuje choć jedna dojrzała roślina, jeśli tak zwraca prawdę, w przeciwnym razie zwraca fałsz
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
return True
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
return True
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
return True
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
return True
return False

13
py.py
View File

@ -2,8 +2,10 @@ import astar
import cart import cart
import definitions import definitions
import graph import graph
import image_slicer
import map import map
import neuralnetwork import neuralnetwork
import os
import plant import plant
import pygame import pygame
import station import station
@ -23,7 +25,7 @@ def main():
clock = pygame.time.Clock() clock = pygame.time.Clock()
tree = treelearn.treelearn() #tworzenie drzewa decyzyjnego tree = treelearn.treelearn() #tworzenie drzewa decyzyjnego
decision = [0] #początkowa decyzja o braku powrotu do stacji (0) decision = [0] #początkowa decyzja o braku powrotu do stacji (0)
#neuralnetwork.create_neural_network() classes, model = neuralnetwork.create_neural_network() #uczenie sieci neuronowej
run = True run = True
while run: #pętla główna programu while run: #pętla główna programu
clock.tick(definitions.FPS) clock.tick(definitions.FPS)
@ -31,10 +33,13 @@ def main():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
run = False run = False
map1.draw_window(cart1, cart1_rect) map1.draw_window(cart1, cart1_rect)
if not move_list and plant.Plant.if_any_mature_plant(map1) is True: #jeżeli są jakieś ruchy do wykonania w move_list oraz istnieje jakaś dojrzała roślina pygame.image.save(pygame.display.get_surface(), os.path.join('resources/neural_network/sliced/', 'screen.jpg')) #zrzut obecnego ekranu
istate = graph.Istate(cart1.get_direction(), cart1.get_x() / definitions.BLOCK_SIZE, cart1.get_y() / definitions.BLOCK_SIZE) #stan początkowy wózka (jego orientacja oraz jego aktualne współrzędne) image_slicer.slice(os.path.join('resources/neural_network/sliced/', 'screen.jpg'), 100) #pocięcie ekranu na sto części
os.remove('resources/neural_network/sliced/screen.jpg')
if not move_list and neuralnetwork.predfield(classes, model) is not False: #jeżeli są jakieś ruchy do wykonania w move_list oraz istnieje jakaś dojrzała roślina
istate = graph.Istate(cart1.get_direction(), cart1.get_x() / definitions.BLOCK_SIZE, cart1.get_y() / definitions.BLOCK_SIZE) #stan początkowy wózka (jego orientacja oraz jego aktualne miejsce)
if decision == [0]: #jeżeli decyzja jest 0 (brak powrotu do stacji) to uprawiaj pole if decision == [0]: #jeżeli decyzja jest 0 (brak powrotu do stacji) to uprawiaj pole
move_list = (astar.graphsearch([], astar.f, [], plant.Plant.get_mature_plant(map1), istate, map1, graph.succ)) #lista z ruchami, które należy po kolei wykonać, astar move_list = (astar.graphsearch([], astar.f, [], neuralnetwork.predfield(classes, model), istate, map1, graph.succ)) #lista z ruchami, które należy po kolei wykonać, astar
else: #jeżeli decyzja jest 1 (powrót do stacji) to wróć do stacji uzupełnić zapasy else: #jeżeli decyzja jest 1 (powrót do stacji) to wróć do stacji uzupełnić zapasy
move_list = (graph.graphsearch([], [], (0, 0), istate, graph.succ)) #lista z ruchami, które należy po kolei wykonać, graphsearch move_list = (graph.graphsearch([], [], (0, 0), istate, graph.succ)) #lista z ruchami, które należy po kolei wykonać, graphsearch
elif move_list: #jeżeli move_list nie jest pusta elif move_list: #jeżeli move_list nie jest pusta

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Some files were not shown because too many files have changed in this diff Show More