0

i'm trying to extract the features vector (128 dim) for deepSORT tracking. I'm using the framework Detectron2. I saw the following code for features extraction:

image = cv2.imread('my_image.jpg')
height, width = image.shape[:2]
image = torch.as_tensor(image.astype("float32").transpose(2, 0, 1))
inputs = [{"image": image, "height": height, "width": width}]
with torch.no_grad():
    images = model.preprocess_image(inputs)  # don't forget to preprocess
    features = model.backbone(images.tensor)  # set of cnn features
    proposals, _ = model.proposal_generator(images, features, None)  # RPN

    features_ = [features[f] for f in model.roi_heads.box_in_features]
    box_features = model.roi_heads.box_pooler(features_, [x.proposal_boxes for x in proposals])
    box_features = model.roi_heads.box_head(box_features)  # features of all 1k candidates
    predictions = model.roi_heads.box_predictor(box_features)
    pred_instances, pred_inds = model.roi_heads.box_predictor.inference(predictions, proposals)
    pred_instances = model.roi_heads.forward_with_given_boxes(features, pred_instances)

    # output boxes, masks, scores, etc
    pred_instances = model._postprocess(pred_instances, inputs, images.image_sizes)  # scale box to orig size
    # features of the proposed boxes
    feats = box_features[pred_inds]

but i don't understand how to extract the 128 dimensional feature vector, from this piece of code. I would be happy for a little help here. thanks in advance.

Smadar
  • 1
  • 1
  • 1
  • Would you explain which variable has 128 dimensional feature vector and how it is formed? – Reza Akraminejad Nov 23 '21 at 12:05
  • As I can see in this paper, we have 'p2', 'p3, ..., 'p6' https://medium.com/@hirotoschwert/digging-into-detectron-2-part-5-6e220d762f9 each one of those ('p2', 'p3'..) contains features data, and i want to know how to use this info about the object detected to perform deepSORT tracking That feature vector becomes our “appearance descriptor” of the object. – Smadar Nov 23 '21 at 12:27

0 Answers0