Compare commits

...

39 Commits

Author SHA1 Message Date
ad0e642964 dataset for project presentation (#35) from wozek_works_in_a_loop into master
Reviewed-on: #35
2023-06-19 12:15:44 +02:00
Woj
175055c84a dataset for project presentation 2023-06-19 12:13:57 +02:00
c918e1007b wozek works autonomously and reacts to new orders (#34) from wozek_works_in_a_loop into master
Reviewed-on: #34
2023-06-18 22:52:44 +02:00
Woj
e4d7f6e37d wozek works autonomously and reacts to new orders 2023-06-18 22:47:28 +02:00
07340db2b8 Merge pull request 'fix in code' (#33) from fix_alg_gen into master
Reviewed-on: #33
2023-06-18 21:17:13 +02:00
Zuzanna Wójcik
e496375238 fix in code 2023-06-18 21:16:29 +02:00
c8859b34f8 Merge pull request 'cleaned up code, removed unneccessary methods in wozek' (#32) from wiki into master
Reviewed-on: #32
2023-06-18 13:08:36 +02:00
f27ff12d88 cleaned up code, removed unneccessary methods in wozek 2023-06-18 13:07:05 +02:00
1a2c00c6e2 Merge pull request 'plansza jest generowana' (#31) from impl_alg_gen into master
Reviewed-on: #31
2023-06-15 18:00:16 +02:00
Zuzanna Wójcik
b5a2e4bd8b plansza jest generowana 2023-06-15 17:58:27 +02:00
ce6bd4c800 Merge pull request 'ocena, mutacja, krzyżowanie, ewolucja' (#30) from alg_gen_mutacja into master
Reviewed-on: #30
2023-06-15 17:36:34 +02:00
Zuzanna Wójcik
972480f501 ocena, mutacja, krzyżowanie, ewolucja 2023-06-15 17:34:10 +02:00
88f5a1acd0 Merge pull request 'genetic_algorithm' (#29) from genetic_algorithm into master
Reviewed-on: #29
2023-06-14 13:10:15 +02:00
Mateusz Kantorski
8cf63dc56d Add population generation 2023-06-14 13:04:08 +02:00
Mateusz Kantorski
e4bc5e2063 Add invidual generating 2023-06-14 13:02:11 +02:00
fc3296b57a Merge pull request 'implementacja sieci neuronowych' (#28) from neural_network_impl into master
Reviewed-on: #28
2023-06-05 00:47:42 +02:00
Zuzanna Wójcik
bb8f28ad40 implementacja sieci neuronowych 2023-06-05 00:45:29 +02:00
51d8327040 second program launch with better accuracy (#27) from neural_network_python into master
Reviewed-on: #27
2023-06-04 16:43:24 +02:00
Woj
255e756dd3 second program launch 2023-06-04 16:41:25 +02:00
55742839d9 neural network model generated + fixed dataset structure (#26) from neural_network_python into master
Reviewed-on: #26
2023-06-04 14:46:59 +02:00
Woj
f7cc21a386 'best_model.pth' neural network learning model + fixes 2023-06-04 14:41:33 +02:00
Woj
23d5dbd614 fixed dataset structure 2023-06-04 13:13:03 +02:00
Woj
9172aa397f learning algoritm 2023-06-04 12:38:13 +02:00
Woj
28b120769d neural network model + datasetconverter 2023-06-04 00:09:57 +02:00
9b1d9c1f13 Merge pull request 'added letters' (#25) from added_letters into master
Reviewed-on: #25
2023-06-02 21:16:59 +02:00
Zuzanna Wójcik
133e54ab12 added letters 2023-06-02 21:14:55 +02:00
aa340e68d3 Merge pull request 'Add training data - packages for neural network' (#24) from packages_data_set into master
Reviewed-on: #24
2023-05-31 16:15:44 +02:00
19c2898b4e Add training data - packages for neural network 2023-05-31 16:14:08 +02:00
fe6e9ff081 Merge pull request 'added training data - letters for neural network' (#23) from neural_network_letters into master
Reviewed-on: #23
2023-05-31 12:41:32 +02:00
48480c717e added training data - letters for neural network 2023-05-31 12:37:44 +02:00
dcda3bbfef Merge pull request 'dodana ikonka skrzynki na listy' (#22) from letter_box_icon into master
Reviewed-on: #22
2023-05-31 09:27:46 +02:00
Zuzanna Wójcik
c946313bcd dodana ikonka skrzynki na listy 2023-05-31 09:25:37 +02:00
497b01ccb3 Merge pull request 'fixed empty list bug' (#21) from fix_empty_package_list_bug into master
Reviewed-on: #21
2023-05-30 21:38:24 +02:00
Zuzanna Wójcik
57d299e767 fixed empty list bug 2023-05-30 21:36:48 +02:00
40ad5222a1 Merge pull request 'poprawione generowanie planszy' (#20) from fix_generowanie_planszy1 into master
Reviewed-on: #20
2023-05-30 21:04:28 +02:00
Zuzanna Wójcik
d3d2fcfb0b poprawione generowanie planszy 2023-05-30 21:00:08 +02:00
bdea00c5b2 Read tree from file 2023-05-30 19:09:24 +02:00
3f65be482c Merge pull request 'drzewo_wiki' (#19) from drzewo_wiki into master
Reviewed-on: #19
2023-05-30 18:48:46 +02:00
4670845a00 Merge pull request 'drzewo_wiki' (#18) from drzewo_wiki into master
Reviewed-on: #18
2023-05-29 13:28:33 +02:00
2040 changed files with 696 additions and 297 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,31 @@
Epoch: 1 Train Loss: 65 Train Accuracy: 0.5754245754245755
Epoch: 2 Train Loss: 25 Train Accuracy: 0.7457542457542458
Epoch: 3 Train Loss: 8 Train Accuracy: 0.8431568431568431
Epoch: 4 Train Loss: 2 Train Accuracy: 0.9010989010989011
Epoch: 5 Train Loss: 1 Train Accuracy: 0.9335664335664335
Epoch: 6 Train Loss: 0 Train Accuracy: 0.9545454545454546
Epoch: 7 Train Loss: 0 Train Accuracy: 0.972027972027972
Epoch: 8 Train Loss: 0 Train Accuracy: 0.9820179820179821
Epoch: 9 Train Loss: 0 Train Accuracy: 0.994005994005994
Epoch: 10 Train Loss: 0 Train Accuracy: 0.9945054945054945
Epoch: 1 Train Loss: 42 Train Accuracy: 0.6428571428571429
Epoch: 2 Train Loss: 11 Train Accuracy: 0.8306693306693307
Epoch: 3 Train Loss: 3 Train Accuracy: 0.8921078921078921
Epoch: 4 Train Loss: 2 Train Accuracy: 0.8891108891108891
Epoch: 5 Train Loss: 1 Train Accuracy: 0.9335664335664335
Epoch: 6 Train Loss: 0 Train Accuracy: 0.952047952047952
Epoch: 7 Train Loss: 0 Train Accuracy: 0.9545454545454546
Epoch: 8 Train Loss: 0 Train Accuracy: 0.9655344655344655
Epoch: 9 Train Loss: 0 Train Accuracy: 0.9815184815184815
Epoch: 10 Train Loss: 0 Train Accuracy: 0.9805194805194806
Epoch: 11 Train Loss: 0 Train Accuracy: 0.9855144855144855
Epoch: 12 Train Loss: 0 Train Accuracy: 0.989010989010989
Epoch: 13 Train Loss: 0 Train Accuracy: 0.9925074925074925
Epoch: 14 Train Loss: 0 Train Accuracy: 0.9915084915084915
Epoch: 15 Train Loss: 0 Train Accuracy: 0.9885114885114885
Epoch: 16 Train Loss: 0 Train Accuracy: 0.994005994005994
Epoch: 17 Train Loss: 0 Train Accuracy: 0.997002997002997
Epoch: 18 Train Loss: 0 Train Accuracy: 0.9965034965034965
Epoch: 19 Train Loss: 0 Train Accuracy: 0.999000999000999
Epoch: 20 Train Loss: 0 Train Accuracy: 1.0

View File

@ -0,0 +1,60 @@
import glob
from src.torchvision_resize_dataset import combined_dataset, images_path, classes
import src.data_model
from torch.optim import Adam
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
train_loader = DataLoader(
combined_dataset, #dataset of images
batch_size=256, # accuracy
shuffle=True # rand order
)
model = src.data_model.DataModel(num_objects=2).to(device)
#optimizer
optimizer = Adam(model.parameters(), lr=0.001, weight_decay=0.0001)
#loss function
criterion = nn.CrossEntropyLoss()
num_epochs = 20
# train_size = len(glob.glob(images_path+'*.jpg'))
train_size = 2002
go_to_accuracy = 0.0
for epoch in range(num_epochs):
#training on dataset
model.train()
train_accuracy = 0.0
train_loss = 0.0
for i, (images, labels) in enumerate(train_loader):
if torch.cuda.is_available():
images = torch.Variable(images.cuda())
labels = torch.Variable(labels.cuda())
# clearing the optimizer gradients
optimizer.zero_grad()
outputs = model(images) # predoction
loss = criterion(outputs, labels) #loss calculation
loss.backward()
optimizer.step()
train_loss += loss.cpu().data*images.size(0)
_, prediction = torch.max(outputs.data, 1)
train_accuracy += int(torch.sum(prediction == labels.data))
train_accuracy = train_accuracy/train_size
train_loss = train_loss/train_size
model.eval()
print('Epoch: '+ str(epoch+1) +' Train Loss: '+ str(int(train_loss)) +' Train Accuracy: '+ str(train_accuracy))
if train_accuracy > go_to_accuracy:
go_to_accuracy= train_accuracy
torch.save(model.state_dict(), "best_model.pth")

Binary file not shown.

147
NeuralNetwork/prediction.py Normal file
View File

@ -0,0 +1,147 @@
import torch
import torch.nn as nn
from torchvision.transforms import transforms
import numpy as np
from torch.autograd import Variable
from torchvision.models import squeezenet1_1
import torch.functional as F
from io import open
import os
from PIL import Image
import pathlib
import glob
from tkinter import Tk, Label
from PIL import Image, ImageTk
absolute_path = os.path.abspath('NeuralNetwork/src/train_images')
train_path = absolute_path
absolute_path = os.path.abspath('Images/Items_test')
pred_path = absolute_path
root=pathlib.Path(train_path)
classes=sorted([j.name.split('/')[-1] for j in root.iterdir()])
class DataModel(nn.Module):
def __init__(self, num_classes):
super(DataModel, self).__init__()
#input (batch=256, nr of channels rgb=3 , size=244x244)
# convolution
self.conv1 = nn.Conv2d(in_channels=3, out_channels=12, kernel_size=3, stride=1, padding=1)
#shape (256, 12, 224x224)
# batch normalization
self.bn1 = nn.BatchNorm2d(num_features=12)
#shape (256, 12, 224x224)
self.reul1 = nn.ReLU()
self.pool=nn.MaxPool2d(kernel_size=2, stride=2)
# reduce image size by factor 2
# pooling window moves by 2 pixels at a time instead of 1
# shape (256, 12, 112x112)
self.conv2 = nn.Conv2d(in_channels=12, out_channels=24, kernel_size=3, stride=1, padding=1)
self.bn2 = nn.BatchNorm2d(num_features=24)
self.reul2 = nn.ReLU()
# shape (256, 24, 112x112)
self.conv3 = nn.Conv2d(in_channels=24, out_channels=48, kernel_size=3, stride=1, padding=1)
#shape (256, 48, 112x112)
self.bn3 = nn.BatchNorm2d(num_features=48)
#shape (256, 48, 112x112)
self.reul3 = nn.ReLU()
# connected layer
self.fc = nn.Linear(in_features=48*112*112, out_features=num_classes)
def forward(self, input):
output = self.conv1(input)
output = self.bn1(output)
output = self.reul1(output)
output = self.pool(output)
output = self.conv2(output)
output = self.bn2(output)
output = self.reul2(output)
output = self.conv3(output)
output = self.bn3(output)
output = self.reul3(output)
# output shape matrix (256, 48, 112x112)
#print(output.shape)
#print(self.fc.weight.shape)
output = output.view(-1, 48*112*112)
output = self.fc(output)
return output
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'best_model.pth')
checkpoint=torch.load(file_path)
model = DataModel(num_classes=2)
model.load_state_dict(checkpoint)
model.eval()
transformer = transforms.Compose([
transforms.Resize((224, 224)), # Resize images to (224, 224)
transforms.ToTensor(), # Convert images to tensors, 0-255 to 0-1
# transforms.RandomHorizontalFlip(), # 0.5 chance to flip the image
transforms.Normalize([0.5,0.5,0.5], [0.5,0.5,0.5])
])
def prediction(img_path,transformer):
image=Image.open(img_path)
image_tensor=transformer(image).float()
image_tensor=image_tensor.unsqueeze_(0)
if torch.cuda.is_available():
image_tensor.cuda()
input=Variable(image_tensor)
output=model(input)
index=output.data.numpy().argmax()
pred=classes[index]
return pred
def prediction_keys():
#funkcja zwracajaca sciezki do kazdego pliku w folderze w postaci listy
images_path=glob.glob(pred_path+'/*.jpg')
pred_list=[]
for i in images_path:
pred_list.append(i)
return pred_list
def predict_one(path):
#wyswietlanie obrazka po kazdym podniesieniu itemu
root = Tk()
root.title("Okno z obrazkiem")
image = Image.open(path)
photo = ImageTk.PhotoImage(image)
label = Label(root, image=photo)
label.pack()
root.mainloop()
#uruchamia sie funkcja spr czy obrazek to paczka czy list
pred_print = prediction(path,transformer)
print('Zdjecie jest: '+pred_print)
return pred_print

View File

@ -0,0 +1,61 @@
import torch.nn as nn
import torch
class DataModel(nn.Module):
def __init__(self, num_objects):
super(DataModel, self).__init__()
#input (batch=256, nr of channels rgb=3 , size=244x244)
# convolution
self.conv1 = nn.Conv2d(in_channels=3, out_channels=12, kernel_size=3, stride=1, padding=1)
#shape (256, 12, 224x224)
# batch normalization
self.bn1 = nn.BatchNorm2d(num_features=12)
#shape (256, 12, 224x224)
self.reul1 = nn.ReLU()
self.pool=nn.MaxPool2d(kernel_size=2, stride=2)
# reduce image size by factor 2
# pooling window moves by 2 pixels at a time instead of 1
# shape (256, 12, 112x112)
self.conv2 = nn.Conv2d(in_channels=12, out_channels=24, kernel_size=3, stride=1, padding=1)
self.bn2 = nn.BatchNorm2d(num_features=24)
self.reul2 = nn.ReLU()
# shape (256, 24, 112x112)
self.conv3 = nn.Conv2d(in_channels=24, out_channels=48, kernel_size=3, stride=1, padding=1)
#shape (256, 48, 112x112)
self.bn3 = nn.BatchNorm2d(num_features=48)
#shape (256, 48, 112x112)
self.reul3 = nn.ReLU()
# connected layer
self.fc = nn.Linear(in_features=48*112*112, out_features=num_objects)
def forward(self, input):
output = self.conv1(input)
output = self.bn1(output)
output = self.reul1(output)
output = self.pool(output)
output = self.conv2(output)
output = self.bn2(output)
output = self.reul2(output)
output = self.conv3(output)
output = self.bn3(output)
output = self.reul3(output)
# output shape matrix (256, 48, 112x112)
#print(output.shape)
#print(self.fc.weight.shape)
output = output.view(-1, 48*112*112)
output = self.fc(output)
return output

View File

@ -0,0 +1,31 @@
import glob
import pathlib
import torchvision.transforms as transforms
from torchvision.datasets import ImageFolder
from torch.utils.data import ConcatDataset
# images have to be the same size for the algorithm to work
transform = transforms.Compose([
transforms.Resize((224, 224)), # Resize images to (224, 224)
transforms.ToTensor(), # Convert images to tensors, 0-255 to 0-1
# transforms.RandomHorizontalFlip(), # 0.5 chance to flip the image
transforms.Normalize([0.5,0.5,0.5], [0.5,0.5,0.5])
])
letters_path = 'C:/Users/wojmed/Documents/VS repositories/Inteligentny_Wozek/NeuralNetwork/src/train_images/letters'
package_path = 'C:/Users/wojmed/Documents/VS repositories/Inteligentny_Wozek/NeuralNetwork/src/train_images/package'
images_path = 'C:/Users/wojmed/Documents/VS repositories/Inteligentny_Wozek/NeuralNetwork/src/train_images'
# # Load images from folders
# letter_folder = ImageFolder(letters_path, transform=transform)
# package_folder = ImageFolder(package_path, transform=transform)
# Combine the both datasets into a single dataset
#combined_dataset = ConcatDataset([letter_folder, package_folder])
combined_dataset = ImageFolder(images_path, transform=transform)
#image classes
path=pathlib.Path(images_path)
classes = sorted([i.name.split("/")[-1] for i in path.iterdir()])
# print(classes)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1004 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

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