dattalab / moseq2-viz

Visualization toolbox for MoSeq2
Other
1 stars 2 forks source link

v0.1.2 - list object has no attribute values #40

Closed wingillis closed 6 years ago

wingillis commented 6 years ago

When I try to run get_behavioral_distance I run into this error

AttributeError                            Traceback (most recent call last)
<ipython-input-19-b058407a17a4> in <module>
----> 1 dists = get_behavioral_distance(index, mdl_path, distances=['pca[dtw]'], dist_options=dict(pca={'normalize': 'mean'}))

~/code/moseq2/moseq2-viz/moseq2_viz/model/dist.py in get_behavioral_distance(index, model_file, whiten, distances, max_syllable, resample_idx, dist_options, sort_labels_by_usage, count)
    101             pc_slices = []
    102             for syllable in tqdm.tqdm(range(max_syllable)):
--> 103                 pc_slice = retrieve_pcs_from_slices(slice_fun(syllable),
    104                                                     pca_scores,
    105                                                     **use_options)

~/code/moseq2/moseq2-viz/moseq2_viz/model/util.py in get_syllable_slices(syllable, labels, label_uuids, index, trim_nans)
    120 def get_syllable_slices(syllable, labels, label_uuids, index, trim_nans=True):
    121 
--> 122     h5s = [v['path'][0] for v in index['files'].values()]
    123     h5_uuids = list(index['files'].keys())
    124 

AttributeError: 'list' object has no attribute 'values'
wingillis commented 6 years ago

The only thing I do custom is load in the index file in my own notebook, then I run the function as is

jmarkow commented 6 years ago

can you post the index loading code? You need to use the second output returned from the function.

jmarkow commented 6 years ago

(I didn't make this clear at all)

jmarkow commented 6 years ago

Example from the wiki,

https://github.com/dattalab/moseq2-docs/blob/master/notebooks/loading_scalars_and_model_results_for_viz.ipynb

wingillis commented 6 years ago
with open(index_path, 'r') as f:
  index = yaml.load(f, Loader=yaml.Loader)
jmarkow commented 6 years ago

Try the parse_index function per the notebook linked above.

wingillis commented 6 years ago

OK - I didn't know that existed, my bad

jmarkow commented 6 years ago

Not your fault. Wasn't super clear. I'll try to add some safeguards so others don't get tripped up as well (maybe a warning if we detect that someone loaded the yaml directly).

wingillis commented 6 years ago

thanks - unfortunately now I'm getting a new error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-27-f3aef73b56c2> in <module>
----> 1 dists = get_behavioral_distance(sorted_index, mdl_path, distances=['pca[dtw]'], dist_options=dict(pca={'normalize': 'mean'}))

~/code/moseq2/moseq2-viz/moseq2_viz/model/dist.py in get_behavioral_distance(index, model_file, whiten, distances, max_syllable, resample_idx, dist_options, sort_labels_by_usage, count)
    101             pc_slices = []
    102             for syllable in tqdm.tqdm(range(max_syllable)):
--> 103                 pc_slice = retrieve_pcs_from_slices(slice_fun(syllable),
    104                                                     pca_scores,
    105                                                     **use_options)

~/code/moseq2/moseq2-viz/moseq2_viz/model/util.py in get_syllable_slices(syllable, labels, label_uuids, index, trim_nans)
    129             score_idx = h5_to_dict(f, 'scores_idx')
    130 
--> 131     sorted_h5s = [h5s[h5_uuids.index(uuid)] for uuid in label_uuids]
    132     syllable_slices = []
    133 

~/code/moseq2/moseq2-viz/moseq2_viz/model/util.py in <listcomp>(.0)
    129             score_idx = h5_to_dict(f, 'scores_idx')
    130 
--> 131     sorted_h5s = [h5s[h5_uuids.index(uuid)] for uuid in label_uuids]
    132     syllable_slices = []
    133 

ValueError: '822c577d-974d-4176-90eb-618328867e15' is not in list

I just checked that my model and the pca score file share the same keys exactly, so this must be a bug, or some issue in how moseq2-viz is finding where the scores file lives

jmarkow commented 6 years ago

ah okay. This one's an easier fix hopefully. Use the following now (I'll add code to automatically do this soon).

Try this

tmp = parse_model_results(model_file)
sorted_index['files'] = {k:v for k,v in sorted_index['files'].items() if k in tmp['train_list']}
wingillis commented 6 years ago

It turns out that this key doesn't exist in my moseq2-index file

jmarkow commented 6 years ago

Try the latest commit.

wingillis commented 6 years ago

hm something's not quite right, I received like a billion of this: /home/wg41/code/moseq2/moseq2-viz/moseq2_viz/model/util.py:144: UserWarning: Index length 80963 and label array length 55146 in /n/groups/datta/win/1pimaging_dls_moseq2/_vae_data/2017-12-03_t11:33:03_a2a-cre-cre-dep_c15_results_00.h5

wingillis commented 6 years ago

hmm this might also be related to another issue - I need to select the last iteration of the resampled data. This might be the cause of the issue. One thing that leads me to that conclusion is that each warning that is generated has the same label array length, but different index lengths

jmarkow commented 6 years ago

Considering this resolved.