I'm trying to do people detection using tensorflow.

Here is a video of what I came up for


My questions.

  1. I run the tensorflow on GPU 1050ti nvidia, and it's extremly slow

  2. The detection still flickers, but thanks to kalman filter that I did it does keep consistent IDs, but how can I make the detection smooth and keeps detecting without flickering?

Here is the detection code that I'm using

def get_localization(self, image, visual=False):

        """Determines the locations of the cars in the image
            image: camera image
            list of bounding boxes: coordinates [y_up, x_left, y_down, x_right]
        category_index = {1: {'id': 1, 'name': u'person'},
                          2: {'id': 2, 'name': u'bicycle'},
                          3: {'id': 3, 'name': u'car'},
                          4: {'id': 4, 'name': u'motorcycle'},
                          5: {'id': 5, 'name': u'airplane'},
                          6: {'id': 6, 'name': u'bus'},
                          7: {'id': 7, 'name': u'train'},
                          8: {'id': 8, 'name': u'truck'},
                          9: {'id': 9, 'name': u'boat'},
                          10: {'id': 10, 'name': u'traffic light'},
                          11: {'id': 11, 'name': u'fire hydrant'},
                          13: {'id': 13, 'name': u'stop sign'},
                          14: {'id': 14, 'name': u'parking meter'}}

        with self.detection_graph.as_default():
            image_expanded = np.expand_dims(image, axis=0)
            (boxes, scores, classes, num_detections) = self.sess.run(
                [self.boxes, self.scores, self.classes, self.num_detections],
                feed_dict={self.image_tensor: image_expanded})

            if visual == True:
                    use_normalized_coordinates=True, min_score_thresh=.4,

                plt.figure(figsize=(9, 6))

            boxes = np.squeeze(boxes)
            classes = np.squeeze(classes)
            scores = np.squeeze(scores)

            cls = classes.tolist()

            # The ID for car in COCO data set is 3
            idx_vec = [i for i, v in enumerate(cls) if ((v == 1) or (v == 3) or (v == 2)or (v == 4)or (v == 8)and (scores[i] > 0.6))]

            if len(idx_vec) == 0:
                print('no detection!')
                self.car_boxes = []
                tmp_car_boxes = []
                for idx in idx_vec:
                    dim = image.shape[0:2]
                    box = self.box_normal_to_pixel(boxes[idx], dim, scores[idx])
                    box_h = box[2] - box[0]
                    box_w = box[3] - box[1]
                    ratio = box_h / (box_w + 0.01)

                    if ((ratio < 0.8 or ratio > 0.8) and (box_h > 20) and (box_w > 20)):
                        #print(box, ', confidence: ', scores[idx], 'ratio:', ratio)

                        #print('wrong ratio or wrong size, ', box, ', confidence: ', scores[idx], 'ratio:', ratio)

                self.car_boxes = tmp_car_boxes

        return self.car_boxes
  • $\begingroup$ two things to focus on: refresh rates to tune flickering remember human eye perceives 12fps only as fluid movement and can try higher and lower resolution bounding boxes to constrain index id to decimal places also can try add colour into the mix, from 1-255 as colour is easier for gpu to process than shape or line $\endgroup$ – zip Feb 4 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.