diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/Dockerfile b/Dockerfile index 9fafa03..c28f9ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,12 +5,13 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends apt-utils && \ apt-get -y upgrade -# clone the repository +# clone the repository RUN git clone --depth 1 https://github.com/tensorflow/models.git # Install object detection api dependencies RUN apt-get install -y protobuf-compiler python-pil python-lxml python-tk && \ pip install Cython && \ + pip install tf_slim && \ pip install contextlib2 && \ pip install jupyter && \ pip install matplotlib && \ @@ -47,8 +48,14 @@ WORKDIR /Tensorflow-2-Object-Detection-API-Flask-Application # change here to download your pretrained model RUN mkdir models && \ cd models/ && \ - curl -O "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz" && \ - tar xzf ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz && \ - rm ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz + #curl -O "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz" && \ + #tar xzf ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz && \ + #rm ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03.tar.gz + + curl -O "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz" && \ + tar xzf ssd_mobilenet_v1_coco_2018_01_28.tar.gz && \ + rm ssd_mobilenet_v1_coco_2018_01_28.tar.gz -CMD ["python", "main.py"] \ No newline at end of file + + +CMD ["python", "main.py"] diff --git a/client.py b/client.py index a9e498b..b019218 100644 --- a/client.py +++ b/client.py @@ -4,6 +4,9 @@ import cv2 import argparse import os +import time + +start_time = time.perf_counter() address = 'http://127.0.0.1:5000' img_path = 'images/girl_image.jpg' @@ -25,7 +28,7 @@ def parse_args(): def post_image(img_path, URL): """ post image and return the response """ - + img = open(img_path, 'rb').read() response = requests.post(URL, data=img, headers=headers) return response @@ -50,5 +53,8 @@ def write_image(save_dir, parsed_response): print("detections are: ", parsed_response["detections"]) print("the image size is: ", parsed_response["image size"]) - write_image(args.output_dir, parsed_response) - \ No newline at end of file + # write_image(args.output_dir, parsed_response) + + finish_time = time.perf_counter() + total_time = finish_time - start_time + print (total_time) diff --git a/images/test.jpg b/images/test.jpg new file mode 100644 index 0000000..bff9b86 Binary files /dev/null and b/images/test.jpg differ diff --git a/main.py b/main.py index fdd0991..9cc2f63 100644 --- a/main.py +++ b/main.py @@ -10,8 +10,11 @@ DEFAULT_PORT = 5000 DEFAULT_HOST = '0.0.0.0' -model_path = "models/ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03/saved_model" +# model_path = "models/ssd_mobilenet_v2_coco_2018_03_29/saved_model" +model_path = "models/ssd_mobilenet_v1_coco_2018_01_28/saved_model" +# model_path = "models/ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco14_sync_2018_07_03/saved_model" labels_path = "data/mscoco_label_map.pbtxt" +print (model_path) vis_threshold = 0.5 max_boxes = 20 @@ -62,7 +65,7 @@ def infer(): # build a response dict to send back to client response = parsed_output_dict - + # encode response response_encoded = json.dumps(response, cls=NumpyArrayEncoder) diff --git a/outputs/.DS_Store b/outputs/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/outputs/.DS_Store differ diff --git a/outputs/girl_image_output.jpg b/outputs/girl_image_output.jpg deleted file mode 100644 index 249f917..0000000 Binary files a/outputs/girl_image_output.jpg and /dev/null differ diff --git a/outputs/server_output.jpg b/outputs/server_output.jpg deleted file mode 100644 index 946cc0c..0000000 Binary files a/outputs/server_output.jpg and /dev/null differ diff --git a/utilities.py b/utilities.py index 48d67b0..94172e4 100644 --- a/utilities.py +++ b/utilities.py @@ -11,7 +11,11 @@ from collections import defaultdict from io import StringIO + +import matplotlib +matplotlib.use('TkAgg') from matplotlib import pyplot as plt + import cv2 from object_detection.utils import ops as utils_ops @@ -50,7 +54,7 @@ def run_inference_for_single_image(model, image): # Convert to numpy arrays, and take index [0] to remove the batch dimension. # We're only interested in the first num_detections. num_detections = int(output_dict.pop('num_detections')) - output_dict = {key:value[0, :num_detections].numpy() + output_dict = {key:value[0, :num_detections].numpy() for key,value in output_dict.items()} output_dict['num_detections'] = num_detections @@ -62,7 +66,7 @@ def run_inference_for_single_image(model, image): # Reframe the the bbox mask to the image size. detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks( output_dict['detection_masks'], output_dict['detection_boxes'], - image.shape[0], image.shape[1]) + image.shape[0], image.shape[1]) detection_masks_reframed = tf.cast(detection_masks_reframed > 0.5, tf.uint8) output_dict['detection_masks_reframed'] = detection_masks_reframed.numpy() diff --git a/utilities.pyc b/utilities.pyc new file mode 100644 index 0000000..3d9cc9a Binary files /dev/null and b/utilities.pyc differ