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()