Colab: deeplabcut.create_training_dataset


I got the following error when I run the code deeplabcut.create_training_dataset on the example data.
“local variable ‘cfg’ referenced before assignment”

Colab was used.

Any solutions?



1 Like


probably you should define cfg (which is the name of the config file I suppose?). Perhaps you need to post more details.


Hi Alexander,

Here are the errors I got:

BTW: import deeplabcut, I got

I have the same problem, some times. Using Colab in Windows 10 and Chrome. Deeplabcut works localy. Labeled data set created and moved to google drive.

I think the key is this part:

(“Config file is not found. Please make sure that the file exists and/or there are no unnecessary spaces in the path of the config file!”)

Which suggest the path to the config file is wrong. But is not that simple as I get this error with one folder but not the other. I have two folders in my DeeplabCut folder in My Drive. pigeon2 path is this

In Colab:
path_config_file = ‘/content/drive/My Drive/DeepLabCut/pigeon2-cristian-2019-03-09/config.yaml’

In the config file:
project_path: /content/drive/My Drive/DeepLabCut/pigeon2-cristian-2019-03-09

This doesn’t get me the “cfg error”. I get the question about converting from windows to linux (and then another error when I press yes, but lets focus on this).

but for my other folder (humm3) I have this:

In Colab:
path_config_file = ‘/content/drive/My Drive/DeepLabCut/humm3-cristian-2019-03-10/config.yaml’

in the config file:
project_path: /content/drive/My Drive/DeepLabCut/humm3-cristian-2019-03-10

and get the cfg error.

Not sure what the difference is.

Thank you for any help.

path_config_file = ‘/content/drive/My Drive/DeepLabCut/Reaching-Mackenzie-2018-08-30/config.yaml’
project_path: /content/drive/My Drive/DeepLabCut/Reaching-Mackenzie-2018-08-30

Didn’t know how to improve them at all.


When you copy the project to colab, you need to a) change the project_path in the config file to reflect the location b) define the path_config_file accordingly when calling dlc. Did you check if those are correct for your project? (i.e. folder /content/drive/My Drive/DeepLabCut/humm3-cristian-2019-03-10 exists, project_path is updated and config file defined in the same way)?

Hi LingLing and Cristian,

I had the same error message. My PhD student James Howard discovered the cause and the fix.

(1) In, any error in the line cfg = ruamelFile.load(f) is treated as though the file f is not found. This happens even if the error is a malformed YAML file, as I had. Therefore your paths etc may all be correct, and the YAML file is indeed being found.

(2) Unfortunately the way the code is structured does not allow the error message to appear as a file-not-found error, but instead as local variable 'cfg' referenced before assignment.

Therefore the thing to check is the YAML file to make sure your text editor (or you) have not mangled something.
In my case at the bottom of the YAML file, my text editor had mutilated the bottom of the file. Once corrected, it worked.

1 Like

Thank you Darrel!!! Good find. I think something was indeed wrong with the config file. I used the one from the other folder (after changing both path) and it works.

Many thanks, Darrel!!! The problem was indeed in the config file. After I changed the actual video name back to " “WILL BE AUTOMATICALLY UPDATED BY DEMO CODE”, it worked.


yes, having a broken or faulty config file will not be read correctly… it’s not a bug, it’s just the error that comes up telling you the file cannot be read; i.e. the path was wrong to the file, or the yaml is corrupted somehow. If you want to use the demo data on colab, see this:

Add the error solve method in my medium story