sports
sports copied to clipboard
significant increase in speed for radar mode
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 :)