def __init__(self, config_file = 'config.cfg', model = 'hg_refined_tiny_200', yoloModel = 'YOLO_small.ckpt', disable_yolo = True): """ Initilize the Predictor Args: config_file : *.cfg file with model's parameters model : *.index file's name. (weights to load) yoloModel : *.ckpt file (YOLO weights to load) """ t = time() params = process_config(config_file) self.predict = PredictProcessor(params) self.predict.color_palette() self.predict.LINKS_JOINTS() self.predict.model_init() self.predict.load_model(load = model) if disable_yolo: pass else: self.predict.yolo_init() self.predict.restore_yolo(load = yoloModel) self.predict._create_prediction_tensor() if True: pass else: self.filter = VideoFilters() print('Done: ', time() - t, ' sec.')
def __init__(self, config_file = 'config.cfg', model = 'hg_refined_tiny_200', yoloModel = 'YOLO_small.ckpt'): """ Initilize the Predictor Args: config_file : *.cfg file with model's parameters model : *.index file's name. (weights to load) yoloModel : *.ckpt file (YOLO weights to load) """ t = time() params = process_config(config_file) self.predict = PredictProcessor(params) self.predict.color_palette() self.predict.LINKS_JOINTS() self.predict.model_init() self.predict.load_model(load = model) self.predict.yolo_init() self.predict.restore_yolo(load = yoloModel) self.predict._create_prediction_tensor() self.filter = VideoFilters() print('Done: ', time() - t, ' sec.')
def show_prections(img, predictions, name): for index, coord in enumerate(predictions): keypt = (int(coord[1]), int(coord[0])) text_loc = (keypt[0] + 7, keypt[1] + 7) cv2.circle(img, keypt, 3, Palette[index], -1) cv2.putText(img, str(index), text_loc, cv2.FONT_HERSHEY_DUPLEX, 0.5, Palette[index], 1, cv2.LINE_AA) cv2.imwrite(os.path.join(params['test_result_directory'], name), img) if __name__ == '__main__': print('-- Parsing Config File') params = process_config('./config.cfg') model = Inference(model=params['pretrained_model']) bbox1 = [692, 1250, 1246, 1934] bbox2 = [76, 810, 626, 1330] bbox3 = [998, 888, 1602, 1400] bbox4 = [670, 440, 1156, 856] bounding_box = { 'cam_00_10_30': bbox1, 'cam_01_10_30': bbox2, 'cam_02_10_30': bbox3, 'cam_03_10_30': bbox4 } img_paths = os.listdir(params['test_img_directory']) for img_path in img_paths: img = cv2.imread(os.path.join(params['test_img_directory'], img_path)) bbox = bounding_box[img_path[0:12]]
y = int(box[2]) w = int(box[3] / 2) h = int(box[4] / 2) prob = box[5] bbox = np.asarray((max(0,x-w), max(0, y-h), min(shapeOd[1]-1, x+w), min(shapeOd[0]-1, y+h))) cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 255, 0), 2) cv2.rectangle(frame, (bbox[0], bbox[1] - 20),(bbox[2], bbox[1]), (125, 125, 125), -1) cv2.putText(frame, class_name + ' : %.2f' % prob, (bbox[0] + 5, bbox[1] - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1) fps = 1/(time() - t) cv2.putText(frame, str(fps)[:4] + ' fps' + ' PinS:' + str(len(result)), (20, 20), 2, 1, (0,0,0), thickness = 2) cv2.imshow('Camera', frame) ret, frame = cap.read() if cv2.waitKey(1) == 27: print('Stream Ended') cv2.destroyAllWindows() cap.release() cv2.destroyAllWindows() cap.release() if __name__ == '__main__': t = time() params = process_config('configTiny.cfg') predict = PredictProcessor(params) predict.color_palette() predict.LINKS_JOINTS() predict.model_init() predict.load_model(load = 'hg_refined_tiny_200') predict.yolo_init() predict.restore_yolo(load = 'YOLO_small.ckpt') predict._create_prediction_tensor() print('Done: ', time() - t, ' sec.')