.
This commit is contained in:
parent
8f9d89b908
commit
e67aa84f1f
@ -103,7 +103,7 @@ class ForkliftAgent(AgentBase):
|
||||
stations = dict(self.graph.packingStations)
|
||||
if i.real_type == ItemType.SHELF:
|
||||
packing_station = stations[PatchType.packingA]
|
||||
elif i.real_type == ItemType.FRIDGE:
|
||||
elif i.real_type == ItemType.REFRIGERATOR:
|
||||
packing_station = stations[PatchType.packingB]
|
||||
elif i.real_type == ItemType.DOOR:
|
||||
packing_station = stations[PatchType.packingC]
|
||||
|
@ -21,6 +21,8 @@ from decision.ActionType import ActionType
|
||||
from pathfinding.PathfinderOnStates import PathFinderOnStates, PathFinderState
|
||||
from util.PathByEnum import PathByEnum
|
||||
from util.PathDefinitions import GridLocation, GridWithWeights
|
||||
from imageClasification.Classificator import image_clasification
|
||||
|
||||
|
||||
|
||||
class Phase(Enum):
|
||||
@ -188,13 +190,13 @@ class GameModel(Model):
|
||||
|
||||
def recognise_item(self, item: Item):
|
||||
# TODO IMAGE PROCESSING
|
||||
val = self.classificator.image_clasification(self.picture_visualization.img)
|
||||
val = image_clasification(self.picture_visualization.img, self.classificator)
|
||||
print("VAL: {}".format(val))
|
||||
|
||||
if val == ItemType.DOOR:
|
||||
item.guessed_type = ItemType.DOOR
|
||||
elif val == ItemType.FRIDGE:
|
||||
item.guessed_type = ItemType.FRIDGE
|
||||
elif val == ItemType.REFRIGERATOR:
|
||||
item.guessed_type = ItemType.REFRIGERATOR
|
||||
elif val == ItemType.SHELF:
|
||||
item.guessed_type = ItemType.SHELF
|
||||
|
||||
|
@ -4,4 +4,4 @@ from enum import Enum
|
||||
class ItemType(Enum):
|
||||
DOOR = "door"
|
||||
SHELF = "shelf"
|
||||
FRIDGE = "fridge"
|
||||
REFRIGERATOR = "refrigerator"
|
@ -0,0 +1,23 @@
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
|
||||
|
||||
def image_clasification(image_path, model):
|
||||
# loaded_model = keras.models.load_model("my_model")
|
||||
class_names = ['door', 'refrigerator', 'shelf']
|
||||
|
||||
img = tf.keras.utils.load_img(
|
||||
image_path, target_size=(180, 180)
|
||||
)
|
||||
img_array = tf.keras.utils.img_to_array(img)
|
||||
img_array = tf.expand_dims(img_array, 0) # Create a batch
|
||||
|
||||
predictions = model.predict(img_array)
|
||||
score = tf.nn.softmax(predictions[0])
|
||||
# print(
|
||||
# "This image most likely belongs to {} with a {:.2f} percent confidence."
|
||||
# .format(class_names[np.argmax(score)], 100 * np.max(score))
|
||||
# )
|
||||
return class_names[np.argmax(score)]
|
||||
|
||||
|
@ -9,7 +9,7 @@ from tensorflow.keras import layers
|
||||
from tensorflow.keras.models import Sequential
|
||||
|
||||
|
||||
class Classificator():
|
||||
class ClassificatorInside():
|
||||
|
||||
def __init__(self, data_dir: str) -> None:
|
||||
super().__init__()
|
||||
|
6
main.py
6
main.py
@ -2,6 +2,7 @@ import random
|
||||
|
||||
from mesa.visualization.ModularVisualization import ModularServer
|
||||
from mesa.visualization.modules import CanvasGrid
|
||||
from tensorflow import keras
|
||||
|
||||
from ForkliftAgent import ForkliftAgent
|
||||
from GameModel import GameModel
|
||||
@ -9,7 +10,6 @@ from PatchAgent import PatchAgent
|
||||
from PatchType import PatchType
|
||||
from PictureVisualizationAgent import PictureVisualizationAgent
|
||||
from data.enum.Direction import Direction
|
||||
from imageClasification.Classificator import Classificator
|
||||
from util.PathDefinitions import GridWithWeights
|
||||
from visualization.DisplayAttributeElement import DisplayAttributeElement
|
||||
from visualization.DisplayItemListAttribute import DisplayItemListAttributeElement
|
||||
@ -88,13 +88,13 @@ if __name__ == '__main__':
|
||||
ordersText = DisplayOrderList("orderList")
|
||||
fulfilled_orders = DisplayOrderList("fulfilled_orders")
|
||||
|
||||
classificator = Classificator("imageClasification/images")
|
||||
loaded_model = keras.models.load_model("./imageClasification/my_model")
|
||||
|
||||
server = ModularServer(GameModel,
|
||||
[grid, readyText, provided_itesm, recognised_items, ordersText,
|
||||
fulfilled_orders],
|
||||
"Automatyczny Wózek Widłowy",
|
||||
dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=3, classificator=classificator))
|
||||
dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=3, classificator=loaded_model))
|
||||
|
||||
server.port = 8888
|
||||
server.launch()
|
||||
|
@ -9,7 +9,7 @@ class PathByEnum:
|
||||
if item == ItemType.DOOR:
|
||||
a = str(random.randint(1, 10))
|
||||
return "item_images/door/drzwi" + a + ".jpg"
|
||||
if item == ItemType.FRIDGE:
|
||||
if item == ItemType.REFRIGERATOR:
|
||||
a = str(random.randint(1, 10))
|
||||
return "item_images/refrigerator/lodowka" + a + ".jpg"
|
||||
if item == ItemType.SHELF:
|
||||
|
Loading…
Reference in New Issue
Block a user