Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down Expand Up @@ -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"]


CMD ["python", "main.py"]
12 changes: 9 additions & 3 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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)

# write_image(args.output_dir, parsed_response)

finish_time = time.perf_counter()
total_time = finish_time - start_time
print (total_time)
Binary file added images/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Binary file added outputs/.DS_Store
Binary file not shown.
Binary file removed outputs/girl_image_output.jpg
Binary file not shown.
Binary file removed outputs/server_output.jpg
Binary file not shown.
8 changes: 6 additions & 2 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand Down
Binary file added utilities.pyc
Binary file not shown.