@@ -0,0 +1,2275 @@
+# Mostly taken from: https://github.com/tensorflow/models/blob/master/object_detection/object_detection_tutorial.ipynb%0A%0Aimport numpy as np%0Aimport tensorflow as tf%0Aimport cv2%0Aimport os%0Afrom scannerpy.stdlib import kernel%0A%0A##################################################################################################%0A# Assume that DNN model is located in PATH_TO_GRAPH with filename 'frozen_inference_graph.pb'    #%0A# Example model can be downloaded from:                                                          #%0A# http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2017_11_17.tar.gz #%0A##################################################################################################%0A%0Ascript_dir = os.path.dirname(os.path.abspath(__file__))%0APATH_TO_REPO = script_dir%0A%0APATH_TO_GRAPH = os.path.join(PATH_TO_REPO, 'ssd_mobilenet_v1_coco_2017_11_17', 'frozen_inference_graph.pb')%0A%0Aclass ObjDetectKernel(kernel.TensorFlowKernel):%0A    def build_graph(self):%0A        dnn = tf.Graph()%0A        with dnn.as_default():%0A            od_graph_def = tf.GraphDef()%0A            with tf.gfile.GFile(PATH_TO_GRAPH, 'rb') as fid:%0A                serialized_graph = fid.read()%0A                od_graph_def.ParseFromString(serialized_graph)%0A                tf.import_graph_def(od_graph_def, name='')%0A        return dnn%0A%0A    # Evaluate object detection DNN model on a frame%0A    # Return bounding box position, class and score%0A    def execute(self, cols):%0A        image = cols%5B0%5D%0A        image_tensor = self.graph.get_tensor_by_name('image_tensor:0')%0A        boxes = self.graph.get_tensor_by_name('detection_boxes:0')%0A        scores = self.graph.get_tensor_by_name('detection_scores:0')%0A        classes = self.graph.get_tensor_by_name('detection_classes:0')%0A        with self.graph.as_default():%0A            (boxes, scores, classes) = self.sess.run(%0A                %5Bboxes, scores, classes%5D,%0A                feed_dict=%7Bimage_tensor: np.expand_dims(image, axis=0)%7D)%0A            %0A            # bundled data format: %5Bbox position(x1 y1 x2 y2), box class, box score%5D%0A            bundled_data = np.concatenate((boxes.reshape(100,4), classes.reshape(100,1), scores.reshape(100,1)), 1)%5B:20%5D%0A            %0A            return %5Bbundled_data.tobytes()%5D%0A%0AKERNEL = ObjDetectKernel%0A

Create obj_detect_kernel.py