Skip to content
Snippets Groups Projects
Commit f6279b07 authored by Anders Langlie's avatar Anders Langlie
Browse files

Included sex_identification. Currently run from seperate file.

parent 07ec63b1
Branches
No related tags found
1 merge request!26Draft: Resolve "Add object detection"
......@@ -5,4 +5,5 @@ __pycache__
algorithm/train_src/dlc_model
img_analyze/*.png
env
temp_images
\ No newline at end of file
temp_images
algorithm/train_src/imageai_model
\ No newline at end of file
import sex_identification
print(sex_identification.identify("E:/PycharmProjects/salamander-api/img_analyze/female.png"))
\ No newline at end of file
from imageai.Detection.Custom import DetectionModelTrainer, CustomObjectDetection
import os
import tensorflow as tf
def identify(image):
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)
root_path = "../../../salamander-api"
os_directory_path = os.path.abspath(root_path)
image_detector = CustomObjectDetection()
image_detector.setModelTypeAsYOLOv3()
image_detector.setModelPath(os.path.join(os_directory_path,
"algorithm/train_src/imageai_model/models/detection_model-ex-012--loss-0018.483.h5"))
image_detector.setJsonPath(
os.path.join(os_directory_path, "algorithm/train_src/imageai_model/json/detection_config.json"))
image_detector.loadModel()
predictions = image_detector.detectObjectsFromImage(input_image=image,
output_image_path=os.path.join(os_directory_path,
"img_analyze/detected_salamander.png"),
minimum_percentage_probability=40)
# winner = {"name": "male", "percentage_probability": 0}
# for prediction in predictions:
# if prediction['percentage_probability'] > winner['percentage_probability']:
# winner['percentage_probability'] = prediction['percentage_probability']
# winner['name'] = prediction['name']
largest_p = max(predictions, key=lambda x: x['percentage_probability'])['name']
return largest_p
def train():
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)
directory_path = "../../../salamander-api/img_analyze"
os_directory_path = os.path.abspath(directory_path)
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory=os.path.join(os_directory_path, "algorithm/train_src/imageai_model"))
trainer.setTrainConfig(object_names_array=["male", "female"], batch_size=8, num_experiments=200)
# In the above,when training for detecting multiple objects,
# set object_names_array=["object1", "object2", "object3",..."objectz"]
trainer.trainModel()
......@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
config_path= "dlc_model/config.yaml"
directory_path= "../../../salamander-api/img_analyze"
image_to_predict = "img40.png"
image_to_predict = "female.png"
config = os.path.abspath(config_path)
os_directory_path = os.path.abspath(directory_path)
......@@ -14,7 +14,6 @@ image_type = image_to_predict[-4:]
img_directory = os_directory_path + '\\' + image_to_predict
smallpath = os_directory_path + '/' + 'small' + image_to_predict
# reading image:
img = cv2.imread(img_directory)
# You will have to convert the color if you use OpenCV.
......
from api import app
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment