dattalab / keypoint-moseq

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

Syllable labeler errors depending on number/existence of grid/crowd movies #53

Closed calebweinreb closed 1 year ago

calebweinreb commented 1 year ago

Currently the syllable labeler code seems to assume that (a) grid and crowd movies both exist; (b) the number of each is the same. I think ideally it should tolerate when both assumptions are violated. In other words, I think it should gracefully handle when there are no crowd movies, no grid movies, or none of either. If the user requested to use grid/crowd movies and none are present, it would be nice to issue a warning and explain how to generate them. Also the number of grid/crowd movies may differ since they use slightly different criteria to decide which syllables to include.

Here are the various errors I got when the assumptions were broken:

Yes grid movies but no/fewer crowd movies

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[20], line 2
      1 movie_type = 'grid' # either 'grid' or 'crowd'
----> 2 progress_paths = kpms.label_syllables(progress_paths, movie_type = movie_type)

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/wrappers.py:106, in label_syllables(progress_paths, movie_type)
    102     with open(progress_paths['progress_filepath'], 'w') as f:
    103         yaml.safe_dump(progress_paths, f, default_flow_style=False)
--> 106 labeler = SyllableLabeler(progress_paths['base_dir'], progress_paths['model_name'],
    107                           progress_paths['index_file'], movie_type, progress_paths['syll_info_path'])
    108 output = widgets.interactive_output(labeler.interactive_syllable_labeler, {'syllables': labeler.syll_select})
    109 display(labeler.clear_button, labeler.syll_select, output)

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/widgets.py:531, in SyllableLabeler.__init__(self, base_dir, model_name, index_file, movie_type, syll_info_path)
    529     self.syll_info = read_yaml(syll_info_path)
    530 else:
--> 531     self.syll_info = self._initialize_syll_info_dict(self.model_name)
    532     # Write to file
    533     with open(self.syll_info_path, 'w') as f:

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/widgets.py:570, in SyllableLabeler._initialize_syll_info_dict(self, movie_dir)
    566 grid_movie_files = sorted(glob(os.path.join(self.base_dir, self.model_name, 'grid_movies',
    567                           '*.mp4')), key=lambda x: int(os.path.basename(x).split('.')[0][8:]))
    568 crowd_movie_files = sorted(glob(os.path.join(self.base_dir, self.model_name,
    569                            'crowd_movies', '*.mp4')), key=lambda x: int(os.path.basename(x).split('.')[0][8:]))
--> 570 return {i: {'label': '', 'desc': '', 'movie_path': [grid_movie_files[i], crowd_movie_files[i]], 'group_info': {}} for i in range(len(grid_movie_files))}

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/widgets.py:570, in <dictcomp>(.0)
    566 grid_movie_files = sorted(glob(os.path.join(self.base_dir, self.model_name, 'grid_movies',
    567                           '*.mp4')), key=lambda x: int(os.path.basename(x).split('.')[0][8:]))
    568 crowd_movie_files = sorted(glob(os.path.join(self.base_dir, self.model_name,
    569                            'crowd_movies', '*.mp4')), key=lambda x: int(os.path.basename(x).split('.')[0][8:]))
--> 570 return {i: {'label': '', 'desc': '', 'movie_path': [grid_movie_files[i], crowd_movie_files[i]], 'group_info': {}} for i in range(len(grid_movie_files))}

IndexError: list index out of range

No grid movies

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[32], line 2
      1 movie_type = 'grid' # either 'grid' or 'crowd'
----> 2 progress_paths = kpms.label_syllables(progress_paths, movie_type = movie_type)

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/wrappers.py:106, in label_syllables(progress_paths, movie_type)
    102     with open(progress_paths['progress_filepath'], 'w') as f:
    103         yaml.safe_dump(progress_paths, f, default_flow_style=False)
--> 106 labeler = SyllableLabeler(progress_paths['base_dir'], progress_paths['model_name'],
    107                           progress_paths['index_file'], movie_type, progress_paths['syll_info_path'])
    108 output = widgets.interactive_output(labeler.interactive_syllable_labeler, {'syllables': labeler.syll_select})
    109 display(labeler.clear_button, labeler.syll_select, output)

File ~/Dropbox (HMS)/caleb weinreb/PROJECTS/MOUSE_SURVEILANCE/22_3_1_keypoint_MOSEQ/official_pipelines/keypoint-moseq/keypoint_moseq/widgets.py:525, in SyllableLabeler.__init__(self, base_dir, model_name, index_file, movie_type, syll_info_path)
    523 self.movie_type = movie_type
    524 self.syll_info_path = syll_info_path
--> 525 self.video_dims = video_dims
    527 # check if syllable info file exists
    528 if os.path.exists(syll_info_path):

UnboundLocalError: local variable 'video_dims' referenced before assignment
versey-sherry commented 1 year ago

handled as discussed: d5a49323947e5a044827208c64f649889134e4e3