Skip to content
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

significant increase in speed for radar mode #22

Open
fenaux opened this issue Sep 18, 2024 · 0 comments
Open

significant increase in speed for radar mode #22

fenaux opened this issue Sep 18, 2024 · 0 comments

Comments

@fenaux
Copy link

fenaux commented Sep 18, 2024

Many thanks for providing this repo.

As getting players team id is quiet long, the idea is to call this process only when a knew player is detected assuming he will not change of team during the play ;).

Then in main.py of example/soccer
in run_radar after players identification from line 342 I suggest

tracker = sv.ByteTrack(minimum_consecutive_frames=3)
sorted_players_tracks = np.array([])
sorted_players_teams_id = np.array([])
for frame in frame_generator:
    result = pitch_detection_model(frame, verbose=False)[0]
    keypoints = sv.KeyPoints.from_ultralytics(result)
    result = player_detection_model(frame, imgsz=1280, verbose=False)[0]
    detections = sv.Detections.from_ultralytics(result)
    detections = tracker.update_with_detections(detections)

    players = detections[detections.class_id == PLAYER_CLASS_ID]
    
    sorted_by_tracks = np.argsort(players.tracker_id)
    if np.array_equal(sorted_players_tracks, np.sort(players.tracker_id)):
        players_team_id = sorted_players_teams_id.copy()
        players_team_id[sorted_by_tracks] = sorted_players_teams_id.copy()
        
    else:
        crops = get_crops(frame, players)
        players_team_id = team_classifier.predict(crops)
        sorted_players_tracks = np.sort(players.tracker_id)
        sorted_players_teams_id = players_team_id[sorted_by_tracks]

for instance in 2e57b9_0.mp4', on a total of 750 frames, 663 of them show unchanged tracks compared to previous frame i.e avoiding the call to team_classifier (note this should be larger as during the last frames one of the player is lost and seen again when he runs near the lateral lane and is likely considered as a referee.

One my laptop processing time for this video decreased from 817s to 191s :)

As I am not a top coder I guess there are smarter way to code this idea :)

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

No branches or pull requests

1 participant