Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Hoorelbeke committed Jun 19, 2020
1 parent 9b9d8aa commit f8a33af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions scripts/up_serving.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/mot/object_detection/query_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 20 additions & 10 deletions src/mot/serving/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "":
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/mot/serving/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit f8a33af

Please sign in to comment.