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