AtomScott / SportsLabKit

A python package for turning sports video into csv files
https://sportslabkit.rtfd.io
GNU General Public License v3.0
216 stars 19 forks source link

AttributeError: 'ExponentialMovingAverage' object has no attribute 'gamma' #137

Open Minokiti11 opened 5 months ago

Minokiti11 commented 5 months ago

Search before asking

SportsLabKit Component

No response

Bug

I got this error when trying to run 06_tracking_the_players.ipynb:

スクリーンショット 2024-01-17 14 01 28

Maybe this error is concerned version of torch or other libraries but I couldn't fix this error.

Environment

Minimal Reproducible Example

from sportslabkit.mot import TeamTracker
import numpy as np 

slk.logger.set_log_level('INFO')
det_model = slk.detection_model.load(
    model_name='yolov8',
    model=root/'models/yolov8/model=yolov8x-imgsz=512.pt',
    conf=0.25,
    iou=0.6,
    imgsz=640,
    device='mps',
    classes=0,
    augment=True,
    max_det=35
)

image_model = slk.image_model.load(
    model_name='mobilenetv2_x1_0',
    image_size=(32,32),
    device='cpu'
)

motion_model = slk.motion_model.load(
    model_name='ExponentialMovingAverage',
)
# motion_model = slk.motion_model.load(
#     model_name='SingleTargetLSTM',
#     model='/Users/atom/Github/SoccerTrack/models/teamtrack/LSTM-F_Soccer_Tsukuba3-epoch=79-val_nll_loss=-2.74.ckpt',
# )

keypoint_json = root / 'notebooks/02_user_guide/assets/soccer_keypoints.json'
cam.source_keypoints, cam.target_keypoints = slk.utils.load_keypoints(keypoint_json)

# calibration model return a 3x3 homography matrix for each frame
calibration_model = slk.calibration_model.load(
    model_name='DummyCalibrationModel',
    homographies=cam.H,
    mode='constant'
)

first_matching_fn = slk.matching.MotionVisualMatchingFunction(
    motion_metric=slk.metrics.EuclideanCMM2D(use_pred_pt=True),
    motion_metric_gate=0.2,
    visual_metric=slk.metrics.CosineCMM(),
    visual_metric_gate=0.2,
    beta=0.9,
)

second_matching_fn = slk.matching.SimpleMatchingFunction(
    metric=slk.metrics.EuclideanCMM2D(use_pred_pt=True),
    gate=0.9,
)

# team_detection_callback = slk.callbacks.TeamDetectionCallback(classication_model=TeamClassifier())

class PrintingCallback(): # removed 'slk.callbacks.Callback' because there is no 'Callback' class in mot/callbacks
    def on_track_sequence_start(self, tracker):
        tracklets = tracker.alive_tracklets + tracker.dead_tracklets
        print(f"Tracking started with {len(tracklets)} tracklets")

    def on_track_sequence_end(self, tracker):
        tracklets = tracker.alive_tracklets + tracker.dead_tracklets
        print(f"Tracking ended with {len(tracklets)} tracklets")

callbacks = [PrintingCallback()]

tracker = TeamTracker(
    detection_model=det_model,
    image_model=image_model,
    motion_model=motion_model,
    calibration_model=calibration_model,
    first_matching_fn=first_matching_fn,
    second_matching_fn=second_matching_fn,
    detection_score_threshold=0.6,
    max_staleness=2,
    min_length=2,
    callbacks=callbacks,
)

tracker.track(frames)[0]

Additional

'SingleTargetLinear' is not available, so I used EMA instead of it.

Are you willing to submit a PR?

AtomScott commented 5 months ago

Thanks for the PR! I will check it this weekend, sorry for the late response!

hangingter commented 3 months ago

image add one line in init fix this. self.gamma = gamma

Minokiti11 commented 3 months ago

@hangingter Thanks a lot! I'll try it!