dattalab / keypoint-moseq

https://keypoint-moseq.readthedocs.io
Other
63 stars 25 forks source link

`update_config` not working from a DLC config file #133

Closed rjd55 closed 4 months ago

rjd55 commented 4 months ago

Hi, I think setting up a project from a DLC config file is not working correctly. Here is my code:


data_dir = '/home/Data'
config = lambda: kpms.load_config(project_dir)

print("Setting up project...")

#setup from DeepLabCut
dlc_config = os.path.join(data_dir, 'config.yaml')
kpms.setup_project(project_dir, deeplabcut_config=dlc_config)

print("Updating config file...")

#edit the config file
kpms.update_config(
    project_dir,
    video_dir=os.path.join(data_dir, 'videos'),
    anterior_bodyparts=['center_nose'],
    posterior_bodyparts=['center_back_low'],
    use_bodyparts=['all_center_of_mass', 'center_abdomen_mid', 'center_back', 'center_back_low', 'center_neck', 'center_nose', 'left_ankle', 'left_arm', 'left_ear_top', 'left_eye', 'left_front_paw', 'left_hind_paw', 'right_ankle', 'right_arm', 'right_ear_top', 'right_eye', 'right_front_paw', 'right_hind_paw']
)

print("Loading keypoint data...")

# load data (e.g. from DeepLabCut)
keypoint_data_path = os.path.join(data_dir, 'videos') # can be a file, a directory, or a list of files
coordinates, confidences, bodyparts = kpms.load_keypoints(keypoint_data_path, 'deeplabcut')

print("Formatting data...")

# format data for modeling
data, metadata = kpms.format_data(coordinates, confidences, **config())

print("Fitting PCA...")

#Fit PCA
pca = kpms.fit_pca(**data, **config())
kpms.save_pca(pca, project_dir)
`

Here is my DLC config file:

``` # Project definitions (do not edit)
Task: WrapUp_BatchSize2_GlobalScale0.8
scorer: fred
date: Feb2
multianimalproject: false
identity:

    # Project path (change when moving around)
project_path: /data/users/fred/code/DeepLabCut_projects/WrapUp_BatchSize2_GlobalScale0.8-monsees-2024-02-02

    # Annotation data set configuration (and individual video cropping parameters)
video_sets:
  /data/users/fred/data/final/2024-01-14_17-55-03__6195_145.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2024-01-13_17-55-02__6195_145.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2024-01-12_17-55-02__6195_145.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2024-01-11_17-55-02__6195_145.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2023-11-25_17-45-02__animal2.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2023-11-24_17-45-02__animal2.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2023-11-18_19-00-02__animal1.mp4:
    crop: 0, 1920, 0, 768
  /data/users/fred/data/final/2023-11-17_19-00-02__animal1.mp4:
    crop: 0, 1920, 0, 768
bodyparts:
- all_center_of_mass
- center_abdomen_mid
- center_back
- center_back_low
- center_neck
- center_nose
- center_tail_base
- center_tail_mid
- center_tail_tip
- left_ankle
- left_arm
- left_ear_top
- left_eye
- left_front_paw
- left_hind_paw
- right_ankle
- right_arm
- right_ear_top
- right_eye
- right_front_paw
- right_hind_paw
start: 0.0
stop: 1.0
numframes2pick: 100

    # Plotting configuration
skeleton:
- - bodypart1
  - bodypart2
- - objectA
  - bodypart3
skeleton_color: black
pcutoff: 0.6
dotsize: 12
alphavalue: 0.7
colormap: rainbow ....`

Here is the output:

```WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
Importing libraries...
Setting up project...
Updating config file...
Loading keypoint data...
Loading keypoints: 100%|██████████████████| 1/1 [00:02<00:00,  2.35s/it]
Formatting data...
ACTION REQUIRED: `skeleton` contains bodypart1 which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains bodypart2 which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains objectA which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains bodypart3 which is not one of the
  options in `bodyparts`.

Fitting PCA...
ACTION REQUIRED: `skeleton` contains bodypart1 which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains bodypart2 which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains objectA which is not one of the
  options in `bodyparts`.

ACTION REQUIRED: `skeleton` contains bodypart3 which is not one of the
  options in `bodyparts`.

>=90.0% of variance exlained by 2 components.`

Should `update_config` include all the bodyparts from the dlc bodyparts and skeleton?

Thank you
calebweinreb commented 4 months ago

The problem is that your DLC config contains a skeleton but the bodypart names in the that skeleton are different from the list of bodyparts earlier in the config.