-
Notifications
You must be signed in to change notification settings - Fork 38
X86 pedestrian detection smart distancing #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alpha-carinae29
wants to merge
20
commits into
galliot-us:master
Choose a base branch
from
alpha-carinae29:x86-pedestrian-detection-smart-distancing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ff7733f
Merge branch 'master' into openvino
kkrampa 99cbf4a
Tweaks
kkrampa 81f5e5e
Tweaks
kkrampa 36f5b6f
Implement Dummy Detector
mohammad7t 839b8e9
Reduce fps for dummy detector
mohammad7t 9a5c33b
Merge pull request #86 from kkrampa/openvino
mhejrati 40d4bf2
add slack channel.
mhejrati 0bfea43
fix #100
mrn-mln 932a580
rename dockerfiles (#92)
mdegans c3e550c
change load_model function in libs/detectors/x86/mobilenet_ssd.py
alpha-carinae29 4d493bb
add pedestrian mobilenet v2 detector to the smart distancing
alpha-carinae29 ea41751
add pedestrian ssdlite mobilenet v2 detector to the smart distancing
alpha-carinae29 408f297
add pedestrian ssdlite mobilenet v3 detector to the smart distancing
alpha-carinae29 606729a
change COCO model from mobilenet_ssd to ssd_mobilenet_v2
alpha-carinae29 991749d
modify config files
alpha-carinae29 d1bdca1
delete tarfile import
alpha-carinae29 a7d1fbf
migrate x86-pedestrian-detection-smart-distancing to new repo
alpha-carinae29 d01efb6
Merge remote-tracking branch 'upstream/master' into x86-pedestrian-de…
alpha-carinae29 99ac785
add pedestrian faster rcnn model for x86
alpha-carinae29 b542a97
change model path
alpha-carinae29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import pathlib | ||
| import time | ||
| import os | ||
| import numpy as np | ||
| import wget | ||
| import tensorflow as tf | ||
|
|
||
| from libs.detectors.utils.fps_calculator import convert_infr_time_to_fps | ||
|
|
||
|
|
||
| def load_model(model_name): | ||
| base_url = 'https://raw.githubusercontent.com/neuralet/neuralet-models/master/amd64/' | ||
| model_file = model_name + "/saved_model/saved_model.pb" | ||
| base_dir = "libs/detectors/x86/data/" | ||
| model_dir = os.path.join(base_dir, model_name) | ||
| if not os.path.isdir(model_dir): | ||
| os.makedirs(os.path.join(model_dir, "saved_model"), exist_ok=True) | ||
| print('model does not exist under: ', model_dir, 'downloading from ', base_url + model_file) | ||
| wget.download(base_url + model_file, os.path.join(model_dir, "saved_model")) | ||
|
|
||
| model_dir = pathlib.Path(model_dir) / "saved_model" | ||
|
|
||
| model = tf.saved_model.load(str(model_dir)) | ||
| model = model.signatures['serving_default'] | ||
|
|
||
| return model | ||
|
|
||
|
|
||
| class Detector: | ||
| """ | ||
| Perform object detection with the given model. The model is a quantized tflite | ||
| file which if the detector can not find it at the path it will download it | ||
| from neuralet repository automatically. | ||
|
|
||
| :param config: Is a ConfigEngine instance which provides necessary parameters. | ||
| """ | ||
|
|
||
| def __init__(self, config): | ||
| self.config = config | ||
| # Get the model name from the config | ||
| self.model_name = self.config.get_section_dict('Detector')['Name'] | ||
| # Frames Per Second | ||
| self.fps = None | ||
|
|
||
| self.detection_model = load_model('ped_ssd_mobilenet_v2') | ||
|
|
||
| def inference(self, resized_rgb_image): | ||
| """ | ||
| inference function sets input tensor to input image and gets the output. | ||
| The interpreter instance provides corresponding detection output which is used for creating result | ||
| Args: | ||
| resized_rgb_image: uint8 numpy array with shape (img_height, img_width, channels) | ||
|
|
||
| Returns: | ||
| result: a dictionary contains of [{"id": 0, "bbox": [x1, y1, x2, y2], "score":s%}, {...}, {...}, ...] | ||
| """ | ||
| input_image = np.expand_dims(resized_rgb_image, axis=0) | ||
| input_tensor = tf.convert_to_tensor(input_image) | ||
| t_begin = time.perf_counter() | ||
| output_dict = self.detection_model(input_tensor) | ||
| inference_time = time.perf_counter() - t_begin # Seconds | ||
|
|
||
| # Calculate Frames rate (fps) | ||
| self.fps = convert_infr_time_to_fps(inference_time) | ||
|
|
||
| boxes = output_dict['detection_boxes'] | ||
| labels = output_dict['detection_classes'] | ||
| scores = output_dict['detection_scores'] | ||
|
|
||
| class_id = int(self.config.get_section_dict('Detector')['ClassID']) | ||
| score_threshold = float(self.config.get_section_dict('Detector')['MinScore']) | ||
| result = [] | ||
| for i in range(boxes.shape[1]): # number of boxes | ||
| if labels[0, i] == class_id and scores[0, i] > score_threshold: | ||
| result.append({"id": str(class_id) + '-' + str(i), "bbox": boxes[0, i, :], "score": scores[0, i]}) | ||
|
|
||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import pathlib | ||
| import time | ||
| import os | ||
| import numpy as np | ||
| import wget | ||
| import tensorflow as tf | ||
|
|
||
| from libs.detectors.utils.fps_calculator import convert_infr_time_to_fps | ||
|
|
||
|
|
||
| def load_model(model_name): | ||
| base_url = 'https://raw.githubusercontent.com/neuralet/neuralet-models/master/amd64/' | ||
| model_file = model_name + "/saved_model/saved_model.pb" | ||
| base_dir = "libs/detectors/x86/data/" | ||
|
alpha-carinae29 marked this conversation as resolved.
Outdated
|
||
| model_dir = os.path.join(base_dir, model_name) | ||
| if not os.path.isdir(model_dir): | ||
| os.makedirs(os.path.join(model_dir, "saved_model"), exist_ok=True) | ||
| print('model does not exist under: ', model_dir, 'downloading from ', base_url + model_file) | ||
| wget.download(base_url + model_file, os.path.join(model_dir, "saved_model")) | ||
|
|
||
| model_dir = pathlib.Path(model_dir) / "saved_model" | ||
|
|
||
| model = tf.saved_model.load(str(model_dir)) | ||
| model = model.signatures['serving_default'] | ||
|
|
||
| return model | ||
|
|
||
|
|
||
| class Detector: | ||
| """ | ||
| Perform object detection with the given model. The model is a quantized tflite | ||
| file which if the detector can not find it at the path it will download it | ||
| from neuralet repository automatically. | ||
|
|
||
| :param config: Is a ConfigEngine instance which provides necessary parameters. | ||
| """ | ||
|
|
||
| def __init__(self, config): | ||
| self.config = config | ||
| # Get the model name from the config | ||
| self.model_name = self.config.get_section_dict('Detector')['Name'] | ||
| # Frames Per Second | ||
| self.fps = None | ||
|
|
||
| self.detection_model = load_model('ped_ssdlite_mobilenet_v2') | ||
|
|
||
| def inference(self, resized_rgb_image): | ||
| """ | ||
| inference function sets input tensor to input image and gets the output. | ||
| The interpreter instance provides corresponding detection output which is used for creating result | ||
| Args: | ||
| resized_rgb_image: uint8 numpy array with shape (img_height, img_width, channels) | ||
|
|
||
| Returns: | ||
| result: a dictionary contains of [{"id": 0, "bbox": [x1, y1, x2, y2], "score":s%}, {...}, {...}, ...] | ||
| """ | ||
| input_image = np.expand_dims(resized_rgb_image, axis=0) | ||
| input_tensor = tf.convert_to_tensor(input_image) | ||
| t_begin = time.perf_counter() | ||
| output_dict = self.detection_model(input_tensor) | ||
| inference_time = time.perf_counter() - t_begin # Seconds | ||
|
|
||
| # Calculate Frames rate (fps) | ||
| self.fps = convert_infr_time_to_fps(inference_time) | ||
|
|
||
| boxes = output_dict['detection_boxes'] | ||
| labels = output_dict['detection_classes'] | ||
| scores = output_dict['detection_scores'] | ||
|
|
||
| class_id = int(self.config.get_section_dict('Detector')['ClassID']) | ||
| score_threshold = float(self.config.get_section_dict('Detector')['MinScore']) | ||
| result = [] | ||
| for i in range(boxes.shape[1]): # number of boxes | ||
| if labels[0, i] == class_id and scores[0, i] > score_threshold: | ||
| result.append({"id": str(class_id) + '-' + str(i), "bbox": boxes[0, i, :], "score": scores[0, i]}) | ||
|
|
||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import pathlib | ||
| import time | ||
| import os | ||
| import numpy as np | ||
| import wget | ||
| import tensorflow as tf | ||
|
|
||
| from libs.detectors.utils.fps_calculator import convert_infr_time_to_fps | ||
|
|
||
|
|
||
| def load_model(model_name): | ||
| base_url = 'https://raw.githubusercontent.com/neuralet/neuralet-models/master/amd64/' | ||
| model_file = model_name + "/saved_model/saved_model.pb" | ||
| base_dir = "libs/detectors/x86/data/" | ||
|
alpha-carinae29 marked this conversation as resolved.
Outdated
|
||
| model_dir = os.path.join(base_dir, model_name) | ||
| if not os.path.isdir(model_dir): | ||
| os.makedirs(os.path.join(model_dir, "saved_model"), exist_ok=True) | ||
| print('model does not exist under: ', model_dir, 'downloading from ', base_url + model_file) | ||
| wget.download(base_url + model_file, os.path.join(model_dir, "saved_model")) | ||
|
|
||
| model_dir = pathlib.Path(model_dir) / "saved_model" | ||
|
|
||
| model = tf.saved_model.load(str(model_dir)) | ||
| model = model.signatures['serving_default'] | ||
|
|
||
| return model | ||
|
|
||
|
|
||
| class Detector: | ||
| """ | ||
| Perform object detection with the given model. The model is a quantized tflite | ||
| file which if the detector can not find it at the path it will download it | ||
| from neuralet repository automatically. | ||
|
|
||
| :param config: Is a ConfigEngine instance which provides necessary parameters. | ||
| """ | ||
|
|
||
| def __init__(self, config): | ||
| self.config = config | ||
| # Get the model name from the config | ||
| self.model_name = self.config.get_section_dict('Detector')['Name'] | ||
| # Frames Per Second | ||
| self.fps = None | ||
|
|
||
| self.detection_model = load_model('ped_ssdlite_mobilenet_v3') | ||
|
|
||
| def inference(self, resized_rgb_image): | ||
| """ | ||
| inference function sets input tensor to input image and gets the output. | ||
| The interpreter instance provides corresponding detection output which is used for creating result | ||
| Args: | ||
| resized_rgb_image: uint8 numpy array with shape (img_height, img_width, channels) | ||
|
|
||
| Returns: | ||
| result: a dictionary contains of [{"id": 0, "bbox": [x1, y1, x2, y2], "score":s%}, {...}, {...}, ...] | ||
| """ | ||
| input_image = np.expand_dims(resized_rgb_image, axis=0) | ||
| input_tensor = tf.convert_to_tensor(input_image) | ||
| t_begin = time.perf_counter() | ||
| output_dict = self.detection_model(input_tensor) | ||
| inference_time = time.perf_counter() - t_begin # Seconds | ||
|
|
||
| # Calculate Frames rate (fps) | ||
| self.fps = convert_infr_time_to_fps(inference_time) | ||
|
|
||
| boxes = output_dict['detection_boxes'] | ||
| labels = output_dict['detection_classes'] | ||
| scores = output_dict['detection_scores'] | ||
|
|
||
| class_id = int(self.config.get_section_dict('Detector')['ClassID']) | ||
| score_threshold = float(self.config.get_section_dict('Detector')['MinScore']) | ||
| result = [] | ||
| for i in range(boxes.shape[1]): # number of boxes | ||
| if labels[0, i] == class_id and scores[0, i] > score_threshold: | ||
| result.append({"id": str(class_id) + '-' + str(i), "bbox": boxes[0, i, :], "score": scores[0, i]}) | ||
|
|
||
| return result | ||
34 changes: 19 additions & 15 deletions
34
libs/detectors/x86/mobilenet_ssd.py → libs/detectors/x86/ssd_mobilenet_v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.