diff --git a/NeuralNetwork/prediction.py b/NeuralNetwork/prediction.py index 94c2c6b..5f810cb 100644 --- a/NeuralNetwork/prediction.py +++ b/NeuralNetwork/prediction.py @@ -12,7 +12,7 @@ def getPrediction(img_path, network_name): img = Image.open(img_path) transform_tensor = transforms.ToTensor()(img).unsqueeze_(0) classes = ['glass', 'metal', 'paper', 'plastic'] - neural_net.load_state_dict(torch.load(PATH + network_name)) + neural_net.load_state_dict(torch.load(PATH + network_name, map_location='cpu')) neural_net.eval() outputs = neural_net(transform_tensor) diff --git a/decision_tree/tree_as_txt.txt b/decision_tree/tree_as_txt.txt index 9b5c043..0bc5127 100644 --- a/decision_tree/tree_as_txt.txt +++ b/decision_tree/tree_as_txt.txt @@ -4,46 +4,46 @@ | | | |--- class: 0 | | |--- feature_0 > 1.50 | | | |--- feature_3 <= 3.50 -| | | | |--- feature_2 <= 2.50 +| | | | |--- feature_4 <= 2.50 | | | | | |--- class: 1 -| | | | |--- feature_2 > 2.50 -| | | | | |--- feature_4 <= 2.50 +| | | | |--- feature_4 > 2.50 +| | | | | |--- feature_2 <= 2.50 | | | | | | |--- class: 1 -| | | | | |--- feature_4 > 2.50 +| | | | | |--- feature_2 > 2.50 | | | | | | |--- class: 0 | | | |--- feature_3 > 3.50 | | | | |--- feature_3 <= 4.50 | | | | | |--- feature_1 <= 2.50 | | | | | | |--- feature_0 <= 2.50 | | | | | | | |--- feature_1 <= 1.50 -| | | | | | | | |--- feature_4 <= 2.50 +| | | | | | | | |--- feature_2 <= 2.50 | | | | | | | | | |--- class: 1 -| | | | | | | | |--- feature_4 > 2.50 -| | | | | | | | | |--- feature_2 <= 2.00 +| | | | | | | | |--- feature_2 > 2.50 +| | | | | | | | | |--- feature_4 <= 2.00 | | | | | | | | | | |--- class: 1 -| | | | | | | | | |--- feature_2 > 2.00 +| | | | | | | | | |--- feature_4 > 2.00 | | | | | | | | | | |--- class: 0 | | | | | | | |--- feature_1 > 1.50 | | | | | | | | |--- class: 0 | | | | | | |--- feature_0 > 2.50 -| | | | | | | |--- feature_2 <= 2.50 +| | | | | | | |--- feature_4 <= 2.50 | | | | | | | | |--- class: 1 -| | | | | | | |--- feature_2 > 2.50 -| | | | | | | | |--- feature_4 <= 2.50 +| | | | | | | |--- feature_4 > 2.50 +| | | | | | | | |--- feature_2 <= 2.50 | | | | | | | | | |--- class: 1 -| | | | | | | | |--- feature_4 > 2.50 +| | | | | | | | |--- feature_2 > 2.50 | | | | | | | | | |--- class: 0 | | | | | |--- feature_1 > 2.50 | | | | | | |--- feature_1 <= 3.50 | | | | | | | |--- feature_0 <= 3.50 | | | | | | | | |--- class: 0 | | | | | | | |--- feature_0 > 3.50 -| | | | | | | | |--- feature_4 <= 2.50 +| | | | | | | | |--- feature_2 <= 2.50 | | | | | | | | | |--- class: 1 -| | | | | | | | |--- feature_4 > 2.50 -| | | | | | | | | |--- feature_2 <= 2.00 +| | | | | | | | |--- feature_2 > 2.50 +| | | | | | | | | |--- feature_4 <= 2.00 | | | | | | | | | | |--- class: 1 -| | | | | | | | | |--- feature_2 > 2.00 +| | | | | | | | | |--- feature_4 > 2.00 | | | | | | | | | | |--- class: 0 | | | | | | |--- feature_1 > 3.50 | | | | | | | |--- class: 0 @@ -76,13 +76,13 @@ | |--- feature_4 <= 1.50 | | |--- feature_1 <= 1.50 | | | |--- feature_2 <= 4.50 -| | | | |--- feature_3 <= 4.50 -| | | | | |--- feature_0 <= 1.50 -| | | | | | |--- class: 0 -| | | | | |--- feature_0 > 1.50 -| | | | | | |--- class: 1 -| | | | |--- feature_3 > 4.50 +| | | | |--- feature_0 <= 1.50 | | | | | |--- class: 0 +| | | | |--- feature_0 > 1.50 +| | | | | |--- feature_3 <= 4.50 +| | | | | | |--- class: 1 +| | | | | |--- feature_3 > 4.50 +| | | | | | |--- class: 0 | | | |--- feature_2 > 4.50 | | | | |--- class: 0 | | |--- feature_1 > 1.50 diff --git a/decision_tree/tree_model b/decision_tree/tree_model index c9ec1be..6097820 100644 Binary files a/decision_tree/tree_model and b/decision_tree/tree_model differ diff --git a/last_map.nparr b/last_map.nparr index c739475..c7831e4 100644 Binary files a/last_map.nparr and b/last_map.nparr differ diff --git a/main.py b/main.py index eb50486..b196ec0 100644 --- a/main.py +++ b/main.py @@ -101,10 +101,10 @@ class Game(): atrrs_container = i.get_attributes() x, y = i.get_coords() dec = decisionTree.decision(getTree(), *atrrs_container) - if dec[0] == 1: - self.positive_decision.append(i) - else: - self.negative_decision.append(i) + # if dec[0] == 1: + self.positive_decision.append(i) # zmiana po to by losowaƂo wszystkie smietniki a nie poprawne tylko, zeby ladniej bylo widac algorytm genetyczny + # else: + # self.negative_decision.append(i) print('positive actions') print(len(self.positive_decision)) @@ -114,12 +114,26 @@ class Game(): # print(i) # print('----') def decsion_tree_move(self): - - for i in self.positive_decision: + + for i in range(0,len(self.positive_decision)): # print(i.get_coords()) print('action') - trash_x, trash_y = i.get_coords() + + + # trash_x, trash_y = i.get_coords() + + # for ii in self.tsp_list: + temp_tsp = str(self.tsp_list[i]) + temp_tsp = temp_tsp.strip("()") + temp_tsp = temp_tsp.split(",") + trash_x = int(temp_tsp[0]) + trash_y = int(temp_tsp[1]) + + + print(trash_x, trash_y) + action = a_star_controller.get_actions_for_target_coords(trash_x, trash_y, self) + print(action) self.t.startAiController(action) @@ -127,7 +141,7 @@ class Game(): print('--rozpoczecie sortowania smietnika--') dir = "./resources/trash_dataset/test/all" files = os.listdir(dir) - for i in range(0, 10): + for j in range(0, 10): random = randint(0, 48) file = files[random] result = prediction.getPrediction(dir + '/' + file, 'trained_nn_20.pth') @@ -155,8 +169,8 @@ class Game(): # dist = a_star.get_cost - tsp_list = TSP.geneticAlgorithmPlot(population=city_list, popSize=100, eliteSize=20, mutationRate=0.01, generations=200) - print(tsp_list) + self.tsp_list = TSP.geneticAlgorithmPlot(population=city_list, popSize=100, eliteSize=20, mutationRate=0.01, generations=200) + print(self.tsp_list) def load_data(self): game_folder = os.path.dirname(__file__) diff --git a/map/map_utils.py b/map/map_utils.py index e3da2c7..6d4a583 100644 --- a/map/map_utils.py +++ b/map/map_utils.py @@ -21,7 +21,7 @@ def generate_map(): map[y][x] = 1 # generowanie smietnikow - for i in range(0, 30): + for i in range(0, 20): x = random.randint(0, MAP_WIDTH-1) y = random.randint(0, MAP_HEIGHT-1) map[y][x] = 2 diff --git a/path_search_algorthms/a_star_utils.py b/path_search_algorthms/a_star_utils.py index ee24f61..8ac26b9 100644 --- a/path_search_algorthms/a_star_utils.py +++ b/path_search_algorthms/a_star_utils.py @@ -84,7 +84,9 @@ def get_rotate_change(rotationA: Rotation, rotationB: Rotation) -> int: return int(rotationA) - int(rotationB) # get new rotation for target_node as neighbour of start_node -def get_needed_rotation(start_node: Node, target_node: Node) -> Rotation: +def get_needed_rotation(start_node: Node or bool, target_node: Node) -> Rotation: + if(start_node == False): + return target_node.rotation if (start_node.x - target_node.x > 0): return Rotation.LEFT if (start_node.x - target_node.x < 0):