damo-cv / TransReID-SSL

Self-Supervised Pre-Training for Transformer-Based Person Re-Identification
MIT License
173 stars 20 forks source link

CFS #3

Open jazzseow opened 2 years ago

jazzseow commented 2 years ago

May I know which part of the code includes the CFS ?

michuanhaohao commented 2 years ago

We uploaded the filtered result of the CFS. You can directly use our results to save time. We didn't upload the code and many intermediate models because it is a copy process of the pre-training and fine-tuning. We tested many times and found that CFS was robust. The performance can be easily reproduced.

For the reference, here is the original code of CFS. We didn't clear it.

import torch
from model import make_model
from config import cfg
import torchvision.transforms as T
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
from tqdm import tqdm
import numpy as np
import pickle

if __name__ == "__main__":
    cfg.MODEL.NAME = 'transformer'
    cfg.MODEL.TRANSFORMER_TYPE = 'deit_small_patch16_224_TransReID'
    cfg.MODEL.PRETRAIN_PATH = './model/vit_small_cfs_lup_20ep.pth'
    cfg.INPUT.SIZE_TRAIN = cfg.INPUT.SIZE_TEST = [256,128]
    cfg.TEST.NECK_FEAT = 'before'
    model = make_model(cfg, num_class=1, camera_num=0, view_num = 0)
    model2 = make_model(cfg, num_class=1, camera_num=0, view_num = 0)
    model2.load_param('./log/transreid/vit_small/lup_dino_20ep_mm/transformer_120.pth')
    model = model.cuda()
    model = model.eval()
    model2 = model2.cuda()
    model2 = model2.eval()
    val_transforms = T.Compose([
        T.Resize([256,128]),
        T.ToTensor(),
        T.Normalize(mean=[0.5,0.5,0.5], std=[0.5,0.5,0.5])
        ])

    test_set = ImageFolder(root='./datasets/LUP',transform=val_transforms)
    test_loader = DataLoader(test_set, batch_size=2048, num_workers=4, shuffle=False)
    forget_score = []
    for n_iter, (img, type_id) in enumerate(tqdm(test_loader)):
        with torch.no_grad():
            img = img.cuda()
            feat1 = model(img)
            feat2 = model2(img)
            forget_score.extend(torch.nn.functional.cosine_similarity(feat1,feat2))
    forget_score = torch.tensor(forget_score)
    sorted, indices = torch.sort(forget_score,descending=True)
    save_list = []
    for i in indices:
        save_list.append(test_set.imgs[i][0])
    pickle.dump(save_list, open("./save/cfs_list.pkl", "wb"))
michuanhaohao commented 2 years ago

vit_small_cfs_lup_20ep.pth: pre-train ViT-S on full LUP with 20 epochs. transformer_120.pth: finetune the pre-trained model on Market and MSMT17.

jazzseow commented 2 years ago

Thank you for your explanation.

I have realised you do not use SIE. Is it because SIE is not suitable for cross domain evaluation?

michuanhaohao commented 2 years ago

Thank you for your explanation.

I have realised you do not use SIE. Is it because SIE is not suitable for cross domain evaluation?

SIE can improve the performance, but using SIE is not fair to compare with other methods. Additionally, SIE is not the contribution of this paper.

hh23333 commented 2 years ago

Very solid work! I want to use it as a strong baseline, but using the pretrained model with CFS seems not fair to compare with other works in my task. So, may I ask for the pretrained model w/o CFS or with Imagenet pretraining? Thanks!

siyuch-fdu commented 2 years ago

vit_small_cfs_lup_20ep.pth: pre-train ViT-S on full LUP with 20 epochs. transformer_120.pth: finetune the pre-trained model on Market and MSMT17.

In CFS section, can I use the fully pre-trained model you provided(such as vit_base_ics_384) as model1, and use model1 to finetune in our own dataset as model2, then use model1 and model2 to generate cfs list?