From 9774b78a0be40b442090cf853451f21e679a353d Mon Sep 17 00:00:00 2001 From: fcr3 Date: Wed, 7 Aug 2019 17:38:35 -0700 Subject: [PATCH 01/13] Initial commit with signoff Signed-off-by: fcr3 --- networks/ssd_inception_v2/AUTHORS | 2 + networks/ssd_inception_v2/Makefile | 173 +++++++++++++++ networks/ssd_inception_v2/README.md | 64 ++++++ networks/ssd_inception_v2/download_weights.py | 35 ++++ networks/ssd_inception_v2/ssd_inception_v2.py | 198 ++++++++++++++++++ .../ssd_v2_support_inception.json | 62 ++++++ 6 files changed, 534 insertions(+) create mode 100644 networks/ssd_inception_v2/AUTHORS create mode 100644 networks/ssd_inception_v2/Makefile create mode 100644 networks/ssd_inception_v2/README.md create mode 100644 networks/ssd_inception_v2/download_weights.py create mode 100644 networks/ssd_inception_v2/ssd_inception_v2.py create mode 100644 networks/ssd_inception_v2/ssd_v2_support_inception.json diff --git a/networks/ssd_inception_v2/AUTHORS b/networks/ssd_inception_v2/AUTHORS new file mode 100644 index 00000000..4be2c13a --- /dev/null +++ b/networks/ssd_inception_v2/AUTHORS @@ -0,0 +1,2 @@ +Name, email, organization +Flaviano Christian Reyes, flaviano.christian.reyes@intel.com, Intel Corporation diff --git a/networks/ssd_inception_v2/Makefile b/networks/ssd_inception_v2/Makefile new file mode 100644 index 00000000..f6857746 --- /dev/null +++ b/networks/ssd_inception_v2/Makefile @@ -0,0 +1,173 @@ +NCCOMPILE = mo.py +CPU_EXTENSION = $(INTEL_OPENVINO_DIR)/deployment_tools/inference_engine/lib/intel64/libcpu_extension_avx2.so + +YELLOW='\033[1;33m' +NOCOLOR='\033[0m' +RED = '\033[1;31m' + +NETWORK_SCRIPT_FILENAME= mnist_deep.py +GET_NETWORK_SCRIPT = wget -P . https://raw.githubusercontent.com/tensorflow/tensorflow/r1.4/tensorflow/examples/tutorials/mnist/${NETWORK_SCRIPT_FILENAME} + +MNIST_NCS_FILENAME = mnist_deep_mod.py +MNIST_INFERENCE_FILENAME = mnist_deep_inference.py + +GRAPH_FILENAME_BASE = ssd_inception_v2 +GRAPH_DIR_FP32 = ssd_inception_v2_mo_fp32 +GRAPH_DIR_FP16 = ssd_inception_v2_mo_fp16 +GRAPH_FILENAME_BASE_IN_DIR_FP32 = ssd_inception_v2_mo_fp32/frozen_inference_graph.xml +GRAPH_FILENAME_BASE_IN_DIR_FP16 = ssd_inception_v2_mo_fp16/frozen_inference_graph.xml +MO_LABELS = frozen_inference_graph.labels +MO_LABELS_IN_DIR_FP32 = ssd_inception_v2_mo_fp32/frozen_inference_graph.labels +MO_LABELS_IN_DIR_FP16 = ssd_inception_v2_mo_fp16/frozen_inference_graph.labels +MO_INPUT_GRAPH_ARG = --input_model tensorflow_model/frozen_inference_graph.pb +MO_INPUT_PIPELINE = --tensorflow_object_detection_api_pipeline_config tensorflow_model/pipeline.config +MO_INPUT_CUSTOM_OPS = --tensorflow_use_custom_operations_config ssd_v2_support_inception.json +MO_OUTPUT_DIR_FP32 = --output_dir ssd_inception_v2_mo_fp32 +MO_OUTPUT_DIR_FP16 = --output_dir ssd_inception_v2_mo_fp16 + +MODEL_DIR = tensorflow_model +MODEL_PIPELINE_CONFIG = tensorflow_model/pipeline.config +MODEL_PB = tensorflow_model/frozen_inference_graph.pb +MODEL_INFERENCE_PIPELINE_CONFIG = pipeline.config +MODEL_INFERENCE_PB = frozen_inference_graph.pb + +GET_MODEL_PIPELINE = wget -c --no-cache -P ./tensorflow_model https://raw.githubusercontent.com/fcr3/gesture_detection/master/tensorflow_model/${MODEL_INFERENCE_PIPELINE_CONFIG} +GET_MO_MODEL_FP32_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp32 https://raw.githubusercontent.com/fcr3/gesture_detection/master/model_optimized_fp32/${MO_LABELS} +GET_MO_MODEL_FP16_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp16 https://raw.githubusercontent.com/fcr3/gesture_detection/master/model_optimized_fp16/${MO_LABELS} +GET_MODEL_PB = python3 download_weights.py + +RUN_PY_RELATIVE_DIR = ssd_inception_v2.py +TEST_IMAGE_RELATIVE_DIR = ../../data/digit_images +TEST_IMAGE_FILENAME = gesture.jpg + +.PHONY: all +all: deps data compile_model + +.PHONY: deps +deps: get_model + @echo $(YELLOW)"\nMnist: Making dependencies..."$(NOCOLOR) + + +.PHONY: data +data: + @echo $(YELLOW)"\nMnist: Downloading required data - No data needed."$(NOCOLOR) + + +.PHONY: get_model +get_model: + @echo $(YELLOW)"\nSSD Inception V2: Downloading model files..."$(NOCOLOR) + @if [ -e ${MODEL_PIPELINE_CONFIG} ] ; \ + then \ + echo "model file ${MODEL_PIPELINE_CONFIG} already exists, skipping download"; \ + else \ + echo "Downloading ${MODEL_INFERENCE_PIPELINE_CONFIG} file"; \ + ${GET_MODEL_PIPELINE}; \ + if [ -e ${MODEL_PIPELINE_CONFIG} ] ; \ + then \ + echo "download ${MODEL_INFERENCE_PIPELINE_CONFIG} done. Downloaded to /tensorflow_model."; \ + else \ + echo "***\nError - Could not download ${MODEL_INFERENCE_PIPELINE_CONFIG}. Check network and proxy settings \n***\n"; \ + exit 1; \ + fi ; \ + fi + @if [ -e ${MODEL_PB} ] ; \ + then \ + echo "model file ${MODEL_PB} already exists, skipping download"; \ + else \ + echo "Downloading ${MODEL_INFERENCE_PB} file" ; \ + ${GET_MODEL_PB} ; \ + if [ -e ${MODEL_PB} ] ; \ + then \ + echo "download ${MODEL_INFERENCE_PB} done. Downloaded to /tensorflow_model."; \ + else \ + echo "***\nError - Could not download ${MODEL_INFERENCE_PB}. Check network and proxy settings \n***\n"; \ + exit 1; \ + fi ; \ + fi + + +.PHONY: train +train: + @echo $(YELLOW) "\nSSD Inception V2: Training model... NOT YET IMPLEMENTED" $(NOCOLOR); + + +.PHONY: compile_model +compile_model: get_model + @echo $(YELLOW)"\nSSD Inception V2: Compiling model to IR..."$(NOCOLOR) + @if [ -e ${GRAPH_FILENAME_BASE_IN_DIR_FP32} ] ; \ + then \ + echo "compiled FP32 model file already exists, skipping compile."; \ + else \ + echo "Compiling FP32 model..."; \ + mkdir ssd_inception_v2_mo_fp32 ; \ + ${NCCOMPILE} --data_type=FP32 --reverse_input_channels ${MO_INPUT_GRAPH_ARG} ${MO_INPUT_PIPELINE} ${MO_INPUT_CUSTOM_OPS} ${MO_OUTPUT_DIR_FP32} || (echo $(RED)"Make sure to set the OpenVINO environment variables using the "$(YELLOW)"setupvars.sh"$(RED)" script found in /bin/ folder."$(NOCOLOR); exit 1;); \ + fi + @if [ -e ${GRAPH_FILENAME_BASE_IN_DIR_FP16} ] ; \ + then \ + echo "compiled FP16 model file already exists, skipping compile."; \ + else \ + echo "Compiling FP16 model..."; \ + mkdir ssd_inception_v2_mo_fp16 ; \ + ${NCCOMPILE} --data_type=FP16 --reverse_input_channels ${MO_INPUT_GRAPH_ARG} ${MO_INPUT_PIPELINE} ${MO_INPUT_CUSTOM_OPS} ${MO_OUTPUT_DIR_FP16} || (echo $(RED)"Make sure to set the OpenVINO environment variables using the "$(YELLOW)"setupvars.sh"$(RED)" script found in /bin/ folder."$(NOCOLOR); exit 1;); \ + fi + @if [ -e ${MO_LABELS_IN_DIR_FP32} ] ; \ + then \ + echo "compiled FP32 model labels already exist, skipping network request."; \ + else \ + echo "Grabbing labels for FP32 model..."; \ + ${GET_MO_MODEL_FP32_LABELS}; \ + fi + @if [ -e ${MO_LABELS_IN_DIR_FP16} ] ; \ + then \ + echo "compiled FP16 model labels already exist, skipping network request."; \ + else \ + echo "Grabbing labels for FP16 model..."; \ + ${GET_MO_MODEL_FP16_LABELS} ;\ + fi + + +.PHONY: install-reqs +install-reqs: + @echo $(YELLOW)"\nSSD Inception V2: Checking application requirements...\n"$(NOCOLOR) + @echo "No requirements needed." + + +.PHONY: run_FP16 +run_FP16: install-reqs deps data compile_model + @echo $(YELLOW) "\nSSD Inception V2: Running Python sample..." $(NOCOLOR) + python3 $(RUN_PY_RELATIVE_DIR) -i 'cam' -m ${GRAPH_FILENAME_BASE_IN_DIR_FP16} --labels ${MO_LABELS_IN_DIR_FP16} -d MYRIAD + + +.PHONY: run_FP32 +run_FP32: install-reqs deps data compile_model + @echo $(YELLOW) "\nSSD Inception V2: Running Python sample..." $(NOCOLOR) + python3 $(RUN_PY_RELATIVE_DIR) -i 'cam' -m ${GRAPH_FILENAME_BASE_IN_DIR_FP32} -l ${CPU_EXTENSION} --labels ${MO_LABELS_IN_DIR_FP32} + + +.PHONY: run +run: run_py + + +.PHONY: run_py +run_py: install-reqs deps data compile_model run_FP16 + + +.PHONY: help +help: + @echo "\nPossible make targets" + @echo $(YELLOW)" make help " $(NOCOLOR) "- Shows this message."; + @echo $(YELLOW)" make run " $(NOCOLOR) "- Runs the Python example."; + @echo $(YELLOW)" make run_py " $(NOCOLOR) "- Runs the Python example."; + @echo $(YELLOW)" make all " $(NOCOLOR) "- Makes everything needed to run, but doesn't run the sample."; + @echo $(YELLOW)" make compile_model " $(NOCOLOR) "- Runs model compiler for the network."; + @echo $(YELLOW)" make model " $(NOCOLOR) "- Downloads the model files."; + @echo $(YELLOW)" make data " $(NOCOLOR) "- Downloads required data."; + @echo $(YELLOW)" make deps " $(NOCOLOR) "- Makes dependencies for project, prepares model etc."; + @echo $(YELLOW)" make clean " $(NOCOLOR) "- Removes all the temporary files that are created by the Makefile."; + @echo $(YELLOW)" make train " $(NOCOLOR) "- Train a mnist model."; + +clean: clean + @echo $(YELLOW)"\nSSD Inception V2: Cleaning up files..."$(NOCOLOR) + rm -rf ${GRAPH_DIR_FP32} + rm -rf ${GRAPH_DIR_FP16} + rm -rf ${MODEL_DIR} diff --git a/networks/ssd_inception_v2/README.md b/networks/ssd_inception_v2/README.md new file mode 100644 index 00000000..42c32a80 --- /dev/null +++ b/networks/ssd_inception_v2/README.md @@ -0,0 +1,64 @@ +# SSD Inception V2 + +## Introduction +The SSD Inception V2 network can be used to detect a number of objects specified by a particular training set. This model in particular can detection the following gestures: +- point up +- point down +- point left +- point right +- exposed palm +- closed fist with exposed bottom palm +- fist with exposed knuckles. + +The provided Makefile does the following: +1. Downloads a trained model +2. Downloads test images +3. Compiles the network using the OpenVINO Model Optimizer +4. There is a python example (run.py) which runs an inference for all of the test images to show how to use the network with the OpenVINO toolkit. + +This network is based on the [TensorFlow Object Detection API SSD Inception V2 model.](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md) The model was modified, trained, and saved in order to be compatible with the OpenVINO toolkit. + + +## Running this example + +``` +make run +``` +The example runs inference using a video stream taken from an existing camera device. Bounding boxes and their associated probabilities and classifications are rendered on frames of the video stream and presented on a OpenCV frame. + + +## Makefile +Provided Makefile describes various targets that help with the above mentioned tasks. + +### make run +Runs a sample application with the FP16 network. Users must plug in their Intel Neural Compute Stick 2 in order to successfully run this application. + +### make run_py +Runs the `ssd_inception_v2.py` script which takes in a video stream from an existing camera, runs inference on each frame, and renders the output to the user. + +### make run_FP32 +Runs the `ssd_inception_v2.py` script with the FP32 network. Note that this application will only run successfully on CPUs that OpenVINO supports. + +### make run_FP16 +Runs the `ssd_inception_v2.py` script with the FP16 network. Users must plug in their Intel Neural Compute Stick 2 in order to successfully run this application. + +### make train +**TO BE IMPLEMENTED.** Trains a SSD Inception V2 model using the Tensorflow Object Detection API given an `Annotations` and `JPEGImages` folder containing .xml and .jpg images, respectively, for training. Training is not necessary since the sample will download a pre-trained model. This option allows for the user to further refine the SSD Inception V2 model if they so desire. + +### make help +Shows makefile possible targets and brief descriptions. + +### make all +Makes the follow items: deps, data, compile_model. + +### make compile_model +Compiles the trained model to generate a OpenVINO IR file. This file can be loaded on the Neural Compute Stick for inferencing. + +### make get_model +Downloads the trained model. + +### deps +Downloads and prepares a trained network for compilation with the OpenVINO toolkit. + +### make clean +Removes all the temporary and target files that are created by the Makefile. diff --git a/networks/ssd_inception_v2/download_weights.py b/networks/ssd_inception_v2/download_weights.py new file mode 100644 index 00000000..18210966 --- /dev/null +++ b/networks/ssd_inception_v2/download_weights.py @@ -0,0 +1,35 @@ +import requests + +def download_file_from_google_drive(id, destination): + URL = "https://docs.google.com/uc?export=download" + + session = requests.Session() + + response = session.get(URL, params = { 'id' : id }, stream = True) + token = get_confirm_token(response) + + if token: + params = { 'id' : id, 'confirm' : token } + response = session.get(URL, params = params, stream = True) + + save_response_content(response, destination) + +def get_confirm_token(response): + for key, value in response.cookies.items(): + if key.startswith('download_warning'): + return value + + return None + +def save_response_content(response, destination): + CHUNK_SIZE = 32768 + + with open(destination, "wb") as f: + for chunk in response.iter_content(CHUNK_SIZE): + if chunk: # filter out keep-alive new chunks + f.write(chunk) + +if __name__ == "__main__": + pb_file_id = '1TuK2SMtkFlT5SRrhjWCz4Z5xXE-gcRDd' + destination = './tensorflow_model/frozen_inference_graph.pb' + download_file_from_google_drive(pb_file_id, destination) diff --git a/networks/ssd_inception_v2/ssd_inception_v2.py b/networks/ssd_inception_v2/ssd_inception_v2.py new file mode 100644 index 00000000..66ca6875 --- /dev/null +++ b/networks/ssd_inception_v2/ssd_inception_v2.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python +""" + Copyright (C) 2018-2019 Intel Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + NOTICE: + The exit key to terminate the program has been changed from CTRL+C to 'q'. + In addition, spacings/variables may have changed but maintain the same functionality as before. +""" + +from __future__ import print_function +import sys +import os +from argparse import ArgumentParser, SUPPRESS +import cv2 +import time +import logging as log +from openvino.inference_engine import IENetwork, IEPlugin + + +def build_argparser(): + parser = ArgumentParser(add_help=False) + args = parser.add_argument_group('Options') + args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.') + args.add_argument("-m", "--model", help="Required. Path to an .xml file with a trained model.", + required=True, type=str) + args.add_argument("-i", "--input", + help="Required. Path to video file or image. 'cam' for capturing video stream from camera", + required=True, type=str) + args.add_argument("-l", "--cpu_extension", + help="Optional. Required for CPU custom layers. Absolute path to a shared library with the " + "kernels implementations.", type=str, default=None) + args.add_argument("-pp", "--plugin_dir", help="Optional. Path to a plugin folder", type=str, default=None) + args.add_argument("-d", "--device", + help="Optional. Specify the target device to infer on; CPU, GPU, FPGA, HDDL or MYRIAD is " + "acceptable. The demo will look for a suitable plugin for device specified. " + "Default value is CPU", default="CPU", type=str) + args.add_argument("--labels", help="Optional. Path to labels mapping file", default=None, type=str) + args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering", + default=0.5, type=float) + + return parser + + +def main(): + log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout) + args = build_argparser().parse_args() + model_xml = args.model + model_bin = os.path.splitext(model_xml)[0] + ".bin" + # Plugin initialization for specified device and load extensions library if specified + log.info("Initializing plugin for {} device...".format(args.device)) + plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir) + if args.cpu_extension and 'CPU' in args.device: + plugin.add_cpu_extension(args.cpu_extension) + # Read IR + log.info("Reading IR...") + net = IENetwork(model=model_xml, weights=model_bin) + + if plugin.device == "CPU": + supported_layers = plugin.get_supported_layers(net) + not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers] + if len(not_supported_layers) != 0: + log.error("Following layers are not supported by the plugin for specified device {}:\n {}". + format(plugin.device, ', '.join(not_supported_layers))) + log.error("Please try to specify cpu extensions library path in demo's command line parameters using -l " + "or --cpu_extension command line argument") + sys.exit(1) + assert len(net.inputs.keys()) == 1, "Demo supports only single input topologies" + assert len(net.outputs) == 1, "Demo supports only single output topologies" + input_blob = next(iter(net.inputs)) + out_blob = next(iter(net.outputs)) + log.info("Loading IR to the plugin...") + exec_net = plugin.load(network=net, num_requests=2) + # Read and pre-process input image + n, c, h, w = net.inputs[input_blob].shape + + log.info("Net input shape: " + str((n, c, h, w))) + log.info("Net output shape: " + str(net.outputs[out_blob].shape)) + + del net + if args.input == 'cam': + input_stream = 0 + else: + input_stream = args.input + assert os.path.isfile(args.input), "Specified input file doesn't exist" + if args.labels: + with open(args.labels, 'r') as f: + labels_map = [x.strip() for x in f] + else: + labels_map = None + + cap = cv2.VideoCapture(input_stream) + + cur_request_id = 0 + next_request_id = 1 + + log.info("Starting inference in async mode...") + log.info("To switch between sync and async modes press Tab button") + log.info("To stop the demo execution press Esc button") + is_async_mode = True + render_time = 0 + ret, frame = cap.read() + + print("To close the application, press 'q'") + while cap.isOpened(): + if is_async_mode: + ret, next_frame = cap.read() + else: + ret, frame = cap.read() + if not ret: + break + + initial_w = cap.get(3) + initial_h = cap.get(4) + + # Main sync point: + # in the truly Async mode we start the NEXT infer request, while waiting for the CURRENT to complete + # in the regular mode we start the CURRENT request and immediately wait for it's completion + inf_start = time.time() + if is_async_mode: + in_frame = cv2.resize(next_frame, (w, h)) + in_frame = in_frame.transpose((2, 0, 1)) # Change data layout from HWC to CHW + in_frame = in_frame.reshape((n, c, h, w)) + exec_net.start_async(request_id=next_request_id, inputs={input_blob: in_frame}) + else: + in_frame = cv2.resize(frame, (w, h)) + in_frame = in_frame.transpose((2, 0, 1)) # Change data layout from HWC to CHW + in_frame = in_frame.reshape((n, c, h, w)) + exec_net.start_async(request_id=cur_request_id, inputs={input_blob: in_frame}) + if exec_net.requests[cur_request_id].wait(-1) == 0: + inf_end = time.time() + det_time = inf_end - inf_start + + # Parse detection results of the current request, only need one so choose max prob + res = exec_net.requests[cur_request_id].outputs[out_blob] + for obj in res[0][0]: + # Draw only objects when probability more than specified threshold + if obj[2] > args.prob_threshold: + best_proposal = obj + + xmin = int(best_proposal[3] * initial_w) + ymin = int(best_proposal[4] * initial_h) + xmax = int(best_proposal[5] * initial_w) + ymax = int(best_proposal[6] * initial_h) + class_id = int(best_proposal[1]) + + # Draw box and label\class_id + color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 5, 255)) + cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2) + + det_label = labels_map[class_id - 1] if labels_map else str(class_id) + label_and_prob = det_label + ", " + str(obj[2] * 100) + "%" + cv2.putText(frame, label_and_prob, (xmin, ymin - 7), cv2.FONT_HERSHEY_COMPLEX, 0.6, color, 1) + + # Draw performance stats + inf_time_message = "Inference time: N\A for async mode" if is_async_mode else \ + "Inference time: {:.3f} ms".format(det_time * 1000) + render_time_message = "OpenCV rendering time: {:.3f} ms".format(render_time * 1000) + async_mode_message = "Async mode is on. Processing request {}".format(cur_request_id) if is_async_mode else \ + "Async mode is off. Processing request {}".format(cur_request_id) + + cv2.putText(frame, inf_time_message, (15, 15), cv2.FONT_HERSHEY_COMPLEX, 0.5, (200, 10, 10), 1) + cv2.putText(frame, render_time_message, (15, 30), cv2.FONT_HERSHEY_COMPLEX, 0.5, (10, 10, 200), 1) + cv2.putText(frame, async_mode_message, (10, int(initial_h - 20)), cv2.FONT_HERSHEY_COMPLEX, 0.5, + (10, 10, 200), 1) + + render_start = time.time() + cv2.imshow("Detection Results", frame) + render_end = time.time() + render_time = render_end - render_start + + if is_async_mode: + cur_request_id, next_request_id = next_request_id, cur_request_id + frame = next_frame + + key = cv2.waitKey(1) + if (key & 0xFF) == ord('q'): + break + if (9 == key): + is_async_mode = not is_async_mode + log.info("Switched to {} mode".format("async" if is_async_mode else "sync")) + + cv2.destroyAllWindows() + + +if __name__ == '__main__': + sys.exit(main() or 0) diff --git a/networks/ssd_inception_v2/ssd_v2_support_inception.json b/networks/ssd_inception_v2/ssd_v2_support_inception.json new file mode 100644 index 00000000..bb159515 --- /dev/null +++ b/networks/ssd_inception_v2/ssd_v2_support_inception.json @@ -0,0 +1,62 @@ +[ + { + "custom_attributes": { + }, + "id": "ObjectDetectionAPIPreprocessorReplacement", + "inputs": [ + [ + { + "node": "map/Shape$", + "port": 0 + }, + { + "node": "map/TensorArrayUnstack/Shape$", + "port": 0 + }, + { + "node": "map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3$", + "port": 2 + } + ] + ], + "instances": [ + ".*Preprocessor/" + ], + "match_kind": "scope", + "outputs": [ + { + "node": "sub$", + "port": 0 + }, + { + "node": "map/TensorArrayStack_1/TensorArrayGatherV3$", + "port": 0 + } + ] + }, + { + "custom_attributes": { + "code_type": "caffe.PriorBoxParameter.CENTER_SIZE", + "pad_mode": "caffe.ResizeParameter.CONSTANT", + "resize_mode": "caffe.ResizeParameter.WARP" + }, + "id": "ObjectDetectionAPISSDPostprocessorReplacement", + "include_inputs_to_sub_graph": true, + "include_outputs_to_sub_graph": true, + "instances": { + "end_points": [ + "detection_boxes", + "detection_scores", + "num_detections" + ], + "start_points": [ + "Postprocessor/Shape", + "Postprocessor/scale_logits", + "Postprocessor/Tile", + "Postprocessor/Reshape_1", + "Postprocessor/Cast" + ] + }, + "match_kind": "points" + } +] From c182a2a18b87181bd88cc548e8873aa8bfa22b11 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Wed, 7 Aug 2019 18:47:13 -0700 Subject: [PATCH 02/13] Renaming files for multiple ssd inception v2 models Signed-off-by: fcr3 --- .../AUTHORS | 0 .../Makefile | 39 ++++++++----------- .../README.md | 0 .../download_weights.py | 0 .../ssd_inception_v2_gesture.py} | 0 .../ssd_v2_support_inception.json | 0 6 files changed, 16 insertions(+), 23 deletions(-) rename networks/{ssd_inception_v2 => ssd_inception_v2_gesture}/AUTHORS (100%) rename networks/{ssd_inception_v2 => ssd_inception_v2_gesture}/Makefile (80%) rename networks/{ssd_inception_v2 => ssd_inception_v2_gesture}/README.md (100%) rename networks/{ssd_inception_v2 => ssd_inception_v2_gesture}/download_weights.py (100%) rename networks/{ssd_inception_v2/ssd_inception_v2.py => ssd_inception_v2_gesture/ssd_inception_v2_gesture.py} (100%) rename networks/{ssd_inception_v2 => ssd_inception_v2_gesture}/ssd_v2_support_inception.json (100%) diff --git a/networks/ssd_inception_v2/AUTHORS b/networks/ssd_inception_v2_gesture/AUTHORS similarity index 100% rename from networks/ssd_inception_v2/AUTHORS rename to networks/ssd_inception_v2_gesture/AUTHORS diff --git a/networks/ssd_inception_v2/Makefile b/networks/ssd_inception_v2_gesture/Makefile similarity index 80% rename from networks/ssd_inception_v2/Makefile rename to networks/ssd_inception_v2_gesture/Makefile index f6857746..987296d1 100644 --- a/networks/ssd_inception_v2/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -5,29 +5,23 @@ YELLOW='\033[1;33m' NOCOLOR='\033[0m' RED = '\033[1;31m' -NETWORK_SCRIPT_FILENAME= mnist_deep.py -GET_NETWORK_SCRIPT = wget -P . https://raw.githubusercontent.com/tensorflow/tensorflow/r1.4/tensorflow/examples/tutorials/mnist/${NETWORK_SCRIPT_FILENAME} - -MNIST_NCS_FILENAME = mnist_deep_mod.py -MNIST_INFERENCE_FILENAME = mnist_deep_inference.py - GRAPH_FILENAME_BASE = ssd_inception_v2 GRAPH_DIR_FP32 = ssd_inception_v2_mo_fp32 GRAPH_DIR_FP16 = ssd_inception_v2_mo_fp16 -GRAPH_FILENAME_BASE_IN_DIR_FP32 = ssd_inception_v2_mo_fp32/frozen_inference_graph.xml -GRAPH_FILENAME_BASE_IN_DIR_FP16 = ssd_inception_v2_mo_fp16/frozen_inference_graph.xml +GRAPH_FILENAME_BASE_IN_DIR_FP32 = ${GRAPH_DIR_FP32}/frozen_inference_graph.xml +GRAPH_FILENAME_BASE_IN_DIR_FP16 = ${GRAPH_DIR_FP16}/frozen_inference_graph.xml MO_LABELS = frozen_inference_graph.labels -MO_LABELS_IN_DIR_FP32 = ssd_inception_v2_mo_fp32/frozen_inference_graph.labels +MO_LABELS_IN_DIR_FP32 = ${GRAPH_DIR_FP32}/frozen_inference_graph.labels MO_LABELS_IN_DIR_FP16 = ssd_inception_v2_mo_fp16/frozen_inference_graph.labels MO_INPUT_GRAPH_ARG = --input_model tensorflow_model/frozen_inference_graph.pb MO_INPUT_PIPELINE = --tensorflow_object_detection_api_pipeline_config tensorflow_model/pipeline.config MO_INPUT_CUSTOM_OPS = --tensorflow_use_custom_operations_config ssd_v2_support_inception.json -MO_OUTPUT_DIR_FP32 = --output_dir ssd_inception_v2_mo_fp32 -MO_OUTPUT_DIR_FP16 = --output_dir ssd_inception_v2_mo_fp16 +MO_OUTPUT_DIR_FP32 = --output_dir ${GRAPH_DIR_FP32} +MO_OUTPUT_DIR_FP16 = --output_dir ${GRAPH_DIR_FP16} MODEL_DIR = tensorflow_model -MODEL_PIPELINE_CONFIG = tensorflow_model/pipeline.config -MODEL_PB = tensorflow_model/frozen_inference_graph.pb +MODEL_PIPELINE_CONFIG = ${MODEL_DIR}/pipeline.config +MODEL_PB = ${MODEL_DIR}/frozen_inference_graph.pb MODEL_INFERENCE_PIPELINE_CONFIG = pipeline.config MODEL_INFERENCE_PB = frozen_inference_graph.pb @@ -36,26 +30,25 @@ GET_MO_MODEL_FP32_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp32 http GET_MO_MODEL_FP16_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp16 https://raw.githubusercontent.com/fcr3/gesture_detection/master/model_optimized_fp16/${MO_LABELS} GET_MODEL_PB = python3 download_weights.py -RUN_PY_RELATIVE_DIR = ssd_inception_v2.py -TEST_IMAGE_RELATIVE_DIR = ../../data/digit_images -TEST_IMAGE_FILENAME = gesture.jpg +RUN_PY_RELATIVE_DIR = ssd_inception_v2_gesture.py + .PHONY: all all: deps data compile_model .PHONY: deps deps: get_model - @echo $(YELLOW)"\nMnist: Making dependencies..."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Making dependencies..."$(NOCOLOR) .PHONY: data data: - @echo $(YELLOW)"\nMnist: Downloading required data - No data needed."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Downloading required data - No data needed."$(NOCOLOR) .PHONY: get_model get_model: - @echo $(YELLOW)"\nSSD Inception V2: Downloading model files..."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Downloading model files..."$(NOCOLOR) @if [ -e ${MODEL_PIPELINE_CONFIG} ] ; \ then \ echo "model file ${MODEL_PIPELINE_CONFIG} already exists, skipping download"; \ @@ -88,12 +81,12 @@ get_model: .PHONY: train train: - @echo $(YELLOW) "\nSSD Inception V2: Training model... NOT YET IMPLEMENTED" $(NOCOLOR); + @echo $(YELLOW) "\nSSD Inception V2 Geseture: Training model... NOT YET IMPLEMENTED" $(NOCOLOR); .PHONY: compile_model compile_model: get_model - @echo $(YELLOW)"\nSSD Inception V2: Compiling model to IR..."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Compiling model to IR..."$(NOCOLOR) @if [ -e ${GRAPH_FILENAME_BASE_IN_DIR_FP32} ] ; \ then \ echo "compiled FP32 model file already exists, skipping compile."; \ @@ -128,7 +121,7 @@ compile_model: get_model .PHONY: install-reqs install-reqs: - @echo $(YELLOW)"\nSSD Inception V2: Checking application requirements...\n"$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Checking application requirements...\n"$(NOCOLOR) @echo "No requirements needed." @@ -167,7 +160,7 @@ help: @echo $(YELLOW)" make train " $(NOCOLOR) "- Train a mnist model."; clean: clean - @echo $(YELLOW)"\nSSD Inception V2: Cleaning up files..."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Cleaning up files..."$(NOCOLOR) rm -rf ${GRAPH_DIR_FP32} rm -rf ${GRAPH_DIR_FP16} rm -rf ${MODEL_DIR} diff --git a/networks/ssd_inception_v2/README.md b/networks/ssd_inception_v2_gesture/README.md similarity index 100% rename from networks/ssd_inception_v2/README.md rename to networks/ssd_inception_v2_gesture/README.md diff --git a/networks/ssd_inception_v2/download_weights.py b/networks/ssd_inception_v2_gesture/download_weights.py similarity index 100% rename from networks/ssd_inception_v2/download_weights.py rename to networks/ssd_inception_v2_gesture/download_weights.py diff --git a/networks/ssd_inception_v2/ssd_inception_v2.py b/networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py similarity index 100% rename from networks/ssd_inception_v2/ssd_inception_v2.py rename to networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py diff --git a/networks/ssd_inception_v2/ssd_v2_support_inception.json b/networks/ssd_inception_v2_gesture/ssd_v2_support_inception.json similarity index 100% rename from networks/ssd_inception_v2/ssd_v2_support_inception.json rename to networks/ssd_inception_v2_gesture/ssd_v2_support_inception.json From 23be1fe5374b477e3297b8dd688bffbc46146a8e Mon Sep 17 00:00:00 2001 From: fcr3 Date: Wed, 7 Aug 2019 18:58:06 -0700 Subject: [PATCH 03/13] Edited README.md Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/README.md b/networks/ssd_inception_v2_gesture/README.md index 42c32a80..486a05cf 100644 --- a/networks/ssd_inception_v2_gesture/README.md +++ b/networks/ssd_inception_v2_gesture/README.md @@ -1,7 +1,7 @@ # SSD Inception V2 ## Introduction -The SSD Inception V2 network can be used to detect a number of objects specified by a particular training set. This model in particular can detection the following gestures: +The SSD Inception V2 network can be used to detect a number of objects specified by a particular training set. This model in particular can detect the following gestures: - point up - point down - point left @@ -34,13 +34,13 @@ Provided Makefile describes various targets that help with the above mentioned t Runs a sample application with the FP16 network. Users must plug in their Intel Neural Compute Stick 2 in order to successfully run this application. ### make run_py -Runs the `ssd_inception_v2.py` script which takes in a video stream from an existing camera, runs inference on each frame, and renders the output to the user. +Runs the `ssd_inception_v2_gesture.py` script which takes in a video stream from an existing camera, runs inference on each frame, and renders the output to the user. ### make run_FP32 -Runs the `ssd_inception_v2.py` script with the FP32 network. Note that this application will only run successfully on CPUs that OpenVINO supports. +Runs the `ssd_inception_v2_gesture.py` script with the FP32 network. Note that this application will only run successfully on CPUs that OpenVINO supports. ### make run_FP16 -Runs the `ssd_inception_v2.py` script with the FP16 network. Users must plug in their Intel Neural Compute Stick 2 in order to successfully run this application. +Runs the `ssd_inception_v2_gesture.py` script with the FP16 network. Users must plug in their Intel Neural Compute Stick 2 in order to successfully run this application. ### make train **TO BE IMPLEMENTED.** Trains a SSD Inception V2 model using the Tensorflow Object Detection API given an `Annotations` and `JPEGImages` folder containing .xml and .jpg images, respectively, for training. Training is not necessary since the sample will download a pre-trained model. This option allows for the user to further refine the SSD Inception V2 model if they so desire. From c3ae7aaa13c66572942a96df7c1f3e8b812c8e71 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Thu, 8 Aug 2019 10:12:49 -0700 Subject: [PATCH 04/13] Edited files to comply with comments Signed-off-by: fcr3 --- .../APACHE_2.0_LICENSE.md | 202 ++++++++++++++++++ .../ssd_inception_v2_gesture/ATTRIBUTIONS.md | 4 + networks/ssd_inception_v2_gesture/AUTHORS | 5 +- networks/ssd_inception_v2_gesture/README.md | 5 + .../download_weights.py | 44 ++-- .../ssd_inception_v2_gesture.py | 7 +- 6 files changed, 233 insertions(+), 34 deletions(-) create mode 100644 networks/ssd_inception_v2_gesture/APACHE_2.0_LICENSE.md create mode 100644 networks/ssd_inception_v2_gesture/ATTRIBUTIONS.md diff --git a/networks/ssd_inception_v2_gesture/APACHE_2.0_LICENSE.md b/networks/ssd_inception_v2_gesture/APACHE_2.0_LICENSE.md new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/networks/ssd_inception_v2_gesture/APACHE_2.0_LICENSE.md @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/networks/ssd_inception_v2_gesture/ATTRIBUTIONS.md b/networks/ssd_inception_v2_gesture/ATTRIBUTIONS.md new file mode 100644 index 00000000..bb876060 --- /dev/null +++ b/networks/ssd_inception_v2_gesture/ATTRIBUTIONS.md @@ -0,0 +1,4 @@ +# Attributions + +## Code Sample Credit +The ssd_inception_v2_gesture.py code is provided by the publishing organization Intel Corporation via the [APACHE_2.0_LICENSE.md](./APACHE_2.0_LICENSE.md). diff --git a/networks/ssd_inception_v2_gesture/AUTHORS b/networks/ssd_inception_v2_gesture/AUTHORS index 4be2c13a..94919961 100644 --- a/networks/ssd_inception_v2_gesture/AUTHORS +++ b/networks/ssd_inception_v2_gesture/AUTHORS @@ -1,2 +1,3 @@ -Name, email, organization -Flaviano Christian Reyes, flaviano.christian.reyes@intel.com, Intel Corporation +Name, email, organization, description +Flaviano Christian Reyes, flaviano.christian.reyes@intel.com, Intel Corporation, Wrote all files other than ssd_inception_v2_gesture.py +Intel Corporation, , Intel Corporation, Wrote ssd_inception_v2_gesture.py diff --git a/networks/ssd_inception_v2_gesture/README.md b/networks/ssd_inception_v2_gesture/README.md index 486a05cf..b4104011 100644 --- a/networks/ssd_inception_v2_gesture/README.md +++ b/networks/ssd_inception_v2_gesture/README.md @@ -62,3 +62,8 @@ Downloads and prepares a trained network for compilation with the OpenVINO toolk ### make clean Removes all the temporary and target files that are created by the Makefile. + +## Credits + +## Attributions +`ssd_inception_v2_gesture.py` is provided per the ATTRIBUTIONS.md file. The rest of the project is provided via the license in the ncappzoo repository's base directory. diff --git a/networks/ssd_inception_v2_gesture/download_weights.py b/networks/ssd_inception_v2_gesture/download_weights.py index 18210966..63550004 100644 --- a/networks/ssd_inception_v2_gesture/download_weights.py +++ b/networks/ssd_inception_v2_gesture/download_weights.py @@ -1,35 +1,23 @@ import requests -def download_file_from_google_drive(id, destination): - URL = "https://docs.google.com/uc?export=download" - - session = requests.Session() - - response = session.get(URL, params = { 'id' : id }, stream = True) - token = get_confirm_token(response) - - if token: - params = { 'id' : id, 'confirm' : token } - response = session.get(URL, params = params, stream = True) - - save_response_content(response, destination) - -def get_confirm_token(response): - for key, value in response.cookies.items(): - if key.startswith('download_warning'): - return value +def main(): + pb_file_id = '1TuK2SMtkFlT5SRrhjWCz4Z5xXE-gcRDd' + file_to_write = './tensorflow_model/frozen_inference_graph.pb' + drive_url = "https://docs.google.com/uc?export=download" - return None + req_session = requests.Session() + session_res = req_session.get(drive_url, params = { 'id' : pb_file_id }, stream = True) -def save_response_content(response, destination): - CHUNK_SIZE = 32768 + for k, v in session_res.cookies.items(): + if k.startswith('download_warning'): + params = { 'id' : pb_file_id, 'confirm' : v } + session_res = session_res.get(drive_url, params = params, stream = True) + break - with open(destination, "wb") as f: - for chunk in response.iter_content(CHUNK_SIZE): - if chunk: # filter out keep-alive new chunks - f.write(chunk) + size = 32768 + with open(file_to_write, "wb") as f: + for packet in session_res.iter_content(size): + f.write(packet) if packet else None if __name__ == "__main__": - pb_file_id = '1TuK2SMtkFlT5SRrhjWCz4Z5xXE-gcRDd' - destination = './tensorflow_model/frozen_inference_graph.pb' - download_file_from_google_drive(pb_file_id, destination) + main() diff --git a/networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py b/networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py index 66ca6875..c3d830bd 100644 --- a/networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py +++ b/networks/ssd_inception_v2_gesture/ssd_inception_v2_gesture.py @@ -14,9 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. - NOTICE: - The exit key to terminate the program has been changed from CTRL+C to 'q'. - In addition, spacings/variables may have changed but maintain the same functionality as before. + NOTICE: (all notices will be listed here and found as NOTICE comments in the line of.) + Line 187: The exit key to terminate the program has been changed from CTRL+C to 'q'. """ from __future__ import print_function @@ -185,7 +184,7 @@ def main(): frame = next_frame key = cv2.waitKey(1) - if (key & 0xFF) == ord('q'): + if (key & 0xFF) == ord('q'): # NOTICE: Changed exit key to 'q', not 'CTRL + C' break if (9 == key): is_async_mode = not is_async_mode From 4682bf7cd92ab2b384cf0df7e5d6efdedff7b7fa Mon Sep 17 00:00:00 2001 From: fcr3 Date: Thu, 8 Aug 2019 12:31:28 -0700 Subject: [PATCH 05/13] Edits to Makefile and README.md Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 12 +++++++----- networks/ssd_inception_v2_gesture/README.md | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index 987296d1..53e3b5f7 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -5,7 +5,7 @@ YELLOW='\033[1;33m' NOCOLOR='\033[0m' RED = '\033[1;31m' -GRAPH_FILENAME_BASE = ssd_inception_v2 +GRAPH_FILENAME_BASE = ssd_inception_v2_food GRAPH_DIR_FP32 = ssd_inception_v2_mo_fp32 GRAPH_DIR_FP16 = ssd_inception_v2_mo_fp16 GRAPH_FILENAME_BASE_IN_DIR_FP32 = ${GRAPH_DIR_FP32}/frozen_inference_graph.xml @@ -38,12 +38,12 @@ all: deps data compile_model .PHONY: deps deps: get_model - @echo $(YELLOW)"\nSSD Inception V2 Gesture: Making dependencies..."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Making dependencies... No extra dependencies needed."$(NOCOLOR) .PHONY: data data: - @echo $(YELLOW)"\nSSD Inception V2 Gesture: Downloading required data - No data needed."$(NOCOLOR) + @echo $(YELLOW)"\nSSD Inception V2 Gesture: Downloading required data... No data needed."$(NOCOLOR) .PHONY: get_model @@ -151,13 +151,15 @@ help: @echo $(YELLOW)" make help " $(NOCOLOR) "- Shows this message."; @echo $(YELLOW)" make run " $(NOCOLOR) "- Runs the Python example."; @echo $(YELLOW)" make run_py " $(NOCOLOR) "- Runs the Python example."; + @echo $(YELLOW)" make run_FP16 " $(NOCOLOR) "- Runs the Python example with FP16 model."; + @echo $(YELLOW)" make run_FP32 " $(NOCOLOR) "- Runs the Python example with FP32 model."; @echo $(YELLOW)" make all " $(NOCOLOR) "- Makes everything needed to run, but doesn't run the sample."; @echo $(YELLOW)" make compile_model " $(NOCOLOR) "- Runs model compiler for the network."; - @echo $(YELLOW)" make model " $(NOCOLOR) "- Downloads the model files."; + @echo $(YELLOW)" make get_model " $(NOCOLOR) "- Downloads the model files."; @echo $(YELLOW)" make data " $(NOCOLOR) "- Downloads required data."; @echo $(YELLOW)" make deps " $(NOCOLOR) "- Makes dependencies for project, prepares model etc."; @echo $(YELLOW)" make clean " $(NOCOLOR) "- Removes all the temporary files that are created by the Makefile."; - @echo $(YELLOW)" make train " $(NOCOLOR) "- Train a mnist model."; + @echo $(YELLOW)" make train " $(NOCOLOR) "- Train a SSD Inception V2 model."; clean: clean @echo $(YELLOW)"\nSSD Inception V2 Gesture: Cleaning up files..."$(NOCOLOR) diff --git a/networks/ssd_inception_v2_gesture/README.md b/networks/ssd_inception_v2_gesture/README.md index b4104011..ee1676f1 100644 --- a/networks/ssd_inception_v2_gesture/README.md +++ b/networks/ssd_inception_v2_gesture/README.md @@ -16,7 +16,7 @@ The provided Makefile does the following: 3. Compiles the network using the OpenVINO Model Optimizer 4. There is a python example (run.py) which runs an inference for all of the test images to show how to use the network with the OpenVINO toolkit. -This network is based on the [TensorFlow Object Detection API SSD Inception V2 model.](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md) The model was modified, trained, and saved in order to be compatible with the OpenVINO toolkit. +This network is based on the [TensorFlow Object Detection API SSD Inception V2 model.](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md) The model was modified, trained, and saved in order to be compatible with the OpenVINO toolkit. ## Running this example @@ -65,5 +65,5 @@ Removes all the temporary and target files that are created by the Makefile. ## Credits -## Attributions +### Attributions `ssd_inception_v2_gesture.py` is provided per the ATTRIBUTIONS.md file. The rest of the project is provided via the license in the ncappzoo repository's base directory. From a93c2c10f098ea3f772b04f9b7e2cc196156a067 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Mon, 13 Jan 2020 12:00:30 -0800 Subject: [PATCH 06/13] Completed training module and compiling from training module Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 316 ++++++++++++++++++++- 1 file changed, 312 insertions(+), 4 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index 53e3b5f7..380ae50a 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -5,7 +5,7 @@ YELLOW='\033[1;33m' NOCOLOR='\033[0m' RED = '\033[1;31m' -GRAPH_FILENAME_BASE = ssd_inception_v2_food +GRAPH_FILENAME_BASE = ssd_inception_v2_gesture GRAPH_DIR_FP32 = ssd_inception_v2_mo_fp32 GRAPH_DIR_FP16 = ssd_inception_v2_mo_fp16 GRAPH_FILENAME_BASE_IN_DIR_FP32 = ${GRAPH_DIR_FP32}/frozen_inference_graph.xml @@ -32,6 +32,39 @@ GET_MODEL_PB = python3 download_weights.py RUN_PY_RELATIVE_DIR = ssd_inception_v2_gesture.py +TRAIN_DIR = train_files +TRAIN_CHKPT_DIR = ${TRAIN_DIR}/ssd_inception_v2_coco_2018_01_28 +PRE_TRAINED_MODEL = wget -c --no-cache -P ./${TRAIN_DIR} http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz + +TRAIN_RECORD_FILE = ./${TRAIN_DIR}/train.record +TRAIN_RECORD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=13uM9aoxrUvPjZTIkXv33av_Dx8CYhg7S' -O ${TRAIN_RECORD_FILE} +TRAIN_RECORD_LINK = 'https://drive.google.com/uc?id=13uM9aoxrUvPjZTIkXv33av_Dx8CYhg7S' + +TEST_RECORD_FILE = ./${TRAIN_DIR}/test.record +TEST_RECORD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=17TmM3Sm_dOmCpnZ9ZIIsPTH536PapIP9' -O ${TEST_RECORD_FILE} + +TRAIN_PBTXT_FILE = ./${TRAIN_DIR}/object_detection.pbtxt +TRAIN_PBTXT = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1lEq3PtqMTijw12tcOpPrNFplqTNgSCTp' -O ${TRAIN_PBTXT_FILE} + +SSD_CONFIG_FILE = ./${TRAIN_DIR}/ssd_inception_v2_coco.config +SSD_CONFIG = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1fHnVpxyXvwdEJyuQmeI3dOERCzBytPUl' -O ${SSD_CONFIG_FILE} + +TRAIN_PIPE_CONFIG_FILE = ./${TRAIN_DIR}/pipeline.config +TRAIN_PIPE_CONFIG = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1KBm4HpjdZFNHSbx-T8cIFExgcGaPV-Qs' -O ${TRAIN_PIPE_CONFIG_FILE} + +JPEG_ZIP_FILE = ./${TRAIN_DIR}/JPEGImages.zip +JPEG_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=113g9NlQHmORnVWjohgnDPqW26-2Emvjz' -O ${JPEG_ZIP_FILE} +JPEG_FOLDER_LINK = 'https://drive.google.com/uc?id=1NJVw3OFORHTYIB4vom4EztL7fKkYLcpA' + +ANNO_ZIP_FILE = ./${TRAIN_DIR}/Annotations.zip +ANNO_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1sqll56Naxeb3Wn5yQrw4JO62IxQ2AJ0F' -O ${ANNO_ZIP_FILE} + +NETWORK_NAME = SSD Inception v2: Gesture Model +TF_MODEL_DIRNAME = models/ +TF_MODEL_REPO = git clone https://github.com/tensorflow/models.git +PROTOC_FILE = models/research/protobuf.zip +PROTOC_DOWNLOAD = wget -O ${PROTOC_FILE} https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip + .PHONY: all all: deps data compile_model @@ -78,10 +111,281 @@ get_model: fi ; \ fi +.PHONY: compile_from_training +compile_from_training: + @echo $(YELLOW) '\n'${NETWORK_NAME}": Information disclosure before compiling model." $(NOCOLOR); + @echo "The following steps will be taken in order to compile your own model that detects produce:" + @echo " - Freeze trained model" + @echo " - Run frozen model through model optimizer" + @echo "" + @echo $(YELLOW)"Before proceeding, edit the compile_from_training script in the Makefile." + @echo "Specifically, edit the trained_checkpoin_prefix to reflect your true (latest) model checkpoint."$(NOCOLOR) + @read -p"Press ENTER to continue the steps or Ctrl-C to cancel" variable_nps; echo; + @if [ -e ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ] ;\ + then \ + echo "Exported graph exists. Skipping exporting graph..." ;\ + else \ + echo "Models directory for TF Object Detection was not found" ;\ + echo "Please downloading training files using: make download_train_files" ;\ + cd ${TF_MODEL_DIRNAME}research ;\ + ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ + cd object_detection ;\ + mkdir export_gesture_graph ;\ + python3 export_inference_graph.py \ + --input_type=image_tensor \ + --pipeline_config_path=training_gesture/ssd_inception_v2_coco.config \ + --trained_checkpoint_prefix=training_gesture/model.ckpt-0 \ + --output_directory=export_gesture_graph ;\ + fi + @echo "Compiling model using model optimizer..." + @if [ -e ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ] ;\ + then \ + if [ -z "$(INTEL_OPENVINO_DIR)" ] ; \ + then \ + echo "Please initiate the OpenVINO environment before optimizing TF graph."; \ + else \ + echo "OpenVINO environment set. Continuing with optimizing TF graph..." ;\ + cd ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ;\ + mkdir ssd_inception_v2_mo_fp32_train ;\ + mkidr ssd_inception_v2_mo_fp16_train ;\ + ${NCCOMPILE} \ + --data_type=FP32 --reverse_input_channels \ + --input_model frozen_inference_graph.pb \ + --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ + --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ + --output_dir ssd_inception_v2_mo_fp32_train ;\ + ${NCCOMPILE} \ + --data_type=FP16 --reverse_input_channels \ + --input_model frozen_inference_graph.pb \ + --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ + --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ + --output_dir ssd_inception_v2_mo_fp16_train ;\ + mv ssd_inception_v2_mo_fp16_train ../../../../ssd_inception_v2_mo_fp16_train ;\ + mv ssd_inception_v2_mo_fp32_train ../../../../ssd_inception_v2_mo_fp32_train ;\ + echo "Successfully exported and optimized training graphs!" ;\ + fi ; \ + else \ + echo "No exported graph was made, so graph optimization could not be completed." ;\ + fi .PHONY: train -train: - @echo $(YELLOW) "\nSSD Inception V2 Geseture: Training model... NOT YET IMPLEMENTED" $(NOCOLOR); +train: train_info download_train_files set_up_training_api copy_training_files train_model + +.PHONY: train_info +train_info: + @echo $(YELLOW) '\n'${NETWORK_NAME}": Information disclosure before training model." $(NOCOLOR); + @echo "The following steps will be taken in order to train your own model that detects produce:" + @echo " - Download training files" + @echo " - Set up and locally install training environment and API" + @echo " - Copy training files into desired location for training" + @echo " - Train model using Tensorflow Object Detection API" + @echo "" + @echo "Throughout this whole process, files will be downloaded and repositories will be cloned." + @echo $(YELLOW)"Please pay attention to the prompts before proceeding as installation may error" + @echo "if not followed properly."$(NOCOLOR) + @read -p"Press ENTER to continue the steps above (this might take a long time) or Ctrl-C to cancel" variable_nps; echo; + +.PHONY: download_train_files +download_train_files: + @echo $(YELLOW)"Downloading train files..." + @if [ -e ${TRAIN_CHKPT_DIR} ] ; \ + then \ + echo $(NOCOLOR)"Checkpoint files already exist, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing checkpoint files from Tensorflow..."; \ + ${PRE_TRAINED_MODEL} ;\ + tar -xvzf ${TRAIN_CHKPT_DIR}.tar.gz ;\ + mv ssd_inception_v2_coco_2018_01_28 ${TRAIN_CHKPT_DIR} ;\ + fi + @if [ -e ${TEST_RECORD_FILE} ] ; \ + then \ + echo $(NOCOLOR)"Test record file already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing test record file..."; \ + ${TEST_RECORD} ;\ + fi + @if [ -e ${TRAIN_PBTXT_FILE} ] ; \ + then \ + echo $(NOCOLOR)"Pbtxt file already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing pbtxt file..."; \ + ${TRAIN_PBTXT} ;\ + fi + @if [ -e ${SSD_CONFIG_FILE} ] ; \ + then \ + echo $(NOCOLOR)"SSD Inception v2 config already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing SSD Inception v2 config file..."; \ + ${SSD_CONFIG} ;\ + fi + @if [ -e ${TF_MODEL_DIRNAME} ] ; \ + then \ + echo $(NOCOLOR)"Models repo already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Cloning models repo..."; \ + ${TF_MODEL_REPO} ;\ + fi + @if [ -e ${PROTOC_FILE} ] ; \ + then \ + echo $(NOCOLOR)"Protoc file already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing protoc file..."; \ + ${PROTOC_DOWNLOAD} ;\ + fi + @if [ -e ${ANNO_ZIP_FILE} ] ; \ + then \ + echo $(NOCOLOR)"Annotated zip file already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing annotated zip file..."; \ + ${ANNO_DOWNLOAD} ;\ + unzip ${ANNO_ZIP_FILE} -d train_files/ ;\ + fi + @echo "Downloading larger files using gdown, checking for installation" + pip3 install --user gdown + @if [ -e ${TRAIN_RECORD_FILE} ] ; \ + then \ + echo $(NOCOLOR)"Train record already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing train record file..."; \ + gdown ${TRAIN_FOLDER_LINK} -O train_files/train.record ;\ + fi + @if [ -e ${JPEG_ZIP_FILE} ] ; \ + then \ + echo $(NOCOLOR)"JPEG zip file already exists, skipping network request."; \ + else \ + echo $(NOCOLOR)"Grabbing JPEG zip file..."; \ + gdown ${JPEG_FOLDER_LINK} -O train_files/JPEGImages.zip ;\ + unzip ${JPEG_ZIP_FILE} -d train_files/ ;\ + fi + @if [ -e cocoapi/PythonAPI ] ;\ + then \ + echo $(NOCOLOR)"cocoapi repo already exists, skipping network request."; \ + else \ + echo "Cloning cocoapi repo for future installation..." ;\ + git clone https://github.com/cocodataset/cocoapi.git ;\ + fi + @echo "" + +.PHONY: set_up_training_api +set_up_training_api: + @echo $(YELLOW)"Setting up training environment..." + @if [ -e cocoapi/PythonAPI ] ; \ + then \ + echo $(YELLOW)"URGENT: READ FOLLOWING BEFORE PROCEEDING:" ;\ + echo "Replacing 'python' with 'python3' in the Makefile within cocoapi/PythonAPI"$(NOCOLOR) ;\ + read -p"Press ENTER to proceed or CTRL+C to exit..." variable_nps; echo ;\ + echo $(NOCOLOR)"Installing COCO API..." ;\ + cd cocoapi/PythonAPI ;\ + sed -i 's/python/python3/g' Makefile ;\ + make ;\ + cp -r pycocotools ../../models/research/ ;\ + else \ + echo $(NOCOLOR)"Please downloading training files before set up."; \ + fi + @if [ -e ${TF_MODEL_DIRNAME} ] ; \ + then \ + echo $(NOCOLOR)"Models repo exists, proceeding with setup."; \ + echo $(NOCOLOR)"Setting up protobuf."; \ + cd models/research/ ;\ + unzip protobuf.zip ;\ + ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ + else \ + echo $(NOCOLOR)"Please downloading training files before set up."; \ + fi + @echo $(YELLOW)"Testing training environment..." + @if python3 -c 'import pkgutil; exit(not pkgutil.find_loader("tensorflow"))' ; \ + then \ + echo $(NOCOLOR)'Tensorflow found, proceeding with testing the training environment...' ; \ + cd models/research/ ;\ + ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ + python3 object_detection/builders/model_builder_test.py ;\ + else \ + echo 'Tensorflow not found. Please install tensorflow (CPU version).' ; \ + echo 'If you would like to install Tensorflow-gpu, please analyze your' ; \ + echo 'your systems hardware and install the required drivers. Then, pip/pip3' ; \ + echo 'install tensorflow-gpu (might need special permissions).' ; \ + fi + @echo "" + +.PHONY: copy_training_files +copy_training_files: + @echo $(YELLOW)"Moving training files..." + @echo $(NOCOLOR)"Will potentially overwrite training files in models/research/object_detection" + @echo "Please check if there are training files within models/research/object_detection." + @read -p"Press ENTER to proceed or CTRL+C to exit..." variable_nps; echo; + @echo $(NOCOLOR)"Checking if training files directory exists in current directory..." + @if [ -e ${TRAIN_DIR} ] ;\ + then \ + echo $(NOCOLOR)"Training files exist, proceeding to copy them into object detection directory."; \ + cp -a ${TRAIN_DIR}/ssd_inception_v2_coco_2018_01_28 models/research/object_detection/. ; \ + mkdir models/research/object_detection/training_gesture ;\ + cp -a ${TRAIN_DIR}/. models/research/object_detection/training_gesture/. ;\ + echo "Moved training files into models/research/object_detection" ;\ + else \ + echo $(NOCOLOR)"Please download training files."; \ + fi + @echo "" + + +.PHONY: train_model +train_model: + @echo $(YELLOW) '\n'${NETWORK_NAME}": Training model..." $(NOCOLOR); + @echo " - Trained network will be saved in:"; + @echo " training_gesture"; + @echo "" + @echo $(YELLOW)"URGENT: READ THE FOLLOWING INSTRUCTIONS BEFORE TRAINING:" ; + @echo "In order to have more verbose logging so you can verify that your model is" ; + @echo "actually training, adding the following to line 57 of model_main.py in" ; + @echo "models/research/object_detection: tf.logging.set_verbosity(tf.logging.INFO)." + @echo "A reference file will be made with the original file content: old_model_main.py" $(NOCOLOR); + @echo "" + @echo "NOTE: Training files are unfrozen. If would like to export a model,"; + @echo "enter 'make export_and_optimize_model' to generate an optimized model"; + @echo "from your Tensorflow model."; + @echo "" + @echo "NOTE: If your system is running out of memory, please decrease batch size to 1."; + @echo "Work upwards to empirically test if your system can handle increased batch sizes."; + @echo "To edit batch size, edit the ssd_inception_v2_coco.config file in models/research/training_gesture by" + @echo "replacing the number on line 136 to any positive integer (ex. 1) after 'batch_size:'." + @echo "" + @read -p"Press ENTER to continue the steps above (this might take a long time) or Ctrl-C to cancel" variable_nps; echo; + + @if [ -e ${TF_MODEL_DIRNAME}/research/object_detection/old_model_main.py ] ;\ + then \ + echo "Changing model_main.py" ;\ + cd models/research/object_detection ;\ + rm -rf model_main.py ;\ + cp old_model_main.py model_main.py ;\ + sed -i -e '57itf.logging.set_verbosity(tf.logging.INFO)' model_main.py ;\ + else \ + echo "Changing model_main.py and adding a reference file" ;\ + cd models/research/object_detection ;\ + cp model_main.py old_model_main.py ;\ + sed -i -e '57itf.logging.set_verbosity(tf.logging.INFO)' model_main.py ;\ + fi + @if [ -e ${TF_MODEL_DIRNAME} ] ; \ + then \ + echo "Directory: ${TF_MODEL_DIRNAME}research/object_detection exists, setting up environment..."; \ + cd models/research/ ;\ + ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ + cd object_detection ;\ + echo "Environment is setup, commencing with training..." ;\ + python3 model_main.py \ + --pipeline_config_path=training_gesture/ssd_inception_v2_coco.config \ + --model_dir=training_gesture/ \ + --num_train_steps=20000 \ + --alsologtostderr ;\ + else \ + echo "Cannot locate the training files for TF Object Detection. Please download."; \ + fi ; .PHONY: compile_model @@ -122,7 +426,7 @@ compile_model: get_model .PHONY: install-reqs install-reqs: @echo $(YELLOW)"\nSSD Inception V2 Gesture: Checking application requirements...\n"$(NOCOLOR) - @echo "No requirements needed." + pip3 uninstall gdown .PHONY: run_FP16 @@ -166,3 +470,7 @@ clean: clean rm -rf ${GRAPH_DIR_FP32} rm -rf ${GRAPH_DIR_FP16} rm -rf ${MODEL_DIR} + rm -rf models + rm -rf cocoapi + rm -rf ssd_inception_v2_mo_fp16_train + rm -rf ssd_inception_v2_mo_fp32_train From 93abbc7691117f7f5ef3b03c19e76f84e0eb86a8 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Mon, 13 Jan 2020 12:47:53 -0800 Subject: [PATCH 07/13] Edited Makefile Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index 8505f745..dd94658d 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -424,7 +424,7 @@ compile_model: get_model .PHONY: install-reqs install-reqs: @echo $(YELLOW)"\nSSD Inception V2 Gesture: Checking application requirements...\n"$(NOCOLOR) - pip3 uninstall gdown + pip3 install --user gdown .PHONY: run_FP16 @@ -445,12 +445,12 @@ run: run_py .PHONY: run_py run_py: install-reqs deps data compile_model run_FP16 - - + + .PHONY: uninstall-reqs -uninstall-reqs: +uninstall-reqs: @echo $(YELLOW)"\nSSD Inception V2 Gesture: Uninstalling requirements..."$(NOCOLOR) - @echo "Nothing to uninstall." + pip3 uninstall gdown .PHONY: help From af5398bc4a014bb702b543baafc4694010adf342 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Mon, 13 Jan 2020 15:01:33 -0800 Subject: [PATCH 08/13] Edited Makefile Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index dd94658d..d0290a42 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -424,7 +424,7 @@ compile_model: get_model .PHONY: install-reqs install-reqs: @echo $(YELLOW)"\nSSD Inception V2 Gesture: Checking application requirements...\n"$(NOCOLOR) - pip3 install --user gdown + @echo "Nothing to install..." .PHONY: run_FP16 From e013f00048cefec64871423cefe188808a4b3af0 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Wed, 15 Jan 2020 17:16:34 -0800 Subject: [PATCH 09/13] Edits to Makefile, tested/verified everything except train_model Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 82 +++++++++++----------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index d0290a42..1ff044aa 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -53,11 +53,12 @@ TRAIN_PIPE_CONFIG_FILE = ./${TRAIN_DIR}/pipeline.config TRAIN_PIPE_CONFIG = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1KBm4HpjdZFNHSbx-T8cIFExgcGaPV-Qs' -O ${TRAIN_PIPE_CONFIG_FILE} JPEG_ZIP_FILE = ./${TRAIN_DIR}/JPEGImages.zip -JPEG_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=113g9NlQHmORnVWjohgnDPqW26-2Emvjz' -O ${JPEG_ZIP_FILE} -JPEG_FOLDER_LINK = 'https://drive.google.com/uc?id=1NJVw3OFORHTYIB4vom4EztL7fKkYLcpA' +JPEG_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1J5p63WjnkcWAyCQVbaW6qshsUBfX7aZ2' -O ${JPEG_ZIP_FILE} +JPEG_FOLDER_LINK = 'https://drive.google.com/uc?id=1J5p63WjnkcWAyCQVbaW6qshsUBfX7aZ2' ANNO_ZIP_FILE = ./${TRAIN_DIR}/Annotations.zip -ANNO_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1sqll56Naxeb3Wn5yQrw4JO62IxQ2AJ0F' -O ${ANNO_ZIP_FILE} +ANNO_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=17ZmWWQFV5ljMWTX1HP-dZtD25xKXVCYU' -O ${ANNO_ZIP_FILE} +ANNO_FOLDER_LINK = 'https://drive.google.com/uc?id=17ZmWWQFV5ljMWTX1HP-dZtD25xKXVCYU' NETWORK_NAME = SSD Inception v2: Gesture Model TF_MODEL_DIRNAME = models/ @@ -126,45 +127,45 @@ compile_from_training: else \ echo "Models directory for TF Object Detection was not found" ;\ echo "Please downloading training files using: make download_train_files" ;\ - cd ${TF_MODEL_DIRNAME}research ;\ - ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ - export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ - export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ - cd object_detection ;\ - mkdir export_gesture_graph ;\ - python3 export_inference_graph.py \ - --input_type=image_tensor \ - --pipeline_config_path=training_gesture/ssd_inception_v2_coco.config \ - --trained_checkpoint_prefix=training_gesture/model.ckpt-0 \ - --output_directory=export_gesture_graph ;\ + cd ${TF_MODEL_DIRNAME}research ;\ + ./bin/protoc object_detection/protos/*.proto --python_out=. ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`/object_detection ;\ + export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim ;\ + cd object_detection ;\ + mkdir export_gesture_graph ;\ + python3 export_inference_graph.py \ + --input_type=image_tensor \ + --pipeline_config_path=training_gesture/ssd_inception_v2_coco.config \ + --trained_checkpoint_prefix=training_gesture/model.ckpt-0 \ + --output_directory=export_gesture_graph ;\ fi @echo "Compiling model using model optimizer..." @if [ -e ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ] ;\ then \ - if [ -z "$(INTEL_OPENVINO_DIR)" ] ; \ - then \ - echo "Please initiate the OpenVINO environment before optimizing TF graph."; \ - else \ - echo "OpenVINO environment set. Continuing with optimizing TF graph..." ;\ - cd ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ;\ - mkdir ssd_inception_v2_mo_fp32_train ;\ - mkidr ssd_inception_v2_mo_fp16_train ;\ - ${NCCOMPILE} \ - --data_type=FP32 --reverse_input_channels \ - --input_model frozen_inference_graph.pb \ - --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ - --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ - --output_dir ssd_inception_v2_mo_fp32_train ;\ - ${NCCOMPILE} \ - --data_type=FP16 --reverse_input_channels \ - --input_model frozen_inference_graph.pb \ - --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ - --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ - --output_dir ssd_inception_v2_mo_fp16_train ;\ - mv ssd_inception_v2_mo_fp16_train ../../../../ssd_inception_v2_mo_fp16_train ;\ - mv ssd_inception_v2_mo_fp32_train ../../../../ssd_inception_v2_mo_fp32_train ;\ - echo "Successfully exported and optimized training graphs!" ;\ - fi ; \ + if [ -z "$(INTEL_OPENVINO_DIR)" ] ; \ + then \ + echo "Please initiate the OpenVINO environment before optimizing TF graph."; \ + else \ + echo "OpenVINO environment set. Continuing with optimizing TF graph..." ;\ + cd ${TF_MODEL_DIRNAME}research/object_detection/export_gesture_graph ;\ + mkdir ssd_inception_v2_mo_fp32_train ;\ + mkidr ssd_inception_v2_mo_fp16_train ;\ + ${NCCOMPILE} \ + --data_type=FP32 --reverse_input_channels \ + --input_model frozen_inference_graph.pb \ + --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ + --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ + --output_dir ssd_inception_v2_mo_fp32_train ;\ + ${NCCOMPILE} \ + --data_type=FP16 --reverse_input_channels \ + --input_model frozen_inference_graph.pb \ + --tensorflow_object_detection_api_pipeline_config ../training_gesture/ssd_inception_v2_coco.config \ + --tensorflow_use_custom_operations_config ../../../../ssd_v2_support_inception_train.json \ + --output_dir ssd_inception_v2_mo_fp16_train ;\ + mv ssd_inception_v2_mo_fp16_train ../../../../ssd_inception_v2_mo_fp16_train ;\ + mv ssd_inception_v2_mo_fp32_train ../../../../ssd_inception_v2_mo_fp32_train ;\ + echo "Successfully exported and optimized training graphs!" ;\ + fi ; \ else \ echo "No exported graph was made, so graph optimization could not be completed." ;\ fi @@ -238,7 +239,7 @@ download_train_files: echo $(NOCOLOR)"Annotated zip file already exists, skipping network request."; \ else \ echo $(NOCOLOR)"Grabbing annotated zip file..."; \ - ${ANNO_DOWNLOAD} ;\ + gdown ${ANNO_FOLDER_LINK} -O ${ANNO_ZIP_FILE} ;\ ;\ unzip ${ANNO_ZIP_FILE} -d train_files/ ;\ fi @echo "Downloading larger files using gdown, checking for installation" @@ -248,7 +249,7 @@ download_train_files: echo $(NOCOLOR)"Train record already exists, skipping network request."; \ else \ echo $(NOCOLOR)"Grabbing train record file..."; \ - gdown ${TRAIN_FOLDER_LINK} -O train_files/train.record ;\ + gdown ${TRAIN_RECORD_LINK} -O train_files/train.record ;\ fi @if [ -e ${JPEG_ZIP_FILE} ] ; \ then \ @@ -475,6 +476,7 @@ clean: clean rm -rf ${GRAPH_DIR_FP32} rm -rf ${GRAPH_DIR_FP16} rm -rf ${MODEL_DIR} + rm -rf train_files rm -rf models rm -rf cocoapi rm -rf ssd_inception_v2_mo_fp16_train From ce84eead2370b43bd697fd21556845383b795705 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Wed, 15 Jan 2020 20:03:53 -0800 Subject: [PATCH 10/13] Verified/tested training module and compilation from training Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 2 +- .../ssd_v2_support_inception_train.json | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 networks/ssd_inception_v2_gesture/ssd_v2_support_inception_train.json diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index 1ff044aa..fdc599c9 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -43,7 +43,7 @@ TRAIN_RECORD_LINK = 'https://drive.google.com/uc?id=13uM9aoxrUvPjZTIkXv33av_Dx8C TEST_RECORD_FILE = ./${TRAIN_DIR}/test.record TEST_RECORD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=17TmM3Sm_dOmCpnZ9ZIIsPTH536PapIP9' -O ${TEST_RECORD_FILE} -TRAIN_PBTXT_FILE = ./${TRAIN_DIR}/object_detection.pbtxt +TRAIN_PBTXT_FILE = ./${TRAIN_DIR}/object-detection.pbtxt TRAIN_PBTXT = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1lEq3PtqMTijw12tcOpPrNFplqTNgSCTp' -O ${TRAIN_PBTXT_FILE} SSD_CONFIG_FILE = ./${TRAIN_DIR}/ssd_inception_v2_coco.config diff --git a/networks/ssd_inception_v2_gesture/ssd_v2_support_inception_train.json b/networks/ssd_inception_v2_gesture/ssd_v2_support_inception_train.json new file mode 100644 index 00000000..f9892bcf --- /dev/null +++ b/networks/ssd_inception_v2_gesture/ssd_v2_support_inception_train.json @@ -0,0 +1,62 @@ +[ + { + "custom_attributes": { + }, + "id": "ObjectDetectionAPIPreprocessorReplacement", + "inputs": [ + [ + { + "node": "map/Shape$", + "port": 0 + }, + { + "node": "map/TensorArrayUnstack/Shape$", + "port": 0 + }, + { + "node": "map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3$", + "port": 2 + } + ] + ], + "instances": [ + ".*Preprocessor/" + ], + "match_kind": "scope", + "outputs": [ + { + "node": "sub$", + "port": 0 + }, + { + "node": "map/TensorArrayStack_1/TensorArrayGatherV3$", + "port": 0 + } + ] + }, + { + "custom_attributes": { + "code_type": "caffe.PriorBoxParameter.CENTER_SIZE", + "pad_mode": "caffe.ResizeParameter.CONSTANT", + "resize_mode": "caffe.ResizeParameter.WARP" + }, + "id": "ObjectDetectionAPISSDPostprocessorReplacement", + "include_inputs_to_sub_graph": true, + "include_outputs_to_sub_graph": true, + "instances": { + "end_points": [ + "detection_boxes", + "detection_scores", + "num_detections" + ], + "start_points": [ + "Postprocessor/Shape", + "Postprocessor/scale_logits", + "Postprocessor/Tile", + "Postprocessor/Reshape_1", + "Postprocessor/Cast_1" + ] + }, + "match_kind": "points" + } +] From 26c419d2a627004cc24e3ab6916edefd4103b92d Mon Sep 17 00:00:00 2001 From: fcr3 Date: Thu, 16 Jan 2020 12:46:16 -0800 Subject: [PATCH 11/13] Edited Makefile Signed-off-by: fcr3 --- networks/ssd_inception_v2_gesture/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index fdc599c9..e16cf738 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -234,6 +234,8 @@ download_train_files: echo $(NOCOLOR)"Grabbing protoc file..."; \ ${PROTOC_DOWNLOAD} ;\ fi + @echo "Downloading larger files using gdown, checking for installation" + pip3 install --user gdown @if [ -e ${ANNO_ZIP_FILE} ] ; \ then \ echo $(NOCOLOR)"Annotated zip file already exists, skipping network request."; \ @@ -242,8 +244,6 @@ download_train_files: gdown ${ANNO_FOLDER_LINK} -O ${ANNO_ZIP_FILE} ;\ ;\ unzip ${ANNO_ZIP_FILE} -d train_files/ ;\ fi - @echo "Downloading larger files using gdown, checking for installation" - pip3 install --user gdown @if [ -e ${TRAIN_RECORD_FILE} ] ; \ then \ echo $(NOCOLOR)"Train record already exists, skipping network request."; \ From c7e57ab98d935dd6bf0120b42a86262e65ca46f0 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Fri, 31 Jan 2020 09:33:57 -0800 Subject: [PATCH 12/13] Updated links, removed gdown requirement --- networks/ssd_inception_v2_gesture/Makefile | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/networks/ssd_inception_v2_gesture/Makefile b/networks/ssd_inception_v2_gesture/Makefile index e16cf738..a1a5c26e 100644 --- a/networks/ssd_inception_v2_gesture/Makefile +++ b/networks/ssd_inception_v2_gesture/Makefile @@ -28,7 +28,8 @@ MODEL_INFERENCE_PB = frozen_inference_graph.pb GET_MODEL_PIPELINE = wget -c --no-cache -P ./tensorflow_model https://raw.githubusercontent.com/fcr3/gesture_detection/master/tensorflow_model/${MODEL_INFERENCE_PIPELINE_CONFIG} GET_MO_MODEL_FP32_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp32 https://raw.githubusercontent.com/fcr3/gesture_detection/master/model_optimized_fp32/${MO_LABELS} GET_MO_MODEL_FP16_LABELS = wget -c --no-cache -P ./ssd_inception_v2_mo_fp16 https://raw.githubusercontent.com/fcr3/gesture_detection/master/model_optimized_fp16/${MO_LABELS} -GET_MODEL_PB = python3 download_weights.py +GET_MODEL_PB = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/model/frozen_inference_graph.pb -O ${MODEL_DIR}/${MODEL_INFERENCE_PB} +# if above doesn't work: python3 download_weights.py RUN_PY_RELATIVE_DIR = ssd_inception_v2_gesture.py @@ -37,28 +38,28 @@ TRAIN_CHKPT_DIR = ${TRAIN_DIR}/ssd_inception_v2_coco_2018_01_28 PRE_TRAINED_MODEL = wget -c --no-cache -P ./${TRAIN_DIR} http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz TRAIN_RECORD_FILE = ./${TRAIN_DIR}/train.record -TRAIN_RECORD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=13uM9aoxrUvPjZTIkXv33av_Dx8CYhg7S' -O ${TRAIN_RECORD_FILE} -TRAIN_RECORD_LINK = 'https://drive.google.com/uc?id=13uM9aoxrUvPjZTIkXv33av_Dx8CYhg7S' +TRAIN_RECORD = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/train.record -O ${TRAIN_RECORD_FILE} +# TRAIN_RECORD_LINK = 'https://drive.google.com/uc?id=13uM9aoxrUvPjZTIkXv33av_Dx8CYhg7S' TEST_RECORD_FILE = ./${TRAIN_DIR}/test.record -TEST_RECORD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=17TmM3Sm_dOmCpnZ9ZIIsPTH536PapIP9' -O ${TEST_RECORD_FILE} +TEST_RECORD = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/test.record -O ${TEST_RECORD_FILE} TRAIN_PBTXT_FILE = ./${TRAIN_DIR}/object-detection.pbtxt -TRAIN_PBTXT = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1lEq3PtqMTijw12tcOpPrNFplqTNgSCTp' -O ${TRAIN_PBTXT_FILE} +TRAIN_PBTXT = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/object-detection.pbtxt -O ${TRAIN_PBTXT_FILE} SSD_CONFIG_FILE = ./${TRAIN_DIR}/ssd_inception_v2_coco.config -SSD_CONFIG = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1fHnVpxyXvwdEJyuQmeI3dOERCzBytPUl' -O ${SSD_CONFIG_FILE} +SSD_CONFIG = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/ssd_inception_v2_coco.config -O ${SSD_CONFIG_FILE} TRAIN_PIPE_CONFIG_FILE = ./${TRAIN_DIR}/pipeline.config -TRAIN_PIPE_CONFIG = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1KBm4HpjdZFNHSbx-T8cIFExgcGaPV-Qs' -O ${TRAIN_PIPE_CONFIG_FILE} +TRAIN_PIPE_CONFIG = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/pipeline.config -O ${TRAIN_PIPE_CONFIG_FILE} JPEG_ZIP_FILE = ./${TRAIN_DIR}/JPEGImages.zip -JPEG_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1J5p63WjnkcWAyCQVbaW6qshsUBfX7aZ2' -O ${JPEG_ZIP_FILE} -JPEG_FOLDER_LINK = 'https://drive.google.com/uc?id=1J5p63WjnkcWAyCQVbaW6qshsUBfX7aZ2' +JPEG_DOWNLOAD = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/JPEGImages-20200116T001612Z-001.zip -O ${JPEG_ZIP_FILE} +# JPEG_FOLDER_LINK = 'https://drive.google.com/uc?id=1J5p63WjnkcWAyCQVbaW6qshsUBfX7aZ2' ANNO_ZIP_FILE = ./${TRAIN_DIR}/Annotations.zip -ANNO_DOWNLOAD = wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=17ZmWWQFV5ljMWTX1HP-dZtD25xKXVCYU' -O ${ANNO_ZIP_FILE} -ANNO_FOLDER_LINK = 'https://drive.google.com/uc?id=17ZmWWQFV5ljMWTX1HP-dZtD25xKXVCYU' +ANNO_DOWNLOAD = wget http://dp2f0iayzbweh.cloudfront.net/ncappzoo/gesture_detection/training/Annotations-20200115T233047Z-001.zip -O ${ANNO_ZIP_FILE} +# ANNO_FOLDER_LINK = 'https://drive.google.com/uc?id=17ZmWWQFV5ljMWTX1HP-dZtD25xKXVCYU' NETWORK_NAME = SSD Inception v2: Gesture Model TF_MODEL_DIRNAME = models/ @@ -235,13 +236,12 @@ download_train_files: ${PROTOC_DOWNLOAD} ;\ fi @echo "Downloading larger files using gdown, checking for installation" - pip3 install --user gdown @if [ -e ${ANNO_ZIP_FILE} ] ; \ then \ echo $(NOCOLOR)"Annotated zip file already exists, skipping network request."; \ else \ echo $(NOCOLOR)"Grabbing annotated zip file..."; \ - gdown ${ANNO_FOLDER_LINK} -O ${ANNO_ZIP_FILE} ;\ ;\ + ${ANNO_DOWNLOAD} ; \ # gdown ${ANNO_FOLDER_LINK} -O ${ANNO_ZIP_FILE} ;\ ;\ unzip ${ANNO_ZIP_FILE} -d train_files/ ;\ fi @if [ -e ${TRAIN_RECORD_FILE} ] ; \ @@ -249,14 +249,14 @@ download_train_files: echo $(NOCOLOR)"Train record already exists, skipping network request."; \ else \ echo $(NOCOLOR)"Grabbing train record file..."; \ - gdown ${TRAIN_RECORD_LINK} -O train_files/train.record ;\ + ${TRAIN_RECORD} ; \ # gdown ${TRAIN_RECORD_LINK} -O train_files/train.recor ;\ fi @if [ -e ${JPEG_ZIP_FILE} ] ; \ then \ echo $(NOCOLOR)"JPEG zip file already exists, skipping network request."; \ else \ echo $(NOCOLOR)"Grabbing JPEG zip file..."; \ - gdown ${JPEG_FOLDER_LINK} -O train_files/JPEGImages.zip ;\ + ${JPEG_DOWNLOAD} ; \ # gdown ${JPEG_FOLDER_LINK} -O train_files/JPEGImages.zi ;\ unzip ${JPEG_ZIP_FILE} -d train_files/ ;\ fi @if [ -e cocoapi/PythonAPI ] ;\ @@ -451,7 +451,7 @@ run_py: install-reqs deps data compile_model run_FP16 .PHONY: uninstall-reqs uninstall-reqs: @echo $(YELLOW)"\nSSD Inception V2 Gesture: Uninstalling requirements..."$(NOCOLOR) - pip3 uninstall gdown + @echo "\nNo requirements to install..." .PHONY: help From 2207ac2c93af2ee758c824cb273625aa89f95d21 Mon Sep 17 00:00:00 2001 From: fcr3 Date: Fri, 31 Jan 2020 09:36:16 -0800 Subject: [PATCH 13/13] Removed download_weights.py Signed-off-by: fcr3 --- .../download_weights.py | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 networks/ssd_inception_v2_gesture/download_weights.py diff --git a/networks/ssd_inception_v2_gesture/download_weights.py b/networks/ssd_inception_v2_gesture/download_weights.py deleted file mode 100644 index 63550004..00000000 --- a/networks/ssd_inception_v2_gesture/download_weights.py +++ /dev/null @@ -1,23 +0,0 @@ -import requests - -def main(): - pb_file_id = '1TuK2SMtkFlT5SRrhjWCz4Z5xXE-gcRDd' - file_to_write = './tensorflow_model/frozen_inference_graph.pb' - drive_url = "https://docs.google.com/uc?export=download" - - req_session = requests.Session() - session_res = req_session.get(drive_url, params = { 'id' : pb_file_id }, stream = True) - - for k, v in session_res.cookies.items(): - if k.startswith('download_warning'): - params = { 'id' : pb_file_id, 'confirm' : v } - session_res = session_res.get(drive_url, params = params, stream = True) - break - - size = 32768 - with open(file_to_write, "wb") as f: - for packet in session_res.iter_content(size): - f.write(packet) if packet else None - -if __name__ == "__main__": - main()