liming-ai / AlignDet

Official code for ICCV 2023 Paper: AlignDet: Aligning Pre-training and Fine-tuning in Object Detection.
https://liming-ai.github.io/AlignDet/
Apache License 2.0
142 stars 13 forks source link

About Box-domain Contrastive Learning #23

Closed NewbeeFL closed 10 months ago

NewbeeFL commented 10 months ago

Hello,dear author,it's a nice work!I have been thoroughly studying your article and delving into the associated code and implementations. And i have a small question In Section 3.2, specifically in the Box-domain Contrastive Learning part, I have a question regarding the following statement:

"For each query box q ∈ Q, assuming its assigned proposal index is i and the feature is zq. The set of positive keys K+ and negative keys K− for query feature zq can be constructed as: Z{+} = \left{z \in Z{1}:l=i \right}"

Upon examining your code, I noticed that there might be a correction needed in this statement. It seems that the correct formulation could be:

"Z{+} = \left{z \in Z{2}:l=i \right}"

Here is the relevant section of your original code: \models\roi_heads\bbox_heads\convfc_bbox_head.py line 142

# ... (previous code)
for label in torch.unique(online_labels):
    # ignore the background class
    if label == self.num_classes:
        continue

    query_inds = (online_labels == label) * (online_label_weights > 0)
    key_inds   = (target_labels == label) * (target_label_weights > 0)
    online_neg_inds = (online_labels != label) * (online_label_weights > 0)
    target_neg_inds = (target_labels != label) * (target_label_weights > 0)

    num_valid_labels += 1

    query = cls_online[query_inds]
    key = cls_target[key_inds] if key_inds.sum() > 0 else query
    neg = torch.cat([cls_online[online_neg_inds], cls_target[target_neg_inds]])

    loss_cls_ = loss_cls_ + self.loss_cls(query, key, neg, avg_factor=avg_factor)

losses['loss_cls'] = loss_cls_ / num_valid_labels
# ... (remaining code)

I wanted to bring this to your attention and seek clarification. If I have misunderstood something, please guide me in the right direction. I greatly appreciate your work and expertise in this field.

Best regards

liming-ai commented 10 months ago

Z{+} = \left{z \in Z{2}:l=i \right}

@NewbeeFL Yes, you are right. Z_{+} = \left{z \in Z_{2}:l=i \right} should be the correct formulation. Thanks for pointing out this error.

liming-ai commented 10 months ago

Feel free to reopen this issue if you have more questions.