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
|
||||
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"
|
||||
|
||||
|
||||
|
||||
|
6
mobs.py
6
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))
|
||||
|
||||
|
29
nn.py
29
nn.py
@ -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,
|
||||
@ -93,30 +87,23 @@ class NeuralN:
|
||||
tf.keras.layers.Softmax()])
|
||||
|
||||
# image_path = image
|
||||
image_path = pathlib.Path('zdjecia\ORK_ARCHER\ork_archer (2).png')
|
||||
#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
|
||||
|
BIN
trained_model.h5
BIN
trained_model.h5
Binary file not shown.
Loading…
Reference in New Issue
Block a user