def run_predict(): predictor = CustomImagePrediction() predictor.setModelPath(model_path="trafficnetmodelacc-0.893750.h5") predictor.setJsonPath(model_json="model_class.json") predictor.loadFullModel(num_objects=4) predictions, probabilities = predictor.predictImage(image_input="images/dense.jpg", result_count=4) for prediction, probability in zip(predictions, probabilities): print(prediction, " : ", probability)
def run_predict(): predictor = CustomImagePrediction() predictor.setModelPath(model_path="trafficnet_resnet_model_ex-055_acc-0.913750.h5") predictor.setJsonPath(model_json="model_class.json") predictor.loadFullModel(num_objects=4) predictions, probabilities = predictor.predictImage(image_input="", result_count=4) #PATH FOR IMAGE for prediction, probability in zip(predictions, probabilities): print(prediction, " : ", probability)
def run_predict(): predictor = CustomImagePrediction() predictor.setModelPath(model_path="action_net_ex-060_acc-0.745313.h5") predictor.setJsonPath(model_json="model_class.json") predictor.loadFullModel(num_objects=16) predictions, probabilities = predictor.predictImage( image_input="images/5.jpg", result_count=4) for prediction, probability in zip(predictions, probabilities): print(prediction, " : ", probability)
def test_custom_recognition_full_model_resnet(): predictor = CustomImagePrediction() predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_full_resnet_ex-001_acc-0.119792.h5")) predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) predictor.loadFullModel(num_objects=10) predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "9.jpg")) assert isinstance(predictions, list) assert isinstance(probabilities, list) assert isinstance(predictions[0], str) assert isinstance(probabilities[0], str)
def activity_detector(image_name): result = [] predictor = CustomImagePrediction() predictor.setModelPath( model_path=os.path.join(root, "action-detection-image", "action.h5")) predictor.setJsonPath(model_json=os.path.join( root, "action-detection-image", "model_class.json")) predictor.loadFullModel(num_objects=16) predictions, probabilities = predictor.predictImage(image_input=image_name, result_count=4) for prediction, probability in zip(predictions, probabilities): result.append([prediction, probability]) print(result) return result[0][0]
def test_custom_recognition_full_model_resnet_multi(): try: keras.backend.clear_session() except: None predictor = CustomImagePrediction() predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_full_resnet_ex-001_acc-0.119792.h5")) predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) predictor.loadFullModel(num_objects=10) images_to_image_array() result_array = predictor.predictMultipleImages(sent_images_array=all_images_array) assert isinstance(result_array, list) for result in result_array: assert "predictions" in result assert "percentage_probabilities" in result assert isinstance(result["predictions"], list) assert isinstance(result["percentage_probabilities"], list) assert isinstance(result["predictions"][0], str) assert isinstance(result["percentage_probabilities"][0], str)
def run_predict(): predictor = CustomImagePrediction() predictor.setModelPath( model_path="trafficnet_resnet_model_ex-055_acc-0.913750.h5") predictor.setJsonPath(model_json="model_class.json") predictor.loadFullModel(num_objects=4) predictions, probabilities = predictor.predictImage( image_input="images/traff.jpg", result_count=4) for prediction, probability in zip(predictions, probabilities): print(prediction, " : ", probability) result["accident"][prediction] = probability # otus thresholding of 80 if probability > 80: result["accident_result"][prediction] = True else: result["accident_result"][prediction] = False if result["accident_result"]["Accident"] == True or result[ "accident_result"]["Fire"] == True: sendemail() print(result) write(result)
from imageai.Prediction.Custom import CustomImagePrediction import os # Load the model to use for prediction predictor = CustomImagePrediction() predictor.setModelPath(model_path="model_ex-035_acc-0.874667.h5") predictor.setJsonPath(model_json="model_class.json") predictor.loadFullModel(num_objects=5) directory = "C:/Programs/Java/Computer-Vision-Team19/testing/" ints = [] # Put the names of the image files into the array of ints for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(".jpg"): ints.append(int(filename.split(".", 1)[0])) else: print("Ignoring file named " + filename) # Sort the filenames and print a newline ints.sort() print() # Log prediction results to a file log = open("../run3.txt", "w") for i in ints: filename = str(i) + ".jpg" path = os.path.join(directory, filename) prediction, probability = predictor.predictImage(image_input=path,
def pre(): execution_path = os.getcwd() im_path = execution_path #+ "/imx" os.system("rm log/" + "*.txt") #note please copy the name of the model that you want to use from /content/im6/models ################################################ ##m_n="best-models/eye16-ResNet/model_ex-055_acc-0.992638.h5" ##m_n="best-models/eye8-DenseNet/model_ex-055_acc-0.992402.h5" #m_n="best-models/eye16-SqueezeNet/model_ex-001_acc-0.494081.h5" m_n = "best-models/eye16-InceptionV3/model_ex-022_acc-0.992049.h5" ################################################ from imageai.Prediction.Custom import CustomImagePrediction prediction = CustomImagePrediction() prediction.setModelPath(model_path=im_path + "/" + m_n) prediction.setJsonPath(model_json=im_path + "/best-models/model_class.json") prediction.loadFullModel(num_objects=2) pa = im_path + "/pic/" print("==================\n==== Welcome ====\n==================") while True: output = [] t1 = time.time() uuu = -1 ######################################## sss = "" for file in sorted(os.listdir(pa)): #if file.endswith(".jpg"): try: uuu = uuu + 1 image_path = pa + "/" + file t1x = time.time() results, probabilities = prediction.predictImage( image_input=image_path, result_count=1) t2x = time.time() print("Time-->", t2x - t1x) output.append(results) if results[0] == 'close': x = "1" else: x = "0" sss = sss + x f = open('log/log.txt', 'a+') f.write("%s" % x) f.close() os.system("rm " + image_path) print(x) except: continue ######################################## '''for file in sorted(os.listdir(pa)): #if file.endswith(".jpg"): try: uuu=uuu+1 image_path=pa+"/"+file results, probabilities = prediction.predictImage(image_input=image_path, result_count=1) output.append(results) os.system("rm "+image_path) #print(image_path) except: continue sss="" with open('log/log.txt', 'a+') as f: for item in output: if item[0]=='close': x="1" else: x="0" sss=sss+x f.write("%s" % x)''' t2 = time.time() if uuu > 0: print("Time-->", t2 - t1, "Files#", uuu)
predictor = CustomImagePrediction() predictor.setModelPath( model_path=os.path.join(execution_path, "idenprof_resnet.h5") ) # Download the model via this link https://github.com/OlafenwaMoses/ImageAI/releases/tag/models-v3 predictor.setJsonPath(model_json=os.path.join(execution_path, "idenprof.json")) predictor.setModelTypeAsResNet() predictor.loadModel(num_objects=10) predictor2 = CustomImagePrediction() predictor2.setModelPath( model_path=os.path.join(execution_path, "idenprof_full_resnet_ex-001_acc-0.119792.h5") ) # Download the model via this link https://github.com/OlafenwaMoses/ImageAI/releases/tag/models-v3 predictor2.setJsonPath( model_json=os.path.join(execution_path, "idenprof.json")) predictor2.loadFullModel(num_objects=10) predictor3 = CustomImagePrediction() predictor3.setModelPath( model_path=os.path.join(execution_path, "idenprof_inception_0.719500.h5") ) # Download the model via this link https://github.com/OlafenwaMoses/ImageAI/releases/tag/models-v3 predictor3.setJsonPath( model_json=os.path.join(execution_path, "idenprof.json")) predictor3.setModelTypeAsInceptionV3() predictor3.loadModel(num_objects=10) results, probabilities = predictor.predictImage(image_input=os.path.join( execution_path, "9.jpg"), result_count=5) print(results) print(probabilities)