def main(): logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Ask tensorflow logger not to propagate logs to parent (which causes # duplicated logging) logging.getLogger('tensorflow').propagate = False global args args = parse_args() logger.info('called with args: %s' % args) # build the class (index/name) dictionary from labelmap file logger.info('reading label map') cls_dict = read_label_map(args.labelmap_file) pb_path = './data/{}_trt.pb'.format(args.model) log_path = './logs/{}_trt'.format(args.model) if args.do_build: logger.info('building TRT graph and saving to pb: %s' % pb_path) build_trt_pb(args.model, pb_path) logger.info('opening camera device/file') cam = Camera(args) cam.open() if not cam.is_opened: sys.exit('Failed to open camera!') logger.info('loading TRT graph from pb: %s' % pb_path) trt_graph = load_trt_pb(pb_path) logger.info('starting up TensorFlow session') tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True #tf_sess = tf.Session(config=tf_config, graph=trt_graph) -- Vincent #Solve : "unable to satfisfy explicit device /dev/CPU:0 -- Vincent tf_sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True), graph=trt_graph) if args.do_tensorboard: logger.info('writing graph summary to TensorBoard') write_graph_tensorboard(tf_sess, log_path) logger.info('warming up the TRT graph with a dummy image') od_type = 'faster_rcnn' if 'faster_rcnn' in args.model else 'ssd' dummy_img = np.zeros((720, 1280, 3), dtype=np.uint8) _, _, _ = detect(dummy_img, tf_sess, conf_th=.3, od_type=od_type) cam.start() # ask the camera to start grabbing images # grab image and do object detection (until stopped by user) logger.info('starting to loop and detect') vis = BBoxVisualization(cls_dict) open_display_window(cam.img_height, cam.img_width) result = loop_and_detect(cam, tf_sess, args.conf_th, vis, od_type=od_type) logger.info('cleaning up') cam.stop() # terminate the sub-thread in camera tf_sess.close() cam.release() cv2.destroyAllWindows()
def main(): logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Ask tensorflow logger not to propagate logs to parent (which causes # duplicated logging) logging.getLogger('tensorflow').propagate = False args = parse_args() logger.info('called with args: %s' % args) # build the class (index/name) dictionary from labelmap file logger.info('reading label map') cls_dict = read_label_map(args.labelmap_file) pb_path = './data/{}_trt.pb'.format(args.model) log_path = './logs/{}_trt'.format(args.model) if args.do_build: logger.info('building TRT graph and saving to pb: %s' % pb_path) build_trt_pb(args.model, pb_path) logger.info('opening camera device/file') infile=args.filename cam=cv2.VideoCapture(infile) size=(int(cam.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT))) fps=cam.get(cv2.CAP_PROP_FPS) writer=cv2.VideoWriter('_res.'.join([f for f in infile.split('.')]),cv2.VideoWriter_fourcc(*'mp4v'), fps, size) logger.info('loading TRT graph from pb: %s' % pb_path) trt_graph = load_trt_pb(pb_path) logger.info('starting up TensorFlow session') tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True tf_sess = tf.Session(config=tf_config, graph=trt_graph) if args.do_tensorboard: logger.info('writing graph summary to TensorBoard') write_graph_tensorboard(tf_sess, log_path) logger.info('warming up the TRT graph with a dummy image') od_type = 'faster_rcnn' if 'faster_rcnn' in args.model else 'ssd' dummy_img = np.zeros((720, 1280, 3), dtype=np.uint8) _, _, _ = detect(dummy_img, tf_sess, conf_th=.3, od_type=od_type) # grab image and do object detection (until stopped by user) logger.info('starting to loop and detect') vis = BBoxVisualization(cls_dict) #open_display_window(cam.img_width, cam.img_height) loop_and_detect(cam, tf_sess, 0.2, vis, od_type=od_type,writer=writer) logger.info('cleaning up') tf_sess.close() cam.release() writer.release()
def main(): logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Ask tensorflow logger not to propagate logs to parent (which causes # duplicated logging) logging.getLogger('tensorflow').propagate = False # build the class (index/name) dictionary from labelmap file logger.info('reading label map') cls_dict = read_label_map(DEFAULT_LABELMAP) pb_path = './data/{}_trt.pb'.format(DEFAULT_MODEL) log_path = './logs/{}_trt'.format(DEFAULT_MODEL) logger.info('opening camera device/file') url1 = 'http://pi1.local:8000/stream.mjpg' url2 = 'http://pi2.local:8000/stream.mjpg' #'http://raspi3bp.local:4000/stream.mjpg' url3 = 'http://pi3.local:8000/stream.mjpg' #'http://picamblack.local:5000/stream.mjpg' url4 = 'http://barcodepi.local:8000/stream.mjpg' #'http://picam201902.local:3000/stream.mjpg' threaded = True stream_handler = VideoStreamHandler([url1, url2, url3, url4], threaded=threaded, resolution=(360, 640)) logger.info('loading TRT graph from pb: %s' % pb_path) trt_graph = load_trt_pb(pb_path) logger.info('starting up TensorFlow session') tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True tf_sess = tf.Session(config=tf_config, graph=trt_graph) logger.info('warming up the TRT graph with a dummy image') od_type = 'ssd' dummy_img = np.zeros((720, 1280, 3), dtype=np.uint8) _, _, _ = detect(dummy_img, tf_sess, conf_th=.3, od_type=od_type) # grab image and do object detection (until stopped by user) logger.info('starting to loop and detect') vis = BBoxVisualization(cls_dict) open_display_window(1280, 720) #if threaded: #stream_handler.start() loop_and_detect(stream_handler, tf_sess, 0.2, vis, od_type=od_type) stream_handler.close() logger.info('cleaning up') tf_sess.close() stream_handler.join_streams() cv2.destroyAllWindows()
def main(): logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Ask tensorflow logger not to propagate logs to parent (which causes # duplicated logging) logging.getLogger('tensorflow').propagate = False args = parse_args() logger.info('called with args: %s' % args) # build the class (index/name) dictionary from labelmap file logger.info('reading label map') cls_dict = read_label_map(args.labelmap_file) pb_path = './ssd_mobilenet_v1_coco_people/{}_trt.pb'.format(args.model) log_path = './logs/{}_trt'.format(args.model) print(log_path) if args.do_build: logger.info('building TRT graph and saving to pb: %s' % pb_path) build_trt_pb(args.model, pb_path) logger.info('loading TRT graph from pb: %s' % pb_path) trt_graph = load_trt_pb(pb_path) logger.info('starting up TensorFlow session') tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True tf_sess = tf.Session(config=tf_config, graph=trt_graph) od_type = 'ssd' logger.info('opening cameras') cam1 = cv2.VideoCapture(0) cam2 = cv2.VideoCapture(1) logger.info('starting to loop and detect') vis = BBoxVisualization(cls_dict) show_fps1 = True fps1 = 0.0 show_fps2 = True fps2 = 0.0 tic1 = time.time() tic2 = time.time() # grab images and do object detections (until stopped by user) while True: ret1, frame1 = cam1.read() ret2, frame2 = cam2.read() if ret1 and ret2: box1, conf1, cls1 = detect(frame1, tf_sess, args.conf_th, od_type=od_type) box2, conf2, cls2 = detect(frame2, tf_sess, args.conf_th, od_type=od_type) frame1 = vis.draw_bboxes(frame1, box1, conf1, cls1) frame2 = vis.draw_bboxes(frame2, box2, conf2, cls2) if show_fps1: frame1 = draw_help_and_fps(frame1, fps1) cv2.imshow(WINDOW_NAME1, frame1) toc1 = time.time() curr_fps1 = 1.0 / (toc1 - tic1) # calculate an exponentially decaying average of fps number fps1 = curr_fps1 if fps1 == 0.0 else (fps1 * 0.9 + curr_fps1 * 0.1) tic1 = toc1 if show_fps2: frame2 = draw_help_and_fps(frame2, fps2) cv2.imshow(WINDOW_NAME2, frame2) toc2 = time.time() curr_fps2 = 1.0 / (toc2 - tic2) # calculate an exponentially decaying average of fps number fps2 = curr_fps2 if fps2 == 0.0 else (fps2 * 0.9 + curr_fps2 * 0.1) tic2 = toc2 key = cv2.waitKey(1) if key == 27: # ESC key: quit program break elif key == ord('F') or key == ord('f'): # Toggle fps show_fps1 = not show_fps1 logger.info('cleaning up and closing cameras') tf_sess.close() cam1.release() cam2.release() cv2.destroyAllWindows()
def main(): logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Ask tensorflow logger not to propagate logs to parent (which causes # duplicated logging) logging.getLogger('tensorflow').propagate = False args = parse_args() logger.info('called with args: %s' % args) # build the class (index/name) dictionary from labelmap file logger.info('reading label map') cls_dict = read_label_map(args.labelmap_file) pb_path = './ssd_mobilenet_v1_coco_people/{}_trt.pb'.format(args.model) log_path = './logs/{}_trt'.format(args.model) print(log_path) if args.do_build: logger.info('building TRT graph and saving to pb: %s' % pb_path) build_trt_pb(args.model, pb_path) logger.info('opening camera device/file') #cam1 = Camera(args) #cam1.open() #if not cam1.is_opened: # sys.exit('Failed to open camera #1!') #cam1.start() # ask the camera to start grabbing images logger.info('loading TRT graph from pb: %s' % pb_path) trt_graph = load_trt_pb(pb_path) logger.info('starting up TensorFlow session') tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True tf_sess = tf.Session(config=tf_config, graph=trt_graph) od_type = 'ssd' cam2 = cv2.VideoCapture(1) logger.info('starting to loop and detect') vis = BBoxVisualization(cls_dict) show_fps1 = True fps1 = 0.0 tic1 = time.time() while True: ret2, frame2 = cam2.read() if ret2: box, conf, cls = detect(frame2, tf_sess, args.conf_th, od_type=od_type) frame2 = vis.draw_bboxes(frame2, box, conf, cls) if show_fps1: frame2 = draw_help_and_fps(frame2, fps1) cv2.imshow(WINDOW_NAME2, frame2) toc1 = time.time() curr_fps1 = 1.0 / (toc1 - tic1) # calculate an exponentially decaying average of fps number fps1 = curr_fps1 if fps1 == 0.0 else (fps1*0.9 + curr_fps1*0.1) tic1 = toc1 key = cv2.waitKey(1) if key == 27: # ESC key: quit program break elif key == ord('H') or key == ord('h'): # Toggle help/fps show_fps1 = not show_fps1 # grab image and do object detection (until stopped by user) #open_display_window(cam1.img_width, cam1.img_height) #open_display_window(args.image_width, args.image_height) #loop_and_detect(cam1, tf_sess, args.conf_th, vis, od_type=od_type) #loop_and_detect(cam2, tf_sess, args.conf_th, vis, od_type=od_type) logger.info('cleaning up') #cam1.stop() # terminate the sub-thread in camera tf_sess.close() #cam1.release() cam2.release() cv2.destroyAllWindows()