diff --git a/main.py b/main.py index e92d1ff..180955e 100644 --- a/main.py +++ b/main.py @@ -303,7 +303,7 @@ class Game: goal = x//TILE_SIZE,y//TILE_SIZE mob_image = self.sauron.image_path prediction = self.prediction_road(x,y,mob_image) - prediction = "SAURON" + #prediction = "SAURON" while True: #do poprawienia poprawne rozpoznawanie print("goal: ",goal) if prediction == "SAURON": @@ -331,7 +331,7 @@ class Game: prediction = self.prediction_road(x,y,mob_image) prediction = "ORK_ARCHER" - elif prediction == "ORK_INFANTRY": + elif prediction == "ORK_MELEE": if self.agent.level < self.infantry_ork.level: lvl = 'nie' else: @@ -356,7 +356,7 @@ class Game: goal = x//TILE_SIZE,y//TILE_SIZE mob_image = self.sauron.image_path prediction = self.prediction_road(x,y,mob_image) - prediction = "SAURON" + #prediction = "SAURON" elif prediction == "ORK_ARCHER": if self.agent.level < self.archer_ork.level: lvl = 'nie' @@ -384,7 +384,7 @@ class Game: goal = x//TILE_SIZE,y//TILE_SIZE mob_image = self.infantry_ork.image_path prediction = self.prediction_road(x,y,mob_image) - prediction = "ORK_INFANTRY" + #prediction = "ORK_INFANTRY" diff --git a/mobs.py b/mobs.py index 8e3e361..6b7b3f7 100644 --- a/mobs.py +++ b/mobs.py @@ -14,7 +14,7 @@ class Archer_ork(pygame.sprite.Sprite): self.width = TILE_SIZE self.height = TILE_SIZE - self.image_path = "./zdjecia/ORK_ARCHER/ork_lucznik.png" + self.image_path = "./zdjecia/ORK_ARCHER/ork_archer (889).jpg" self.ARCHER_ORK_IMG = pygame.image.load(self.image_path) self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64)) @@ -45,7 +45,7 @@ class Infantry_ork(pygame.sprite.Sprite): self.width = TILE_SIZE self.height = TILE_SIZE - self.image_path = "./zdjecia/ORK_MELEE/ork-piechota.png" + self.image_path = "C:\\mobs_photos\\ork_melee (11).jpg"#sciezka do zmiany self.INFANTRY_ORK_IMG = pygame.image.load(self.image_path) self.INFANTRY_ORK = pygame.transform.scale(self.INFANTRY_ORK_IMG,(64,64)) @@ -77,7 +77,7 @@ class Sauron(pygame.sprite.Sprite): self.width = TILE_SIZE self.height = TILE_SIZE - self.image_path = "./zdjecia/SAURON/sauron.png" + self.image_path = "C:\\mobs_photos\\sauron (700).jpg"#sciezka do zmiany self.SAURON_IMG = pygame.image.load(self.image_path) self.SAURON = pygame.transform.scale(self.SAURON_IMG,(64,64)) diff --git a/nn.py b/nn.py index 5f09003..1ab31f5 100644 --- a/nn.py +++ b/nn.py @@ -11,8 +11,8 @@ import pathlib class NeuralN: -# @staticmethod - def predict(self,image_path): + # @staticmethod + def predict(self, image_path): data_dir = pathlib.Path('zdjecia') saved_model_path = pathlib.Path('trained_model.h5') class_names_path = pathlib.Path("class_names.pkl") @@ -47,12 +47,6 @@ class NeuralN: image_size=(180, 180), batch_size=32) - # test_ds = tf.keras.utils.image_dataset_from_directory( - # data_dir, - # seed=123, - # image_size=(180, 180), - # batch_size=32) - class_names = train_ds.class_names print(class_names) @@ -77,7 +71,7 @@ class NeuralN: metrics=['accuracy']) model.summary() - epochs = 1 + epochs = 10 history = model.fit( train_ds, validation_data=val_ds, @@ -92,31 +86,24 @@ class NeuralN: probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()]) - #image_path = image - image_path = pathlib.Path('zdjecia\ORK_ARCHER\ork_archer (2).png') + # image_path = image + #image_path = pathlib.Path('') image = Image.open(image_path) # Preprocess the image + image = image.resize((180, 180)) # Resize to match the input size of the model image_array = tf.keras.preprocessing.image.img_to_array(image) image_array = image_array / 255.0 # Normalize pixel values # Add an extra dimension to the image array - image_array = tf.expand_dims(image_array, 0) + image_array = tf.expand_dims(image, 0) # Make the prediction - predictions = probability_model.predict(image_array) - + model = tf.keras.models.load_model("trained_model.h5") + prediction = model.predict(image_array) # Convert the predictions to class labels - predicted_label = class_names[predictions[0].argmax()] - #actions = { - # 'ORK_MELEE': 'fight', - # 'ORK_ARCHER': 'change_dir', - # 'SAURON': 'change_dir' - #} - - # Get the action for the predicted character - #action = actions.get(predicted_label, 'unknown') + predicted_label = class_names[prediction[0].argmax()] # Print the predicted label print(predicted_label) - return predicted_label#, action + return predicted_label diff --git a/trained_model.h5 b/trained_model.h5 index 0b8bfa4..b9783e2 100644 Binary files a/trained_model.h5 and b/trained_model.h5 differ