Skip to content
Snippets Groups Projects
Commit 83800a74 authored by Eirik Martin Danielsen's avatar Eirik Martin Danielsen :speech_balloon:
Browse files

estimage code

parent c208bc1d
No related branches found
No related tags found
1 merge request!37Resolve "rematch function and endpoint"
......@@ -3,6 +3,8 @@ venv
images
__pycache__
algorithm/train_src/dlc_model
algorithm/train_src/imageai_model
img_analyze/*.png
env
temp_images
*.db
\ No newline at end of file
......@@ -166,6 +166,8 @@ def estimate_image(detection_model_path: str = abs_path_imageai_model,
:return detected_objects_image_array:
"""
with _ACCESS_TF_AND_GPU_SEMA:
gender = "AI_sex"
if os.path.isfile(detection_model_path) and os.path.isfile(configuration_json):
manager = Manager()
return_dict = manager.list()
# return_dict = multiprocessing.Value("d", [], lock=False)
......@@ -177,8 +179,10 @@ def estimate_image(detection_model_path: str = abs_path_imageai_model,
p = Process(target=run_estimation, args=args)
p.start()
p.join()
return return_dict[0], return_dict[1], return_dict[2], return_dict[3]
if return_dict[0]['name']:
gender = return_dict[0]['name']
return gender, return_dict[1], return_dict[2], return_dict[3]
return gender, None, None, None
class BoundBox:
def __init__(self, xmin, ymin, xmax, ymax, objness=None, classes=None):
......
......@@ -7,7 +7,7 @@ import cv2
import os
from api import limiter
from image_encoder.image_encoder import *
from path_constants import image_type
from path_constants import image_type, abs_path_imageai_model, abs_path_imageai_config
ALLOWED_EXTENSIONS = ['jpg', 'png', 'jpeg']
......@@ -38,7 +38,8 @@ class FindSalamanderInfo(Resource):
str_image = cv2.cvtColor(str_image, cv2.COLOR_BGR2RGB)
cv2.imwrite(os.path.join(temp_img_path, str(user_id) + "_str." + image_type), str_image)
encoded = encode(os.path.join(temp_img_path, str(user_id) + "_str." + image_type))[2:-1]
return jsonify({"sex": "AI_sex", "species": "AI_species", "status": 200, "image": encoded})
gender, _, _, _ = estimate_image(abs_path_imageai_model,abs_path_imageai_config)
return jsonify({"sex": gender, "species": "AI_species", "status": 200, "image": encoded})
else:
return jsonify({"message": "image could not be processed", "status": 400})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment