Comments (5)
Hi there,
It sounds like a challenging but interesting problem! Implementing re-identification (ReID) can indeed help maintain object tracking continuity even through occlusions or other visual interruptions.
For a simple ReID system without modifying the YOLOv8 source code, consider maintaining a history of object features (like bounding boxes, appearance features extracted from the detection region, etc.). Here’s a brief idea:
-
Extract Features: Every time an object is detected, extract features that could be used to re-identify it later. This could be simple bounding box coordinates and size, or more complex appearance features using a separate feature extraction model.
-
Comparison Function: Implement a function to compare the feature vector of a newly detected object with those of previously tracked objects. The function could be based on simple Euclidean distance for numerical features, or more complex similarity measures for comprehensive feature vectors.
-
Update Logic: When an object is occluded and reappears, use this function to find the most similar previously tracked object and assign its ID to the new detection.
Here's a rough code example to illustrate the concept:
def extract_features(detection):
# Placeholder for feature extraction logic
return detection['bbox'], detection['appearance']
def match_object(new_detection, tracked_objects):
new_features = extract_features(new_detection)
best_match = None
min_distance = float('inf')
for obj in tracked_objects:
dist = np.linalg.norm(new_features - tracked_objects[obj]['features'])
if dist < min_distance:
min_distance = dist
best_match = obj
return best_match
# Usage in tracking loop
new_detection = detect_objects(frame)
object_id = match_object(new_detection, tracked_objects)
if object_id:
update_tracker(object_id, new_detection)
else:
add_new_object(new_detection)
This approach manages IDs at the application level and doesn't require altering the underlying model or its training procedure. However, integrating more advanced machine learning models for feature comparison could offer better results but might involve more complexity and computational overhead.
Hope this helps get you started on your ReID system, and I'm eager to see how your project turns out!
from ultralytics.
Hi Glenn,
Sorry about the late response. I've been busy with other projects and school mostly. Thank you for the quick response. I am still confused about how I can update the tracker. I am using this to obtain results from the model:
result = model.track(frame, persist=True, tracker="custom.yaml")[0]
detections = sv.Detections.from_ultralytics(result)
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
This gives me tracker ids as an output. Is there any way to access and update yolov8 tracker? I am confused about "update_tracker" function you mentioned. Was it just some sort of pseudocode or was it me not being able to find it inside in YOLO. Big thanks.
from ultralytics.
@yusufkoca0 hi there,
No worries about the delay; I completely understand how busy things can get with school and other projects. 😊
Regarding your question, the update_tracker
function I mentioned was indeed pseudocode to illustrate the concept. YOLOv8's built-in tracking functionality doesn't directly support modifying tracker IDs post-detection.
However, you can implement a custom logic to handle re-identification by maintaining a mapping of tracker IDs and updating them as needed. Here's a more concrete example to help you get started:
# Initialize a dictionary to store the mapping of old IDs to new IDs
id_mapping = {}
# Function to update tracker IDs
def update_tracker_ids(result, id_mapping):
for i, old_id in enumerate(result.boxes.id.cpu().numpy().astype(int)):
if old_id in id_mapping:
result.boxes.id[i] = id_mapping[old_id]
else:
# If the ID is new, add it to the mapping
new_id = max(id_mapping.values(), default=0) + 1
id_mapping[old_id] = new_id
result.boxes.id[i] = new_id
# Example usage in your tracking loop
result = model.track(frame, persist=True, tracker="custom.yaml")[0]
update_tracker_ids(result, id_mapping)
detections = sv.Detections.from_ultralytics(result)
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
This way, you can maintain consistency in tracker IDs even when objects are re-identified after occlusions.
I hope this clarifies things! If you have any more questions or need further assistance, feel free to ask. Good luck with your project! 🚀
from ultralytics.
Hi Glenn, sometimes the most obvious answers can be hard to imagine because we're so focused on the hard task. Thanks for the tip, since I was so determined on trying to update the tracker I didn't think about a simple dictionary lol. I didn't exactly use your implementation but it was helpful! Thanks for the help.
from ultralytics.
Hi @yusufkoca0,
I'm glad to hear that the suggestion helped spark a solution for you! It's often those simpler approaches that slip our minds when we're deep into complex problems. If you have any more questions or need further assistance as you refine your implementation, feel free to reach out. Happy coding and best of luck with your project!
from ultralytics.
Related Issues (20)
- C2f module HOT 1
- How to freeze layers in yolov8? The freeze parameter means freeze first "freeze" layers, right?For example the backbone contains 11 layers,then i need to set freeze=11?but seems it also freezed my last segmentation head(layer 30),that's wield. HOT 2
- Changing the feature extractor HOT 6
- evaluation VS benchmark HOT 3
- default mean/std for yolov8-cls model HOT 2
- How to implement ordinal encoding of classes for yolov8-cls model? HOT 3
- It it possible to increase grid density in FastSAM? HOT 3
- Struggling to Improve mAP Scores on Custom Dataset (YOLOv8) HOT 2
- Trouble detecting multiple classes in same frame HOT 2
- Overfitting HOT 1
- Having question for the label showed by "Plotting label" in the beginning of training. HOT 6
- Adding epochs after training is done HOT 5
- How many classes are used to train "yolov8n-oiv7.pt" model HOT 2
- Thanks for your work,excellent! some question about yolo-world finetune freeze and prompt. HOT 3
- YoloV8 with TensorRT Jetpack 6: dependencies? HOT 4
- Questions about domain adaptation for YOLOv8 HOT 3
- (YOLOv8的anchor机制,可以根据训练样本自动调整anchor吗?anchor是聚类生成,不是设定的吧?)Can the yolov8 training process automatically adjust the anchor size according to the anchor of the training set? Since my detection targets are all small targets, it should be better to adjust anchor HOT 4
- ultralytics 8.2.26 export to openvino int8 quantization, performance drop significantly HOT 12
- Why pad 0.5 here? HOT 2
- GPU_mem not correlated with task manager GPU memory usage HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralytics.