Skip to content

Feat/core/bytetrack #40

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

Open
wants to merge 80 commits into
base: main
Choose a base branch
from
Open

Feat/core/bytetrack #40

wants to merge 80 commits into from

Conversation

AlexBodner
Copy link
Collaborator

@AlexBodner AlexBodner commented May 5, 2025

Description

This pull request adds the ByteTrack tracker to the list of implemented trackers.

No extra depedencies are required for usage, for testing I used pytest which is in the dev dependencies. The test file can be removed if you consider so, let me know.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

The implementation has been thoroughly tested, passing all the evaluations, and showing the expected results.

The new tracker can be used in the following Google Colab, which shows 2 different examples of the Tracker in its 2 possible modes: using appearance features for high confidence boxes and using IoU.

There is also a test file in the route: trackers/core/bytetrack/tests_bytetrack.py, this tests cover the main functioning of the tracker and check that it behaves as expected.

Any specific deployment considerations

Check trackers/init.py so that it can be imported correctly.
I've updated my trackers/core/deepsort/feature_extractor.py to be exactly like the one in the main branch, but for a reason it compares it to the old one.

@AlexBodner AlexBodner marked this pull request as ready for review May 5, 2025 21:33
Copy link

@rolson24 rolson24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks pretty good! Just have a few comments about organization, but they are just my opinions.

@SkalskiP
Copy link
Collaborator

Hi @onuralpszr — any chance you could take a look at these MyPy issues? They actually originate from @soumik12345’s PR: #49. Your MyPy checks were merged in parallel, so this is the first PR where both changes are part of the same codebase.

I took a look at the errors but couldn’t figure out how to resolve them.

@onuralpszr
Copy link
Collaborator

Hi @onuralpszr — any chance you could take a look at these MyPy issues? They actually originate from @soumik12345’s PR: #49. Your MyPy checks were merged in parallel, so this is the first PR where both changes are part of the same codebase.

I took a look at the errors but couldn’t figure out how to resolve them.

Sure let me take a look.

@onuralpszr onuralpszr requested a review from soumik12345 May 19, 2025 08:50
@@ -28,7 +34,7 @@ class TripletsDataset(Dataset):
Attributes:
tracker_id_to_images (dict[str, list[str]]): Dictionary mapping tracker IDs
to lists of image paths
transforms (Optional[Compose]): Optional image transformations to apply
transforms (Union[Compose, ToTensor]): Image transformations to apply
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onuralpszr what was the reason for making this change? The docstring no longer matches the actual type of the argument it describes.

Copy link
Collaborator

@onuralpszr onuralpszr May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does match and Previous code already enforcing "Compose, ToTensor" in transforms I just added type annotation

self.transforms: Union[Compose, ToTensor] = transforms or ToTensor()

And for the function side you return "Tensor" and I made sure it is Tensor (which is I transformed) but IF* it is actually "Optional" I need to change small bit

Comment on lines +209 to +221
if not hasattr(self.backbone_model, "num_features"):
raise AttributeError(
"Backbone model is missing 'num_features' attribute, "
"cannot add projection layer."
)

num_model_features = getattr(self.backbone_model, "num_features")
if not isinstance(num_model_features, int):
raise TypeError(
f"Backbone model's 'num_features' must be an int, "
f"but got {type(num_model_features)}."
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onuralpszr could you explain why this was needed and how it affected the MyPy check results?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I wanted to be ensure we have that parameter (not related to mypy but cover the missing attribute error)

            if not hasattr(self.backbone_model, "num_features"):
                raise AttributeError(
                    "Backbone model is missing 'num_features' attribute, "
                    "cannot add projection layer."
                )

Mypy part is here (we are not enforcing any so it is fine)

num_model_features = getattr(self.backbone_model, "num_features")

Here since I am getting any it will work but I wanted to make sure for "int" value so I added a check

if not isinstance(num_model_features, int):
    raise TypeError(
        f"Backbone model's 'num_features' must be an int, "
        f"but got {type(num_model_features)}."
    )
    

@@ -38,7 +44,7 @@ def __init__(
transforms: Optional[Compose] = None,
):
self.tracker_id_to_images = validate_tracker_id_to_images(tracker_id_to_images)
self.transforms = transforms or ToTensor()
self.transforms: Union[Compose, ToTensor] = transforms or ToTensor()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.transforms: Union[Compose, ToTensor] = transforms or ToTensor()
self.transforms: Compose = transforms or transforms.Compose([ToTensor()])

@soumik12345 would it make sense to update this line like this? It might help unify the MyPy typing in this part of the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better type hint would be Union[Compose, Callable] because any stateful callables should technically be possible to be composed as transforms.

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.

5 participants