Post DLC Processing

As in other posts, I have been trying to use code to analyze post-DLC information, such as time spent in a certain ROI. I am using the code based from here: DLCutils/Demo_loadandanalyzeDLCdata.ipynb at e8948d385a38219ca38d3009dd9406434cedba24 · DeepLabCut/DLCutils · GitHub.

I did my best to match up my video and h5 file with the syntax. Everything seems to work fine, up until I enter Dataframe.head(). What do you think went wrong? According to the code in the URL, I’m supposed to get an output of X and Y coordinates; I’m not getting them. Attached is the screenshot file.


To give more context, I’m using a CPU system.

@RyanAvenido, I thought I had solved your issue by email.
The path given to pd.read_hdf is incorrect and an error message should have rightly indicated it.
This is what the demo code looks like:

Since you have already defined dataname, reuse it, this will avoid syntax errors. The safest option though is to directly copy the path to your file, and paste it in pd.read_hdf(path_to_file).

@jeylau; I’m sorry if my questions have sounded repetitive. I think I was still confused. So do I substitute my defined dataname for “path_to_file”? Or do I still need to include os.path.join(______)? Because I received syntax errors after pasting my dataname after os.path.join(pasted dataname here). Thanks.

Yes, just substitute your dataname for path_to_file and get rid of the os.path.join (which I’ll also remove from the demo notebook because it is useless, since a single path is given) :slight_smile:

Thanks for leading me to another possible code. I tried your advice for Dataframe = pd.read_hdf(dataname). However, after I hit Enter, I have a FileNotFound Error. This means that my file doesn’t exist. How can I ensure that I do have a file that definitely exists? image

The path you gave is not absolute; that is, it doesn’t tell python what drive and folder to look into (hence why your file is not found). Have a look here.

Hey @jeylau. I followed your advice about including the drive and folder. I tried to be more clear, but it still says that “file does not exist.” What should I do next?

For the “FileNotFoundError,” why do I keep getting FileNotFoundError: File fiveminutesC:/Users/aven1791/.ipython/fiveminutes-aven1791-2020-12-08/videos/fiveminutesDLC_resnet50_fiveminutesDec8shuffle1_27500.h5 does not exist?

The fiveminutes in front shouldn’t be there. How did the fiveminutes end up as a file? I think this is my main barrier.

@jeylau Another possible issue could be the dataname format? I tried being very specific with including the title of the video and DLCscorer and it still results in FileNotFoundError.

@RyanAvenido, I have given by emails and in multiple places on this forum several tips on how to get a file location right, the simplest one being (on Windows) Shift+right click on the file->Copy As Path or (on Mac) Option+right click. I do not understand why you keep trying to type it manually, which evidently is too error-prone, for beginner or advanced programmers alike…

Hello @jeylau,
Because I use Windows, I did the Shift+right click on file then Copy As Path. I then pasted the file into the Console. However, I receive a unicode error. What does this mean?

Either use raw strings (it suffices to add a ‘r’ in front of your string, as in: r"C:\Users\..." or double backslashes everywhere in the path (like "C:\\Users\\..."). You should be all set :slight_smile:

Thanks. I tried both options, but I still get the FileNotFoundError. Here is a sample image of r"C:\Users…"


Here is the version where I applied “C:\Users\…”
I still get the same issue.

What should I do differently with the way I type the code? As I mentioned earlier, how did the phrase “fiveminutes” end up at the start of the file that supposedly doesn’t exist?

File fiveminutesC:\Users\aven1791.ipython\fiveminutes-aven1791-2020-12-08\videos\fiveminutesDLC_resnet50_fiveminutesDec8shuffle1_27500.h5 does not exist

To clarify: How did my code formulate fiveminutesC:\Users\aven1791.ipython\fiveminutes-aven1791-2020-12-08\videos\fiveminutesDLC_resnet50_fiveminutesDec8shuffle1_27500.h5? Again, this is the output that doesn’t exist. Whoever can help me with this issue will be greatly appreciated. Thanks!

It looks like you are trying to programmatically generate a path to your file, when you simply don’t have to. You probably got the path code from the colab notebook, but that is set up to take various files based on other variables. To do this in a single instance of ipython, for a single file, you don’t need to do any of that.

The fiveminutes being added to the front is the .stem of the path you are passing, then you add on a full string, then “.h5”. It’s much easier (and accurate) to to just give it the path to the file, especially if you are not familiar with the pathlib module.

  1. In windows explorer, copy the file path to the h5 file you want to load (not the video).
  2. In your ipython, once you’ve imported pandas and other modules, type

DataFrame = pd.read_hdf(r

  1. then ctrl-v to paste the path (windows will include double quotes)
  2. Then close the parentheses.
  3. You should end up with something like

DataFrame = pd.read_hdf(r"C:\Users\some\more\path\filename.h5")

  1. Hit enter.

@backyardbiomech ; Thanks for your input. Question, why won’t I need the video for DataFrame? In the post-DLC processing for time spent in a ROI, there are directions indicating that DataFrame= pd.read_hdf(dataname). However, I’ve tried using the latter multiple times; I’ll give the code you gave to me a try!

The h5 file is basically a spreadsheet of the xy coordinates of the various body parts in it. You just need to know the coordinates of your ROI, and then you can figure out what you need to know from that.