Giter VIP home page Giter VIP logo

Comments (5)

glenn-jocher avatar glenn-jocher commented on June 26, 2024

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:

  1. 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.

  2. 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.

  3. 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.

yusufkoca0 avatar yusufkoca0 commented on June 26, 2024

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.

glenn-jocher avatar glenn-jocher commented on June 26, 2024

@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.

yusufkoca0 avatar yusufkoca0 commented on June 26, 2024

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.

glenn-jocher avatar glenn-jocher commented on June 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.