fix: batch 1 fixes - various improvements#204
Conversation
… in processing loop
📝 WalkthroughWalkthrough
ChangesTracking lifecycle updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/tracking/tracker.py`:
- Around line 126-140: Stop assigning the re-identification result directly to
DeepSort’s managed ID in the ReID matching block. Remove the t.track_id =
lost_id mutation and store the matched persistent ID separately from DeepSort’s
track ID, updating downstream application-owned tracking data to use that
separate identifier.
- Around line 186-196: The LOST embedding lookup in the lifecycle handling must
retain stale confirmed tracks from the raw tracking results while excluding
their IDs from current_ids. Update the current_ids construction and related
track collection logic near the LOST branch so stale confirmed tracks remain
available to the track lookup without being treated as active, preserving the
existing embedding capture behavior in _lost_embeddings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cfea92fb-41d7-451e-a5b7-3fe5d20bfd59
📒 Files selected for processing (1)
services/tracking/tracker.py
| # ── ReID matching ───────────────────────────────────── | ||
| if hasattr(t, "features") and t.features: | ||
| new_embedding = t.features[-1] | ||
| for lost_id, data in list(self._lost_embeddings.items()): | ||
| age = self._frame_id - data["last_seen"] | ||
| if age > self.max_age: | ||
| continue | ||
| similarity = self._cosine_similarity( | ||
| new_embedding, | ||
| data["embedding"], | ||
| ) | ||
| if similarity > self.REID_SIMILARITY_THRESHOLD: | ||
| tid = lost_id | ||
| t.track_id = lost_id | ||
| del self._lost_embeddings[lost_id] |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🌐 Web query:
For the deep-sort-realtime version declared by this repository: does update_tracks()retain lost tracks untilmax_age, and is Track.track_id supported as a mutable application-owned field?
💡 Result:
In the deep-sort-realtime repository, the update_tracks() method does retain tracks that have lost their association with detections until they exceed the max_age threshold, at which point they are deleted [1][2]. During this period, confirmed tracks continue to perform Kalman filter predictions on their bounding box states [2]. Regarding Track.track_id, it is not intended to be a mutable, application-owned field. The track_id is managed internally by the tracker to ensure uniqueness across the sequence (or daily, if the today parameter is used) [1][3]. While you can access track.track_id as a string, it is dynamically generated by the library [3]. If you require custom track-related metadata or application-specific identifiers, the recommended approach is to subclass the Track class and pass it to the DeepSort constructor via the override_track_class argument [4][5]. This allows you to include your own mutable fields or logic within your custom track implementation [4][5].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 2: Deep sort remembering bad state levan92/deep_sort_realtime#43
- 3: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 4: https://pypi.org/project/deep-sort-realtime/
- 5: https://pypi.org/project/tactus-deep-sort-realtime/
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate tracker files and deps =="
fd -a 'tracker.py$|requirements.*|pyproject.toml|poetry.lock|Pipfile|Pipfile.lock|uv.lock|setup.py|setup.cfg' . | sed 's#^\./##' | head -200
echo
echo "== services/tracking/tracker.py outline/lines =="
wc -l services/tracking/tracker.py
sed -n '1,260p' services/tracking/tracker.py
echo
echo "== deepsort declarations/usages =="
rg -n "DeepSort|deep_sort|max_age|DEEP_SORT|deep-sort" -S . --glob '!**/.git/**' | head -300
echo
echo "== lock/package references for deep_sort_realtime =="
for f in poetry.lock requirements.txt pyproject.toml Pipfile.lock uv.lock setup.py setup.cfg; do
[ -f "$f" ] && { echo "--- $f"; rg -n "deep_sort_realtime|deep-sort-realtime|DeepSort" "$f" -S || true; }
doneRepository: Devnil434/Eagle
Length of output: 16555
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== installed deep-sort-realtime package/source, if available =="
python3 - <<'PY'
import importlib.util
import os
print("spec:", importlib.util.find_spec("deep_sort_realtime"))
try:
import deep_sort_realtime.deepsort_tracker as ds
print("file:", ds.__file__)
print("has update_tracks:", hasattr(ds.DeepSort, "update_tracks"))
except Exception as e:
print("import_error:", repr(e))
PY
if python3 - <<'PY' >/tmp/ds_source_path.txt 2>/tmp/ds_import_err.txt
import importlib.util
spec = importlib.util.find_spec("deep_sort_realtime")
print(spec.origin if spec else "NOT_FOUND")
PY
then
FILE=$(cat /tmp/ds_source_path.txt)
echo
echo "== deep_sort_realtime file excerpts:"
wc -l "$FILE"
sed -n '1,90p' "$FILE"
echo "--- update_tracks and track_id references ---"
rg -n "def update_tracks|class Track|track_id|max_age|self\._tracks" "$FILE" -A 3 -B 3
fi
echo
echo "== local dependency pin =="
sed -n '1,80p' services/tracking/requirements.txt
echo
echo "== repo's local tests around ReID / lost mutation semantics =="
sed -n '320,470p' tests/test_tracker.pyRepository: Devnil434/Eagle
Length of output: 381
🌐 Web query:
deep-sort-realtime 1.3.2 deep_sort_realtime/deepsort_tracker.py update_tracks Track track_id
💡 Result:
In the deep-sort-realtime library (including version 1.3.2), the update_tracks method is the primary API call used to process object detections for a given frame [1][2][3]. When you call tracker.update_tracks(detections, frame=frame), it returns a list of active Track objects [1][3]. To access the unique identifier for a specific track, you iterate through this list of returned track objects and access the track_id attribute [1][3][4]. The standard usage pattern is as follows: tracks = tracker.update_tracks(bbs, frame=frame) for track in tracks: if not track.is_confirmed: continue # Access the unique track ID here track_id = track.track_id # You can also retrieve bounding box coordinates, e.g., ltrb = track.to_ltrb The track_id is typically a unique string (e.g., "1" or "2024-06-01_3") assigned to each object being tracked [3]. Only tracks that have passed the confirmation threshold (typically determined by consecutive detections) are usually processed, which is why it is standard practice to check if track.is_confirmed before using the track_id [1][3][5].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime
- 2: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 3: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 4: https://learnopencv.com/real-time-deep-sort-with-torchvision-detectors/
- 5: https://fxis.ai/edu/how-to-setup-and-use-deep-sort-for-real-time-object-tracking/
🌐 Web query:
github.com levan92 deep_sort_realtime deepsort_tracker.py 1.3.2 update_tracks max_age delete
💡 Result:
In the levan92/deep_sort_realtime library, specifically in the context of deepsort_tracker.py and the Tracker class, max_age is a parameter used to control how long a track persists without a corresponding detection [1]. Key details regarding max_age and track deletion include: - Purpose: max_age defines the maximum number of consecutive frames (or missed detections) allowed before a track is considered lost and is deleted from the tracker [1]. - Configuration: You can set this value when instantiating the DeepSort object [2][3]. For example, tracker = DeepSort(max_age=5) sets the tracker to allow 5 consecutive missed detections before deleting a track [2][4]. - Behavior: When a track does not receive a matching detection in a frame, the library performs a Kalman prediction to estimate the object's position [3]. The track remains in the tracker's list as long as the number of consecutive missed updates is less than or equal to max_age [1][3]. - Filtering: If you want to exclude tracks that are currently relying on Kalman predictions (i.e., not matched to a raw detection in the current frame), you can filter them by checking if track.time_since_update > 0 [3]. Additionally, it is standard practice to use track.is_confirmed() to ignore tentative tracks that have not yet reached the required number of consecutive detections to be considered stable [2][3]. The v1.3.2 release (published February 2023) maintained these fundamental tracking mechanics while introducing features such as background masking, updated numpy compatibility, and exposed hyperparameters like max_iou_distance [5].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 2: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 3: Deep sort remembering bad state levan92/deep_sort_realtime#43
- 4: https://pypi.org/project/deep-sort-realtime/
- 5: https://github.com/levan92/deep_sort_realtime/releases/tag/v1.3.2
🌐 Web query:
site:github.com/levan92/deep_sort_realtime "class Track" "track_id" "deep_sort_realtime"
💡 Result:
In the deep_sort_realtime library, the Track class represents an individual object being tracked [1][2]. You access the unique identifier for a tracked object through the track_id attribute of a Track instance [1][3]. When you call tracker.update_tracks(bbs, frame=frame), it returns a list of Track objects [1][2]. You can iterate through this list to access the track_id for each active track: for track in tracks: if not track.is_confirmed: continue track_id = track.track_id # Additional processing, e.g., using track.to_ltrb Key details regarding the Track class and track_id include: 1. Tracking Lifecycle: A track is typically considered active once it reaches the confirmed state, which occurs after being associated with detections for n_init consecutive frames (default is 3) [4][5][3]. 2. ID Generation: The track_id is managed by the Tracker class [5]. If a today argument is provided during the initialization of the DeepSort tracker, the track_id is formatted as {today}_{_next_id}; otherwise, it is simply the string representation of the incremental _next_id [5]. This date-based formatting helps prevent ID overflow and reset IDs for long-running systems [2]. 3. Customization: You can implement custom logic within the track object by creating a subclass of the Track class and passing it to the DeepSort constructor using the override_track_class argument [1][2]. Sources: [1][4][2][5][3]
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 2: https://github.com/levan92/deep_sort_realtime
- 3: Implementation of Deep sort with yolo as an object detection levan92/deep_sort_realtime#45
- 4: Sample Code levan92/deep_sort_realtime#25
- 5: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
🌐 Web query:
raw.githubusercontent.com levan92 deep_sort_realtime v1.3.2 deep_sort_realtime/deep_sort/tracker.py "delete" "max_age"
💡 Result:
In the levan92/deep_sort_realtime repository (version 1.3.2), the max_age parameter is a configurable integer that defines the maximum number of consecutive frames a track can remain active without being associated with a new detection before it is marked as Deleted [1][2]. It is defined in the Tracker class within deep_sort_realtime/deep_sort/tracker.py [1]. While the source code provides the parameter as an argument to the Tracker constructor (defaulting to 30) [1], users typically interact with it through the DeepSort class constructor in deep_sort_realtime/deepsort_tracker.py, which passes the max_age value down to the underlying Tracker instance [3][2]. To modify the max_age value, you do not "delete" the parameter; rather, you specify a new integer value when initializing the DeepSort object in your code [3][2]: python from deep_sort_realtime.deepsort_tracker import DeepSort # Set max_age to your desired number of frames (e.g., 5) tracker = DeepSort(max_age=5) The max_age parameter is used by the tracker's internal logic to determine the lifespan of tracks that are not matched during the detection association process [1][2]. There is no requirement or functionality to remove or "delete" this parameter from the source code to use the library; it is designed to be tuned by the user to suit specific tracking requirements [3][2].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
🌐 Web query:
deep-sort-realtime source "delete_tracks" "max_age" "time_since_update"
💡 Result:
In the deep-sort-realtime library, max_age, time_since_update, and track deletion work together to manage the lifecycle of tracked objects [1][2]. max_age This is a hyperparameter initialized when creating the DeepSort tracker (e.g., DeepSort(max_age=30)) [3][4]. It defines the maximum number of consecutive frames a track can remain in the system without being associated with a new detection before it is deleted [1][2]. time_since_update This is a property of a Track object that indicates the number of frames elapsed since the track was last successfully matched with a detection [2]. - When a track is matched to a detection in the current frame, its time_since_update is reset to 0 [2]. - If a track is not matched in a frame, the tracker uses Kalman filtering to predict its state, and the time_since_update increments [2][4]. - A track is deleted once its time_since_update exceeds the max_age threshold [1][2]. Manual Deletion To manually clear all active tracks and reset the tracker's internal ID counter to 1, you can use the delete_all_tracks method [1][2]: tracker.delete_all_tracks Additional Filtering If you wish to ignore "ghost" tracks (tracks that exist only via Kalman prediction and haven't been updated by a recent detection), you can manually filter tracks in your processing loop using time_since_update [4]: for track in tracks: if not track.is_confirmed or track.time_since_update > 0: continue
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: https://github.com/levan92/deep_sort_realtime
- 4: Deep sort remembering bad state levan92/deep_sort_realtime#43
Do not mutate the DeepSort-managed track ID.
max_age tracks can remain in DeepSort’s active state while missing detections, so reassigning t.track_id = lost_id can overwrite DeepSort’s tracking metadata for the lost ID and corrupt the _active_tracks entry/trajectory for that persistent ID. Keep DeepSort IDs separate from re-ID persistent IDs, or use a custom override_track_class for application-owned track data.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@services/tracking/tracker.py` around lines 126 - 140, Stop assigning the
re-identification result directly to DeepSort’s managed ID in the ReID matching
block. Remove the t.track_id = lost_id mutation and store the matched persistent
ID separately from DeepSort’s track ID, updating downstream application-owned
tracking data to use that separate identifier.
| # ── Lifecycle: LOST for tracks that disappeared ──────────────────── | ||
| for tid, prev_obj in list(self._active_tracks.items()): | ||
| if tid not in current_ids: | ||
| frames_since = self._frame_id - prev_obj.last_seen_frame | ||
| track = next((t for t in raw_tracks if int(t.track_id) == tid), None) if frames_since == 1 else None | ||
|
|
||
| if track is not None and hasattr(track, "features") and track.features: | ||
| self._lost_embeddings[tid] = { | ||
| "embedding": track.features[-1], | ||
| "last_seen": self._frame_id, | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Inspect the repository's declared DeepSort version and existing Track API usage.
rg -n -C2 'deep-sort|deep_sort|deep-sort-realtime' \
--glob 'pyproject.toml' --glob 'requirements*.txt' --glob 'poetry.lock' --glob 'uv.lock' .
rg -n -C3 '\b(update_tracks|time_since_update|track_id)\b' services/tracking/tracker.pyRepository: Devnil434/Eagle
Length of output: 3057
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== tracker.py outline =="
ast-grep outline services/tracking/tracker.py --view compact || true
echo "== tracker.py relevant section =="
sed -n '80,210p' services/tracking/tracker.py
echo "== dependency version/manifest =="
cat services/tracking/requirements.txtRepository: Devnil434/Eagle
Length of output: 6229
🌐 Web query:
deep-sort-realtime v1.3.2 update_tracks filter_confirmed_time_since_update source
💡 Result:
In the deep-sort-realtime library (including version 1.3.2), update_tracks is the primary method used to update object tracks with new detections [1][2]. The filter_confirmed_time_since_update parameter is not a standard, built-in argument for the update_tracks method [1][2]. Instead, track filtering based on state (such as whether a track is confirmed or how many frames have passed since its last update) is handled manually by the user when iterating through the list of returned tracks [3][2]. You can implement this filtering logic using the following attributes available on the Track object: 1. track.is_confirmed: Returns a boolean indicating if the track has been successfully initialized (typically after a required number of consecutive detections) [2]. 2. track.time_since_update: An integer representing the number of frames since the track was last matched to a detection (0 indicates a match occurred in the current frame) [2]. Example usage for filtering: tracks = tracker.update_tracks(detections, frame=frame) for track in tracks: # Filter for confirmed tracks that have been updated recently (e.g., within 5 frames) if not track.is_confirmed or track.time_since_update > 5: continue # Process valid track track_id = track.track_id bbox = track.to_ltrb The time_since_update value is managed internally by the tracker based on the max_age parameter, which you can set when initializing the DeepSort object to define how long a track remains alive without new detections [3].
Citations:
- 1: https://pypi.org/project/deep-sort-realtime/
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: Deep sort remembering bad state levan92/deep_sort_realtime#43
🌐 Web query:
"deep-sort-realtime" "update_tracks" "filter_confirmed" "time_since_update"
💡 Result:
In the deep_sort_realtime library, the status and lifecycle of tracked objects are managed through the Track class and the update process [1][2]. While filter_confirmed and time_since_update are key internal attributes used to manage track state, they are typically accessed via helper methods rather than direct parameters in the update_tracks function [1][2]. 1. filter_confirmed (is_confirmed): Tracks are initialized as tentative and must achieve a certain number of consecutive detections (defined by the n_init parameter during DeepSort initialization) to become confirmed [1][2]. The is_confirmed method is the standard way to check this status [3][2]. It is commonly used in implementation loops to filter out unstable or false-positive detections, for example: if not track.is_confirmed: continue 2. time_since_update: This attribute tracks how many consecutive frames have passed since a track was last matched with a detection [1][4]. It is a critical internal component of the tracker's logic for determining when a track should be marked as missed or deleted [1][4]. When a track's time_since_update exceeds the max_age parameter (set during DeepSort instantiation), the track is typically deleted [1][5]. In summary, users typically do not pass these as arguments to update_tracks. Instead, you interact with them by: - Filtering results using track.is_confirmed to ensure you are only processing stable tracks [3][2]. - Relying on the internal max_age parameter to automatically prune old, unmatched tracks [5].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 2: Sample Code levan92/deep_sort_realtime#25
- 3: https://github.com/Cranfield-GDP3/deep_sort_realtime
- 4: https://github.com/nwojke/deep_sort/blob/master/deep_sort/tracker.py
- 5: https://context7.com/levan92/deep_sort_realtime/llms.txt
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== deep_sort_realtime installed package files =="
python3 - <<'PY'
import importlib.util, os
spec = importlib.util.find_spec("deep_sort_realtime")
print(f"deep_sort_realtime found: {spec is not None}")
print(f"origin: {spec.origin}")
PY
if python3 - <<'PY'
import importlib.util
print(importlib.util.find_spec("deep_sort_realtime") is not None)
PY
then
python3 - <<'PY'
import deep_sort_realtime.deep_sort as ds
import inspect
print(inspect.getfile(ds))
PY
echo "== deepsortracker source =="
python3 - <<'PY'
import deep_sort_realtime.deep_sort.tracker as tracker_module
print(inspect.getsource(tracker_module.DeepSortTracker))
PY
fi
echo "== local deepsort init in repo =="
rg -n -C4 'DeepSort\(|deep_sort_realtime|tracker' . \
--glob '!**/*.png' '--glob !**/*.lock'Repository: Devnil434/Eagle
Length of output: 367
🌐 Web query:
github levan92 deep-sort-realtime tracker.py deepsort.update_tracks time_since_update is_confirmed
💡 Result:
In the levan92/deep_sort_realtime library, the update_tracks method is the primary interface for processing detections and updating the internal state of tracked objects [1][2]. update_tracks This method is called on the DeepSort object to perform both prediction (Kalman filter propagation) and measurement updates (matching detections to tracks) for every frame [3][4]. It accepts a list of detections and returns a list of track objects [1][5]. time_since_update This property represents the number of frames that have passed since a track was last successfully matched with a detection [6]. A value of 0 indicates that the track was matched with a detection in the current frame [6]. is_confirmed This method returns a boolean indicating the lifecycle state of a track [6]. A track is considered confirmed once it has achieved a sufficient number of consecutive hits (initialization matches) as defined by the tracker configuration [6]. Tracks that are not yet confirmed are typically referred to as tentative or provisional [6]. Usage in tracker.py The tracker.py module manages the collection of tracks, performing the matching cascade and updating track states [3]. During iteration over the output of update_tracks, it is standard practice to filter out unconfirmed tracks if you only wish to process objects that have been reliably identified [1][2][6]. Example usage: for track in tracks: if not track.is_confirmed: continue # Process confirmed track track_id = track.track_id ltrb = track.to_ltrb
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 2: https://github.com/levan92/deep_sort_realtime
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 4: Clarification on how tracking works levan92/deep_sort_realtime#23
- 5: https://pypi.org/project/tactus-deep-sort-realtime/
- 6: https://context7.com/levan92/deep_sort_realtime/llms.txt
🌐 Web query:
deep_sort_realtime deep_sort/tracker.py def update_tracks source
💡 Result:
In the deep-sort-realtime library, the update_tracks method is the primary API used to process detections and update track states for a given frame [1][2]. While there is a tracker.py file located within the deep_sort/ directory of the repository, this file contains the internal multi-target tracker logic (such as the predict and update methods) used by the library [3]. The end-user API, which is commonly called in implementation scripts, is defined in the DeepSort class within deepsort_tracker.py [4][1]. The update_tracks method in deepsort_tracker.py performs the following high-level operations: 1. Receives raw detections (expected as a list of tuples in ( [left, top, w, h], confidence, detection_class) format) and an optional frame for embedding [1][2]. 2. Optionally computes appearance embeddings for the detections if they are not pre-computed [1][2]. 3. Passes these detections to the internal tracker (the one defined in tracker.py) to perform Kalman filter prediction and data association [3]. 4. Returns a list of active Track objects, which can be queried for information like track IDs and bounding box coordinates [1][2]. For implementation, users typically import and use it as follows: from deep_sort_realtime.deepsort_tracker import DeepSort tracker = DeepSort(max_age=5) tracks = tracker.update_tracks(bbs, frame=frame)
Citations:
- 1: https://github.com/levan92/deep_sort_realtime
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deep_sort/tracker.py
- 4: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
python3 - <<'PY'
import tarfile
import urllib.request
url = "https://files.pythonhosted.org/packages/9b/25/aa3e3e1822c010a92c916f1a0e50057667c6b156296a235d65ec36069bb/deep-sort-realtime-1.3.2.tar.gz"
tmp = "/tmp/deep_sort_realtime-1.3.2.tar.gz"
print("Downloading", url)
urllib.request.urlretrieve(url, tmp)
print("Downloaded", tmp)
with tarfile.open(tmp, "r:gz") as tf:
names = [n for n in tf.getnames() if n.endswith(".py")]
for n in names:
if "deepsort" in n or "tracker.py" in n:
print(n)
# Read only the relevant source text.
for n in [
"deep-sort-realtime-1.3.2/deep_sort_realtime/deepsort_tracker.py",
"deep-sort-realtime-1.3.2/deep_sort_realtime/deep_sort/tracker.py",
]:
print("\n==", n, "==")
try:
source = tf.extractfile(n).read().decode("utf-8")
except KeyError:
continue
for needle in ["def update_tracks", "time_since_update", "return self.tracks"]:
try:
idx = source.index(needle)
before = max(0, source.rindex("\n", 0, idx - 1) if idx > 0 else 0)
after = source.index("\n", source.index("\n", idx) + 1 if idx < len(source) - 1 else idx)
window = source[before:after]
except ValueError:
window = None
print(f"*** {needle} ***")
print("\n".join(f"{i+1}: {line}" for i,line in enumerate(window.splitlines(), start=1)))
# Also print methods around update_tracks with line numbers.
lines = source.splitlines()
start, end = None, None
for i,l in enumerate(lines):
if "def update_tracks" in l or "def __init__" in l and start is None:
start = i
if start is not None and i > start and l.startswith((" def ", "class ")):
end = i; break
if start:
if not end: end = min(len(lines), start+120)
print(f"\n== source lines {start+1}-{end} ==")
for i in range(start, end):
print(f"{i+1}: {lines[i]}")
PYRepository: Devnil434/Eagle
Length of output: 3072
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Pin the dependency, then inspect the exact source text from the PyPI wheel/tarball.
python3 - <<'PY'
import hashlib, tarfile, urllib.request
url = "https://files.pythonhosted.org/packages/9b/25/aa3e3e1822c010a92c916f1a0e50057667c6b156296a235d65ec36069bb/deep-sort-realtime-1.3.2.tar.gz"
dest = "/tmp/deep-sort-realtime-1.3.2.tar.gz"
req = urllib.request.Request(url)
req.add_header("User-Agent", "CodeRabbit-verification")
try:
with urllib.request.urlopen(req, timeout=20, cafile=None) as resp:
data = resp.read()
except Exception as e:
# Fallback to self-signed-cert-aware fetch only if needed; print cause.
print("FALLBACK_FETCH", type(e).__name__, e)
import ssl
ctx = ssl._create_unverified_context()
with urllib.request.urlopen(url, timeout=20, context=ctx) as resp:
data = resp.read()
print("sha256", hashlib.sha256(data).hexdigest())
with open(dest, "wb") as f:
f.write(data)
with tarfile.open(dest, "r:gz") as tf:
for n in [
"deep-sort-realtime-1.3.2/deep_sort_realtime/deepsort_tracker.py",
"deep-sort-realtime-1.3.2/deep_sort_realtime/deep_sort/tracker.py",
]:
print(f"\n===== {n} =====")
try:
src = tf.extractfile(n).read().decode("utf-8")
except KeyError:
print("MISSING")
continue
lines = src.splitlines()
print("total", len(lines))
for keyword in ["def update_tracks", "def __init__", "class DeepSort"]:
print(f"\n--- matches for {keyword} ---")
for i,l in enumerate(lines):
if keyword in l:
start=max(1,i-12); end=min(len(lines),i+50)
for j in range(start,end+1):
print(f"{j}: {lines[j-1]}")
print("\n===== exact update_tracks substring (with context) =====")
with tarfile.open(dest, "r:gz") as tf:
try:
src = tf.extractfile("deep-sort-realtime-1.3.2/deep_sort_realtime/deepsort_tracker.py").read().decode("utf-8")
except KeyError:
raise SystemExit
for needle in ["def update_tracks"]:
idx = src.index(needle)
start = src.rfind("\n", 0, idx)
end = src.index("\n", src.index("\n", idx) + 1) if idx < len(src)-1 else len(src)
print(f"--- {needle} ---")
print(src[start:end])
print("--- line count of this class block ---")
lines = src[start:end+1].splitlines()
print(len(lines))
print("\n".join(f"{i+1}: {lines[i]}" for i in range(len(lines))))
PYRepository: Devnil434/Eagle
Length of output: 3928
🌐 Web query:
raw.githubusercontent.com levan92 deep-sort-realtime 1.3.2 deep_sort_realtime deepsort_tracker.py update_tracks
💡 Result:
The deep_sort_realtime library, maintained by levan92 on GitHub, is a real-time adaptation of the original Deep SORT algorithm [1][2]. Version 1.3.2 is the latest release, published on February 11, 2023 [3]. In the deep_sort_realtime.deepsort_tracker module, the update_tracks method is the primary interface for updating the object tracker with new detections [4][5]. Key details regarding update_tracks: Usage and Parameters: The method signature is generally: update_tracks(raw_detections, embeds=None, frame=None, today=None, others=None, instance_masks=None) [5]. The raw_detections argument expects a list of detections, where each detection is typically provided as a tuple containing: ([left, top, w, h], confidence, detection_class) [4]. The frame argument (optional) is expected to be a numpy array of shape (Height, Width, Channels) with pixel values in the range [4]. It is used for feature extraction (embedding) if pre-computed embeddings are not provided [4]. Functionality: The method handles the tracking lifecycle by predicting the movement of existing tracks and then associating them with the provided detections [5]. If an embedder is configured (e.g., MobileNet, CLIP), the frame is cropped based on the bounding boxes and passed through the network to generate appearance embeddings [4]. Background masking is supported by providing an instance_masks argument [3][6]. The method returns a list of Track objects, which contain information about the tracked object, such as the track_id and the bounding box coordinates (e.g., via to_ltrb()) [4][5]. Common Issues: Users often encounter ValueError exceptions if the frame argument is passed incorrectly or if input shapes (e.g., bounding box formats) do not align with the tracker's expectations [5][7]. Ensuring the correct format ([left, top, w, h], confidence, detection_class) and passing the frame as a valid numpy array are crucial for correct operation [4][5]. Version 1.3.2 specifically included fixes for numpy deprecations (such as np.float) and exposed additional configuration parameters like max_iou_distance [3][8].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime
- 2: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 3: https://github.com/levan92/deep_sort_realtime/releases/tag/v1.3.2
- 4: Sample Code levan92/deep_sort_realtime#25
- 5: ValueError: shapes not aligned (when running deep sort with yolov8 object detector) levan92/deep_sort_realtime#50
- 6: https://libraries.io/pypi/deep-sort-realtime
- 7: https://stackoverflow.com/questions/78138866/valueerror-shapes-not-aligned-when-running-deep-sort-on-yolov8
- 8: np.float deprecated levan92/deep_sort_realtime#40
🌐 Web query:
raw.githubusercontent.com/levan92/deep-sort-realtime/1.3.2/deep_sort_realtime/deepsort_tracker.py
💡 Result:
The file deepsort_tracker.py is a core component of the deep-sort-realtime library, a Python package maintained by levan92 that provides a real-time adaptation of the Deep SORT multi-object tracking algorithm [1][2]. Key information regarding this file and library: Purpose: The deep-sort-realtime library is designed to facilitate real-time object tracking by integrating directly with object detection outputs [2][3]. It improves upon the original academic implementation of Deep SORT by optimizing it for real-time processing and providing flexible options for appearance feature extraction (embeddings) [2][3]. Role of deepsort_tracker.py: This file contains the DeepSort class, which is the primary interface for users [4][5]. When a user initializes the tracker or calls its update_tracks method, they are interacting with the logic defined in this file [5]. Key Features: - Multiple Embedder Options: The library supports various appearance embedders, including built-in MobileNet, CLIP, and TorchReID models [2][3][6]. - Flexible Input: It accepts raw detection data (typically [left, top, width, height] bounding boxes, confidence, and detection class) and a frame for processing [7][5]. - Hyperparameter Tuning: Users can adjust parameters such as max_age, max_iou_distance, and nms_max_overlap directly through the DeepSort constructor in deepsort_tracker.py to suit specific use cases [4][5]. - Real-time Optimization: The implementation includes optimizations like skipping non-maximum suppression (NMS) when unnecessary and allowing for pre-computed embeddings to reduce latency [2][3]. Installation and Usage: The library is available on PyPI and can be installed via pip [1][3]: pip install deep-sort-realtime Example usage typically involves initializing the tracker, obtaining detections from a model (e.g., YOLO), and updating the tracker with those detections [8][5]. For further technical details, including the specific implementations of Kalman filtering, linear assignment, and matching metrics used by the tracker, the library's source code documentation and the original Deep SORT paper (Wojke et al.) are recommended as primary references [2][3].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime
- 2: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 3: https://pypi.org/project/deep-sort-realtime/
- 4: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py
- 5: https://github.com/Cranfield-GDP3/deep_sort_realtime
- 6: https://learnopencv.com/real-time-deep-sort-with-torchvision-detectors/
- 7: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 8: Falling to implement deep -sort-realtime with YOLOv8 levan92/deep_sort_realtime#44
🌐 Web query:
raw.githubusercontent.com/levan92/deep-sort-realtime/master/deep_sort_realtime/deepsort_tracker.py update_tracks source
💡 Result:
The update_tracks method is the primary API call in the DeepSort class within the deep_sort_realtime library, located in deep_sort_realtime/deepsort_tracker.py [1][2]. It is used to process a single frame of data by updating tracker states with new object detections [2]. Key details regarding the update_tracks method: Functionality and Inputs: - The method processes a set of raw detections and, if a frame is provided, performs built-in appearance embedding (feature extraction) [2]. - Primary arguments include raw_detections, which is expected to be a list of tuples containing ([left, top, w, h], confidence, detection_class) [3][4]. - The method accepts a frame argument (the image) for automated embedding, or users can provide pre-computed embeds directly to bypass the built-in feature extractor [3][2][4]. - Additional arguments like others can be used to pass supplementary information (e.g., instance segmentation masks) that will be associated with the corresponding tracks [3][4]. Return Value: - It returns a list of active Track objects [2]. Each Track object provides access to tracking information such as the unique track_id, bounding box coordinates (via to_ltrb() or to_ltwh()), detection class (get_det_class()), and detection confidence (get_det_conf()) [2][4]. Common usage: - Standard implementation: tracks = tracker.update_tracks(bbs, frame=frame) [3][4]. - Using pre-computed embeddings: tracks = tracker.update_tracks(bbs, embeds=embeds) [3][4]. For further implementation details, you can consult the official repository documentation [5] or the source code in deepsort_tracker.py [1]. Users encountering issues with this method often reference its signature and argument requirements [6][7].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 4: https://pypi.org/project/deep-sort-realtime/
- 5: https://github.com/levan92/deep_sort_realtime
- 6: ValueError: shapes not aligned (when running deep sort with yolov8 object detector) levan92/deep_sort_realtime#50
- 7: Bug with the detection file levan92/deep_sort_realtime#38
🌐 Web query:
site:raw.githubusercontent.com/levan92/deep-sort-realtime master deep_sort_realtime deepsort_tracker.py "return self.tracks"
💡 Result:
I couldn’t find an indexed result for that exact raw GitHub path/snippet. The repo levan92/deep_sort_realtime does reference deep_sort_realtime/deepsort_tracker.py, and downstream code imports DeepSort from deep_sort_realtime.deepsort_tracker and calls update_tracks(...). (context7.com)
If you want, I can help you construct the exact raw file URL or locate the line in the repo.
Citations:
🌐 Web query:
site:raw.githubusercontent.com/levan92/deep-sort-realtime master deep_sort_realtime deepsort_tracker.py "def update_tracks" "return self.tracks"
💡 Result:
update_tracks is in deep_sort_realtime/deepsort_tracker.py in the levan92/deep_sort_realtime repo, and the docs describe it as the main API that returns the current list of active Track objects. (pypi.org)
If you want, I can also try to pull the exact raw GitHub line for return self.tracks.
Citations:
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== repository DeepSort construction =="
rg -n -C4 'DeepSort\(' .
echo "== exact tracker implementation from PyPI via wheel lookup =="
python3 - <<'PY'
import tarfile, textwrap, xml.etree.ElementTree as ET, urllib.request
metadata_url = "https://files.pythonhosted.org/packages/9b/25/aa3e3e1822c010a92c916f1a0e50057667c6b156296a235d65ec36069bb/deep-sort-realtime-1.3.2.tar.gz.metadata"
try:
req = urllib.request.Request(metadata_url)
req.add_header("User-Agent", "CodeRabbit-verification")
metadata = urllib.request.urlopen(req, timeout=20).read().decode("utf-8")
print(metadata)
except Exception as e:
print("metadata fetch failed", e)
pypi_repo = "https://pypi.org/pypi/deep-sort-realtime/json"
try:
data = ET.XML(urllib.request.urlopen(pypi_repo, timeout=20).read()).attrib
except Exception as e:
data = None
print("\n== release urls (sample) ==")
import xml.etree.ElementTree as ET
try:
root = ET.XML(urllib.request.urlopen(pypi_repo, timeout=20).read())
releases = root.find('releases')
if releases is not None:
for rel in releases.findall('release'):
if rel.attrib.get('name') == 'deep-sort-realtime' and rel.attrib.get('version') == '1.3.2':
for f in rel.findall('file'):
print(f.attrib.get('url'), f.attrib.get('packagetype'), f.attrib.get('filename'))
except Exception as e:
print("release list fetch failed", e)
print("\n== raw github file (no version pin) ==")
try:
data = urllib.request.urlopen(
urllib.request.Request(
"https://raw.githubusercontent.com/levan92/deep-sort-realtime/master/deep_sort_realtime/deepsort_tracker.py",
headers={"User-Agent": "CodeRabbit-verification"},
timeout=20,
),
timeout=20,
).read().decode("utf-8")
lines = data.splitlines()
for i,l in enumerate(lines):
if "def update_tracks" in l or "return self.tracks" in l:
print(f"## {i+1}: {l}")
start=max(0,i-20); end=min(len(lines),i+35)
for j in range(start,end):
print(f"{j+1}: {lines[j]}")
except Exception as e:
print("raw github fetch failed", e)
PYRepository: Devnil434/Eagle
Length of output: 1397
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
python3 - <<'PY'
import ssl, urllib.request
url = "https://raw.githubusercontent.com/levan92/deep-sort-realtime/master/deep_sort_realtime/deepsort_tracker.py"
with urllib.request.urlopen(url, context=ssl._create_unverified_context(), timeout=20) as resp:
src = resp.read().decode("utf-8")
lines = src.splitlines()
print("source length", len(lines))
for mark in ["def update_tracks", "def _update_tracker_with_embeddings", "return self.tracks"]:
print(f"\n--- matches for {mark} ---")
for i,l in enumerate(lines):
if mark in l:
print(f"{i+1}: {l}")
for j in range(max(0,i-25), min(len(lines), i+45)):
print(f"{j+1}: {lines[j]}")
PYRepository: Devnil434/Eagle
Length of output: 1105
🌐 Web query:
github raw levan92 deep-sort-realtime release 1.3.2 deep_sort_realtime deepsort_tracker.py
💡 Result:
The release version 1.3.2 of the levan92/deep_sort_realtime repository was published on February 11, 2023 [1][2]. This release introduced several updates to the library, including the addition of background masking functionality, fixes for NumPy deprecations regarding np.float, and the exposure of new arguments in the DeepSort object [1]. Specifically, in the deepsort_tracker.py file, the max_iou_distance argument was exposed to the DeepSort class, and a gating_only_position argument was added to the tracker to allow gating based solely on x and y coordinates rather than the default of x, y, aspect ratio, and height [1][3]. The library is available for installation via PyPI, and source/wheel files for version 1.3.2 can be found on the project's official GitHub releases page [1][2][4].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/releases/tag/v1.3.2
- 2: https://pypi.org/project/deep-sort-realtime/
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py
- 4: https://github.com/levan92/deep_sort_realtime
🌐 Web query:
github levan92 deep-sort-realtime blob v1.3.2 deep_sort_realtime deepsort_tracker.py update_tracks
💡 Result:
In the levan92/deep_sort_realtime library, particularly around version 1.3.2, the update_tracks method is the primary API call for multi-object tracking [1][2]. It is located within the DeepSort class in deep_sort_realtime/deepsort_tracker.py [3][1]. Usage and Functionality: The update_tracks method processes a new set of detections and the current video frame to update the state of all tracked objects [2]. Signature and Inputs: The standard usage pattern is: tracks = tracker.update_tracks(bbs, frame=frame) [1][2] bbs: A list of detections, where each detection is a tuple containing ([left, top, w, h], confidence, detection_class) [1][2]. frame (optional): A numpy array of shape (Height, Width, Channels) with pixel values in [4]. If provided, the library uses its internal embedder to calculate appearance features [4][2]. If you have pre-computed appearance features, you can pass them via an embeds argument instead, making the frame input unnecessary [5][2]. Advanced Options: Masks: You can pass instance segmentation masks using the masks argument (e.g., masks=[mask]) to be associated with detections [1][2]. Polygon Detection: When using polygon-based detections, the polygon argument should be set to True during DeepSort instantiation [1]. The original coordinates are then passed to the track via supplementary information [1]. Return Value: The method returns a list of active Track objects [2]. You can iterate through these to retrieve information such as track IDs and bounding boxes using methods like track.track_id and track.to_ltrb [1][6][7]. It is recommended to check track.is_confirmed to ensure only stable tracks are processed [4][2].
Citations:
- 1: https://github.com/levan92/deep_sort_realtime/blob/master/README.md
- 2: https://context7.com/levan92/deep_sort_realtime/llms.txt
- 3: https://github.com/levan92/deep_sort_realtime/blob/master/deep_sort_realtime/deepsort_tracker.py
- 4: Sample Code levan92/deep_sort_realtime#25
- 5: https://github.com/levan92/deep_sort_realtime
- 6: https://pypi.org/project/deep-sort-realtime/
- 7: https://github.com/Cranfield-GDP3/deep_sort_realtime
Use stale raw tracks for LOST ReID embedding capture.
current_ids is populated from every confirmed track, so the LOST branch never sees the frame where a confirmed track disappears. If stale tracks are absent from raw_tracks, track is None and the ReID embedding is lost. Keep stale confirmed tracks available for the LOST lookups, but exclude stale track IDs from current_ids.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@services/tracking/tracker.py` around lines 186 - 196, The LOST embedding
lookup in the lifecycle handling must retain stale confirmed tracks from the raw
tracking results while excluding their IDs from current_ids. Update the
current_ids construction and related track collection logic near the LOST branch
so stale confirmed tracks remain available to the track lookup without being
treated as active, preserving the existing embedding capture behavior in
_lost_embeddings.
Batch 1 fixes for Eagle
Summary by CodeRabbit