def __init__(self, img, truth, is_training, batcn_norm_decay=0.997): self.img = img self.truth = truth self.is_training = is_training self.batch_norm_decay = batcn_norm_decay self.img_shape = tf.shape(self.img) backbone = Network() if is_training: self.head, self.l2_loss = backbone.inference(self.is_training, self.img) else: self.head = backbone.inference(self.is_training, self.img)
def __init__(self, img, age_labels, age_vector, is_training, batcn_norm_decay=0.997): self.img = img self.age_labels = age_labels self.age_vector = age_vector self.is_training = is_training self.batch_norm_decay = batcn_norm_decay self.img_shape = tf.shape(self.img) backbone = Network() if is_training: self.feats, self.pred, self.l1_loss = backbone.inference(self.is_training, self.img) else: self.feats, self.pred = backbone.inference(self.is_training, self.img)
if args.cfg: cfg_from_file(args.cfg) net = Network() checkpoint = torch.load(osp.abspath(args.checkpoint)) net.load_state_dict(checkpoint["model"]) logging.info("Loaded checkpoint from: %s" % args.checkpoint) net.eval() device = torch.device("cuda:%s" % args.gpu if args.gpu != -1 else "cpu") net.to(device) # Extract feature of the query person query_img = cv2.imread("imgs/query.jpg") query_roi = np.array([0, 0, 466, 943]) # [x1, y1, x2, y2] query_feat = net.inference(query_img, query_roi).view(-1, 1) # Get gallery images gallery_imgs = sorted(glob("imgs/gallery*.jpg")) for gallery_img in gallery_imgs: logging.info("Detecting %s" % gallery_img) detections, features = net.inference(cv2.imread(gallery_img)) # Compute pairwise cosine similarities, # which equals to inner-products, as features are already L2-normed similarities = features.mm(query_feat).squeeze() # Visualize the results visualize_result(gallery_img, detections, similarities)
# which equals to inner-products, as features are already L2-normed similarities = features.mm(query_feat).squeeze() # Visualize the results visualize_result(gallery_img, detections, similarities) """ #### For video file cap = cv2.VideoCapture("data/dataset/video/handmovewhite.mp4") #### For video camera #cap = cv2.VideoCapture(0) query_img = cv2.imread("data/dataset/video/query.png") query_roi = np.array([0, 0, 313, 733]) query_feat = net.inference(query_img, query_roi).view(-1, 1) scale_percent = 50 width = int(cap.get(3) * scale_percent / 100) height = int(cap.get(4) * scale_percent / 100) dim = (width, height) output_video = cv2.VideoWriter("output/output_video.avi", cv2.VideoWriter_fourcc('M','J','P','G'), 20.0, (width, height)) no_frame = 1 while cap.isOpened(): ret, frame = cap.read() if not ret: print("Can't receive frame (stream end?). Exiting ...")