dattalab / keypoint-moseq

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

NameError: name 'model_name' is not defined #97

Closed ryanschwark closed 1 year ago

ryanschwark commented 1 year ago

Hi all,

After successfully training the AR-HMM and fitting the full model in the Jupyter notebook, I'm attempting the Apply to New Data step. After the model successfully trained, I successfully completed the 'Extract model results' and 'save results in csv format' steps. Then when applying to new data, I used the following cell:

load the most recent model checkpoint and pca object model = kpms.load_checkpoint(project_dir, model_name)[0] pca = kpms.load_pca(project_dir)

load new data (e.g. from deeplabcut) new_data = 'D:/Naked mole-rat open field videos/7-11-23 videos' # can be a file, a directory, or a list of files coordinates, confidences, bodyparts = kpms.load_keypoints(new_data, 'sleap') data, metadata = kpms.format_data(coordinates, confidences, **config())

apply saved model to new data results = kpms.apply_model(model, pca, data, metadata, project_dir, model_name, **config())

optionally rerun save_results_as_csv to export the new results kpms.save_results_as_csv(results, project_dir, model_name)

However, I received this error message:


NameError Traceback (most recent call last) Cell In[19], line 2 1 # load the most recent model checkpoint and pca object ----> 2 model = kpms.load_checkpoint(project_dir, model_name)[0] 3 pca = kpms.load_pca(project_dir) 5 # load new data (e.g. from deeplabcut)

NameError: name 'model_name' is not defined

I think the problem might stem from the fact that I saved the Jupyter notebook, closed it, then relaunched it. Could this be the source of the issue? After I re-opened the Jupyter notebook, I made sure to import all of the data again, and only skipped the model training steps. When I try the 'Extract model results' and 'save results in csv format' steps, I also receive the same error. If this is the case, what steps do I have to take when relaunching a Jupyter notebook in order to successfully reload the last trained model checkpoint without encountering this error? Thanks!

calebweinreb commented 1 year ago

Just look back through the notebook to find the model name (it will be something like "2023_08_01-10_16_25") and then use it to define the model_name variable, e.g.

model_name = "2023_08_01-10_16_25"
ryanschwark commented 1 year ago

Thanks! This seemed to fix the issue!