changes for better understanding of code

This commit is contained in:
Pavel 2023-06-04 19:16:50 +02:00
parent 7e3a9cf3d0
commit e8b8de741d

View File

@ -5,10 +5,11 @@ from tensorflow import keras
import cv2 import cv2
import random import random
#YOU CAN DOWNLOAD MODEL FROM https://uam-my.sharepoint.com/:f:/g/personal/pavbia_st_amu_edu_pl/EmBHjnETuk5LiCZS6xk7AnIBNsnffR3Sygf8EX2bhR1w4A #You can download model from https://uam-my.sharepoint.com/:f:/g/personal/pavbia_st_amu_edu_pl/EmBHjnETuk5LiCZS6xk7AnIBNsnffR3Sygf8EX2bhR1w4A
#Change the path to model + to datasets (string 12 + strings 35,41,47,53)
class VacuumRecognizer: class VacuumRecognizer:
model = keras.models.load_model('AI_brain\model.h5') model = keras.models.load_model('AI_brain\model.h5') #Neuron model path
def recognize(self, image_path) -> str: def recognize(self, image_path) -> str:
class_names = ['Banana', 'Cat', 'Earings', 'Plant'] class_names = ['Banana', 'Cat', 'Earings', 'Plant']
@ -31,25 +32,25 @@ class VacuumRecognizer:
def get_random_dir(self, type) -> str: def get_random_dir(self, type) -> str:
if type == 'Plant': if type == 'Plant':
plant_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Plant' plant_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Plant' #Plant dataset path
plant_dirs = os.listdir(plant_image_paths) plant_dirs = os.listdir(plant_image_paths)
full_path = plant_image_paths + '\\' + plant_dirs[random.randint(0, len(plant_dirs)-1)] full_path = plant_image_paths + '\\' + plant_dirs[random.randint(0, len(plant_dirs)-1)]
print(full_path) print(full_path)
return full_path return full_path
elif type == 'Earings': elif type == 'Earings':
earnings_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Earings' earnings_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Earings' #Earings dataset path
earning_dirs = os.listdir(earnings_image_paths) earning_dirs = os.listdir(earnings_image_paths)
full_path = earnings_image_paths + '\\' + earning_dirs[random.randint(0, len(earning_dirs)-1)] full_path = earnings_image_paths + '\\' + earning_dirs[random.randint(0, len(earning_dirs)-1)]
print(full_path) print(full_path)
return full_path return full_path
elif type == 'Banana': elif type == 'Banana':
banana_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Banana' banana_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Banana' #Banana dataset path
banana_dirs = os.listdir(banana_image_paths) banana_dirs = os.listdir(banana_image_paths)
full_path = banana_image_paths + '\\' + banana_dirs[random.randint(0, len(banana_dirs)-1)] full_path = banana_image_paths + '\\' + banana_dirs[random.randint(0, len(banana_dirs)-1)]
print(full_path) print(full_path)
return full_path return full_path
elif type == 'Cat': elif type == 'Cat':
cat_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Cat' cat_image_paths = 'C:\\Users\\Pavel\\Desktop\\AI\\Machine_learning_2023\\AI_brain\\Image_datasetJPGnewBnW\\check\\Cat' #Cat dataset path
cat_dir = os.listdir(cat_image_paths) cat_dir = os.listdir(cat_image_paths)