poprawa sieci neuronowej oraz drobne zmiany
This commit is contained in:
parent
71b2ecc23f
commit
ee864b16c7
8
main.py
8
main.py
@ -303,7 +303,7 @@ class Game:
|
|||||||
goal = x//TILE_SIZE,y//TILE_SIZE
|
goal = x//TILE_SIZE,y//TILE_SIZE
|
||||||
mob_image = self.sauron.image_path
|
mob_image = self.sauron.image_path
|
||||||
prediction = self.prediction_road(x,y,mob_image)
|
prediction = self.prediction_road(x,y,mob_image)
|
||||||
prediction = "SAURON"
|
#prediction = "SAURON"
|
||||||
while True: #do poprawienia poprawne rozpoznawanie
|
while True: #do poprawienia poprawne rozpoznawanie
|
||||||
print("goal: ",goal)
|
print("goal: ",goal)
|
||||||
if prediction == "SAURON":
|
if prediction == "SAURON":
|
||||||
@ -331,7 +331,7 @@ class Game:
|
|||||||
prediction = self.prediction_road(x,y,mob_image)
|
prediction = self.prediction_road(x,y,mob_image)
|
||||||
prediction = "ORK_ARCHER"
|
prediction = "ORK_ARCHER"
|
||||||
|
|
||||||
elif prediction == "ORK_INFANTRY":
|
elif prediction == "ORK_MELEE":
|
||||||
if self.agent.level < self.infantry_ork.level:
|
if self.agent.level < self.infantry_ork.level:
|
||||||
lvl = 'nie'
|
lvl = 'nie'
|
||||||
else:
|
else:
|
||||||
@ -356,7 +356,7 @@ class Game:
|
|||||||
goal = x//TILE_SIZE,y//TILE_SIZE
|
goal = x//TILE_SIZE,y//TILE_SIZE
|
||||||
mob_image = self.sauron.image_path
|
mob_image = self.sauron.image_path
|
||||||
prediction = self.prediction_road(x,y,mob_image)
|
prediction = self.prediction_road(x,y,mob_image)
|
||||||
prediction = "SAURON"
|
#prediction = "SAURON"
|
||||||
elif prediction == "ORK_ARCHER":
|
elif prediction == "ORK_ARCHER":
|
||||||
if self.agent.level < self.archer_ork.level:
|
if self.agent.level < self.archer_ork.level:
|
||||||
lvl = 'nie'
|
lvl = 'nie'
|
||||||
@ -384,7 +384,7 @@ class Game:
|
|||||||
goal = x//TILE_SIZE,y//TILE_SIZE
|
goal = x//TILE_SIZE,y//TILE_SIZE
|
||||||
mob_image = self.infantry_ork.image_path
|
mob_image = self.infantry_ork.image_path
|
||||||
prediction = self.prediction_road(x,y,mob_image)
|
prediction = self.prediction_road(x,y,mob_image)
|
||||||
prediction = "ORK_INFANTRY"
|
#prediction = "ORK_INFANTRY"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
6
mobs.py
6
mobs.py
@ -14,7 +14,7 @@ class Archer_ork(pygame.sprite.Sprite):
|
|||||||
self.width = TILE_SIZE
|
self.width = TILE_SIZE
|
||||||
self.height = 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_IMG = pygame.image.load(self.image_path)
|
||||||
self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64))
|
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.width = TILE_SIZE
|
||||||
self.height = 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_IMG = pygame.image.load(self.image_path)
|
||||||
self.INFANTRY_ORK = pygame.transform.scale(self.INFANTRY_ORK_IMG,(64,64))
|
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.width = TILE_SIZE
|
||||||
self.height = 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_IMG = pygame.image.load(self.image_path)
|
||||||
self.SAURON = pygame.transform.scale(self.SAURON_IMG,(64,64))
|
self.SAURON = pygame.transform.scale(self.SAURON_IMG,(64,64))
|
||||||
|
|
||||||
|
35
nn.py
35
nn.py
@ -11,8 +11,8 @@ import pathlib
|
|||||||
|
|
||||||
|
|
||||||
class NeuralN:
|
class NeuralN:
|
||||||
# @staticmethod
|
# @staticmethod
|
||||||
def predict(self,image_path):
|
def predict(self, image_path):
|
||||||
data_dir = pathlib.Path('zdjecia')
|
data_dir = pathlib.Path('zdjecia')
|
||||||
saved_model_path = pathlib.Path('trained_model.h5')
|
saved_model_path = pathlib.Path('trained_model.h5')
|
||||||
class_names_path = pathlib.Path("class_names.pkl")
|
class_names_path = pathlib.Path("class_names.pkl")
|
||||||
@ -47,12 +47,6 @@ class NeuralN:
|
|||||||
image_size=(180, 180),
|
image_size=(180, 180),
|
||||||
batch_size=32)
|
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
|
class_names = train_ds.class_names
|
||||||
print(class_names)
|
print(class_names)
|
||||||
|
|
||||||
@ -77,7 +71,7 @@ class NeuralN:
|
|||||||
metrics=['accuracy'])
|
metrics=['accuracy'])
|
||||||
model.summary()
|
model.summary()
|
||||||
|
|
||||||
epochs = 1
|
epochs = 10
|
||||||
history = model.fit(
|
history = model.fit(
|
||||||
train_ds,
|
train_ds,
|
||||||
validation_data=val_ds,
|
validation_data=val_ds,
|
||||||
@ -92,31 +86,24 @@ class NeuralN:
|
|||||||
probability_model = tf.keras.Sequential([model,
|
probability_model = tf.keras.Sequential([model,
|
||||||
tf.keras.layers.Softmax()])
|
tf.keras.layers.Softmax()])
|
||||||
|
|
||||||
#image_path = image
|
# image_path = image
|
||||||
image_path = pathlib.Path('zdjecia\ORK_ARCHER\ork_archer (2).png')
|
#image_path = pathlib.Path('')
|
||||||
image = Image.open(image_path)
|
image = Image.open(image_path)
|
||||||
|
|
||||||
# Preprocess the image
|
# Preprocess the image
|
||||||
|
|
||||||
image = image.resize((180, 180)) # Resize to match the input size of the model
|
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 = tf.keras.preprocessing.image.img_to_array(image)
|
||||||
image_array = image_array / 255.0 # Normalize pixel values
|
image_array = image_array / 255.0 # Normalize pixel values
|
||||||
|
|
||||||
# Add an extra dimension to the image array
|
# 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
|
# 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
|
# Convert the predictions to class labels
|
||||||
predicted_label = class_names[predictions[0].argmax()]
|
predicted_label = class_names[prediction[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')
|
|
||||||
|
|
||||||
# Print the predicted label
|
# Print the predicted label
|
||||||
print(predicted_label)
|
print(predicted_label)
|
||||||
return predicted_label#, action
|
return predicted_label
|
||||||
|
BIN
trained_model.h5
BIN
trained_model.h5
Binary file not shown.
Loading…
Reference in New Issue
Block a user