dattalab / keypoint-moseq

https://keypoint-moseq.readthedocs.io
Other
71 stars 28 forks source link

Data loader #105

Closed Aexolowski closed 11 months ago

Aexolowski commented 11 months ago

Hi there! We are tracking with DLC, but are correcting the data post-hoc. The final format is an excel sheet with frames X labels (x coordinate, y coordinate). What is the best way to load these data for keypoint-moseq? Thanks!

calebweinreb commented 11 months ago

You could try saving them as cvs files and then loading them with numpy?

import numpy as np
import tqdm
import os

csv_paths = [XXX]

coordinates = {}
for filepath in tqdm.tqdm(csv_paths):

    # load data
    data = np.loadtxt(filepath, delimiter=',', skiprows=1)

    # reshape
    num_timepoints = data.shape[0]
    data = data.reshape(num_timepoints, -1, 2)

    # add to dict
    name = os.path.splitext(os.path.basename(filepath))[0]
    coordinates[name] = data
Aexolowski commented 11 months ago

Hi Caleb, thanks a lot, we will try that! Another question is how / if we can also use the confidence estimates from the DLC model?

calebweinreb commented 11 months ago

Sure, you can just load them normal (without defining the coordinates)

_, confidences, bodyparts = kpms.load_keypoints(keypoint_data_path, 'deeplabcut')

The one thing to make sure of is that confidences and coordinates end up with the same keys. If they don't, then you'll either have to edit the filenames or modify the code I posted earlier to adjust the names as necessary.