Code Monkey home page Code Monkey logo

Comments (9)

victordibia avatar victordibia commented on July 23, 2024

Hmmm ...
That is indeed baffling - 1fps.

Just for sanity ... to ensure its not some issue with the handtracking code (or differences in implementation environment like #3 #5 and #6), it may be a good idea to compare this with the speed you achieve for the basic tensorflow object detection api tutorial. Similar FPS might suggest your development environment (CPU) as the reason for the slow speed.

One more thing, my test environment is a MacbookPro i7, 2.5GHz, 16GB Quad Core. I also have compiled Tensorflow from source to ensure it is optimized for my cpu architecture (which makes tensorflow faster).

For other ways to optimize tensorflow, I think this link may be helpful.
https://www.tensorflow.org/performance/performance_guide

-V.

from handtracking.

Hzzone avatar Hzzone commented on July 23, 2024

@victordibia Have you applied NMS to merge repeated bounding box? If you do that I think it may make a better performance in detection.

from handtracking.

victordibia avatar victordibia commented on July 23, 2024

Happy to try it out.
What do you mean by NMS though? Any link you can share that describes it in more detail?

-V.

from handtracking.

Hzzone avatar Hzzone commented on July 23, 2024

@victordibia
this video may help you to understand NMS.
Here is some python code to implement it:

import sys
from operator import itemgetter
import numpy as np
import cv2
'''
Function:
	calculate Intersect of Union
Input: 
	rect_1: 1st rectangle
	rect_2: 2nd rectangle
Output:
	IoU
'''
def IoU(rect_1, rect_2):
    x11 = rect_1[0]    # first rectangle top left x
    y11 = rect_1[1]    # first rectangle top left y
    x12 = rect_1[2]    # first rectangle bottom right x
    y12 = rect_1[3]    # first rectangle bottom right y
    x21 = rect_2[0]    # second rectangle top left x
    y21 = rect_2[1]    # second rectangle top left y
    x22 = rect_2[2]    # second rectangle bottom right x
    y22 = rect_2[3]    # second rectangle bottom right y
    x_overlap = max(0, min(x12,x22) -max(x11,x21))
    y_overlap = max(0, min(y12,y22) -max(y11,y21))
    intersection = x_overlap * y_overlap
    union = (x12-x11) * (y12-y11) + (x22-x21) * (y22-y21) - intersection
    if union == 0:
	return 0
    else:
        return float(intersection) / union
'''
Function:
	calculate Intersect of Min area
Input: 
	rect_1: 1st rectangle
	rect_2: 2nd rectangle
Output:
	IoM
'''
def IoM(rect_1, rect_2):
    x11 = rect_1[0]    # first rectangle top left x
    y11 = rect_1[1]    # first rectangle top left y
    x12 = rect_1[2]    # first rectangle bottom right x
    y12 = rect_1[3]    # first rectangle bottom right y
    x21 = rect_2[0]    # second rectangle top left x
    y21 = rect_2[1]    # second rectangle top left y
    x22 = rect_2[2]    # second rectangle bottom right x
    y22 = rect_2[3]    # second rectangle bottom right y
    x_overlap = max(0, min(x12,x22) -max(x11,x21))
    y_overlap = max(0, min(y12,y22) -max(y11,y21))
    intersection = x_overlap * y_overlap
    rect1_area = (y12 - y11) * (x12 - x11)
    rect2_area = (y22 - y21) * (x22 - x21)
    min_area = min(rect1_area, rect2_area)
    return float(intersection) / min_area
'''
Function:
	apply NMS(non-maximum suppression) on ROIs in same scale
Input:
	rectangles: rectangles[i][0:3] is the position, rectangles[i][4] is scale, rectangles[i][5] is score
Output:
	rectangles: same as input
'''
def NMS(rectangles,threshold,type):
    sorted(rectangles,key=itemgetter(4),reverse=True)
    result_rectangles = rectangles
    number_of_rects = len(result_rectangles)
    cur_rect = 0
    while cur_rect < number_of_rects : 
        rects_to_compare = number_of_rects - cur_rect - 1 
        cur_rect_to_compare = cur_rect + 1 
        while rects_to_compare > 0:
	    score = 0
	    if type == 'iou':
		score =  IoU(result_rectangles[cur_rect], result_rectangles[cur_rect_to_compare])
	    else:
		score =  IoM(result_rectangles[cur_rect], result_rectangles[cur_rect_to_compare])
            if score >= threshold:
                del result_rectangles[cur_rect_to_compare]      # delete the rectangle
                number_of_rects -= 1
            else:
                cur_rect_to_compare += 1    # skip to next rectangle            
            rects_to_compare -= 1
        cur_rect += 1   # finished comparing for current rectangle
    return result_rectangles

from handtracking.

Hzzone avatar Hzzone commented on July 23, 2024

@victordibia In original repo, weiliu89 has applied NMS with a threshold of 0.45. you can find it in ssd_pascal.py.

# parameters for generating detection output.
det_out_param = {
    'num_classes': num_classes,
    'share_location': share_location,
    'background_label_id': background_label_id,
    'nms_param': {'nms_threshold': 0.45, 'top_k': 400},
    'keep_top_k': 200,
    'confidence_threshold': 0.01,
    'code_type': code_type,
    }

from handtracking.

victordibia avatar victordibia commented on July 23, 2024

@Hzzone , thanks for the link, will look through it and post any updates I find.

Btw ... I am using some form of thresholding (variable score_thresh in detect_multi_threaded.py ) already.

-V.

from handtracking.

pharrellyhy avatar pharrellyhy commented on July 23, 2024

I just cloned your repo and run the detect_multi_threaded.py on my macbook pro (i7 2.4G, 16GB RAM). The max fps I got is just 3. Any idea to improve it?

from handtracking.

victordibia avatar victordibia commented on July 23, 2024

from handtracking.

3073 avatar 3073 commented on July 23, 2024

I tried SSD detector (VGG16 as base) with dlib tracker for passenger counting and it disprove the saying on papers that "SSD is very fast" it shows me FPS = 0.... do you have any idea how can I make it fast to the extent that it can be used for real time passenger counting ..

Environment:
untitled

from handtracking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.