diff --git a/scripts/up_serving.sh b/scripts/up_serving.sh index 721ea89..b34129f 100755 --- a/scripts/up_serving.sh +++ b/scripts/up_serving.sh @@ -4,5 +4,6 @@ RATIO_GPU=${RATIO_GPU:-0.45} echo "Using GPU: $NVIDIA_VISIBLE_DEVICES" echo "Limiting GPU to ratio: $RATIO_GPU" +cd /src/mot/serving python3 -m mot.serving.app & /usr/bin/tf_serving_entrypoint.sh --per_process_gpu_memory_fraction=$RATIO_GPU diff --git a/src/mot/object_detection/query_server.py b/src/mot/object_detection/query_server.py index 8a116a7..f15ca9e 100644 --- a/src/mot/object_detection/query_server.py +++ b/src/mot/object_detection/query_server.py @@ -86,7 +86,7 @@ def localizer_tensorflow_serving_inference( [0.1, 0.1, 0.9, 0.9], [0.0, 0.2, 0.1, 0.4], [0.2, 0.4, 0.5, 0.7], - ], (y1, x1, y2, x2) scaled between 0 and 1 + ], # (y1, x1, y2, x2) scaled between 0 and 1 'output/labels:0': [3, 1, 2], # the labels start at 1 since 0 is for background 'output/scores:0': [0.98, 0.87, 0.76] # sorted in descending order } diff --git a/src/mot/serving/inference.py b/src/mot/serving/inference.py index f5f1cd3..7795a90 100644 --- a/src/mot/serving/inference.py +++ b/src/mot/serving/inference.py @@ -80,14 +80,26 @@ def process_video(): def process_zip(): images_folder = os.path.join(upload_folder, "{}_split".format(filename)) with zipfile.ZipFile(full_filepath, 'r') as zip_obj: - file_names = zip_obj.namelist() - for file_name in file_names: - zip_obj.extract(file_name, images_folder) - if os.path.basename(file_name): - shutil.move( - os.path.join(images_folder, file_name), - os.path.join(images_folder, os.path.basename(file_name)) - ) + zip_obj.extractall(images_folder) + + def move_files_to_root(directory, root_directory): + for x in os.listdir(directory): + path = os.path.join(directory, x) + if x.startswith("._") or x.startswith("__"): + # unwanted files such as __MACOSX + shutil.rmtree(path) + else: + if os.path.isfile(path): + # we want to move this file to the root of the zip directory + if not os.path.isfile(os.path.join(root_directory, x)): + # unless it is aleady present at root + shutil.move(path, root_directory) + else: + # if there is a folder, we want to move back the files to root + move_files_to_root(path, root_directory) + + move_files_to_root(images_folder, images_folder) + return images_folder if file.mimetype == "": @@ -154,8 +166,6 @@ def _process_image(image_path: str) -> Dict: ``` """ image = cv2.imread(image_path) # cv2 opens in BGR - if image is None: - return None predictions = localizer_tensorflow_serving_inference(image, SERVING_URL, return_all_scores=True) return predictions diff --git a/src/mot/serving/viz.py b/src/mot/serving/viz.py index cda5ba1..bda3607 100644 --- a/src/mot/serving/viz.py +++ b/src/mot/serving/viz.py @@ -25,8 +25,8 @@ def draw_boxes(image_path: str, trashes: List[Dict]): img, trash["label"] + " " + str(round(trash["score"], 2)), (box[0], box[1] - 10), - cv2.FONT_HERSHEY_COMPLEX, - 2, + cv2.FONT_HERSHEY_SIMPLEX, + 1, CLASS_NAME_TO_COLOR[trash["label"]], cv2.LINE_4, )