Skip to content

feat(trackers): Implement training ReIDModel using Cross-entropy loss #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

soumik12345
Copy link
Collaborator

@soumik12345 soumik12345 commented Jun 4, 2025

Description

  • Implement an identity dataloader that can be used to train a ReIDModel using cross-entropy loss.
  • Make Market1501 dataset work with the identity dataloader.
  • Implement PK-sampling: randomly sample P distinct IDs from the dataset and then randomly sample K unique images from each ID if possible, duplicate if that ID has < K images. (reference: section 3.1 of ICE: Inter-instance Contrastive Encoding for Unsupervised Person Re-identification)
  • Refactor triplet training logic into TripletsTrainer, executed only when the dataset is a TripletsDataset.
  • Implement fine-tuning with a cross-entropy loss with a projection head + (log?)softmax activation.
  • Experiment with optimal hyperparameters and note results integrating into the updated DeepSORT implementation from feat(trackers): Implementation of Kalman Gating for DeepSORTTracker #17.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Example code snippet

from torch.utils.data import DataLoader
from torch.utils.data.sampler import RandomSampler

from trackers import ReIDModel
from trackers.core.reid.dataset.market_1501 import get_market1501_triplets_dataset

train_dataset, val_dataset = get_market1501_triplets_dataset(
    data_dir="datasets/Market-1501-v15.09.15/bounding_box_train",
    dataset_type="identity",
    split_ratio=0.8,
)

train_loader = DataLoader(
    dataset=train_dataset,
    batch_size=32,
    sampler=RandomSampler(train_dataset),
    drop_last=True,
)

val_loader = DataLoader(
    dataset=val_dataset,
    batch_size=32,
    drop_last=True,
)
reid_model = ReIDModel.from_timm("resnetv2_50.a1h_in1k")

reid_model.train(
    train_loader=train_loader,
    epochs=5,
    validation_loader=val_loader,
    projection_dimension=len(train_dataset),
    freeze_backbone=True,
    learning_rate=5e-4,
    weight_decay=1e-2,
    log_to_wandb=True,
)

@soumik12345 soumik12345 self-assigned this Jun 4, 2025
@soumik12345 soumik12345 marked this pull request as draft June 4, 2025 14:55
@soumik12345 soumik12345 changed the title feat(trackers): Implement identity data loading for training ReIDModel feat(trackers): Implement training ReIDModel using Cross-entropy loss Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant