Creating csv files without re-analyzing

So I have been analyzing several videos and just realized that at some point I removed the ‘save_as_csv=True’ flag from my data. Is there a quick way to reproduce those csv files without having to reanalyze all of the data? I have the plot trajectories and the labeled videos, but I need the csv files as well.


no problem! We anticipated this :slight_smile: there is a function called deeplabcut.analyze_videos_converth5_to_csv

deeplabcut.analyze_videos_converth5_to_csv(videopath, videotype='.avi')
    By default the output poses (when running analyze_videos) are stored as MultiIndex Pandas Array, which contains the name of the network, body part name, (x, y) label position 

    in pixels, and the likelihood for each frame per body part. These arrays are stored in an efficient Hierarchical Data Format (HDF) 

    in the same directory, where the video is stored. If the flag save_as_csv is set to True, the data is also exported as comma-separated value file. However,
    if the flag was *not* set, then this function allows the conversion of all h5 files to csv files (without having to analyze the videos again)!
    This functions converts hdf (h5) files to the comma-separated values format (.csv), which in turn can be imported in many programs, such as MATLAB, R, Prism, etc.
    videopath : string
        A strings containing the full paths to videos for analysis or a path to the directory where all the videos with same extension are stored.

    videotype: string, optional
        Checks for the extension of the video in case the input to the video is a directory.
Only videos with this extension are analyzed. The default is ``.avi``


    Converts all pose-output files belonging to mp4 videos in the folder '/media/alex/experimentaldata/cheetahvideos' to csv files. 
1 Like

Hello everyone,

I’m not sure if this might happened before, but I had the same issues as Kyle to create the csv files. However, the convert function did not work for me at first. I did notice that it would work on resnet networks since it’s like a default statement on conversioncode function (line #141). Since I use mobnet, I had to change it in the conversion function manually. Maybe it would be interesting to automatically detect or request this as user input in the future.



Videos=[fn for fn in os.listdir(os.curdir) if (videotype in fn) and (’_labeled.mp4’ not in fn)] #exclude labeled-videos!

Allh5files=[fn for fn in os.listdir(os.curdir) if (".h5" in fn) and ("resnet" in fn)]

for video in Videos:
     vname = Path(video).stem
     #Is there a scorer for this?
     PutativeOutputFiles=[fn for fn in Allh5files if vname in fn]
     for pfn in PutativeOutputFiles:
         if "DLC" in scorer or "DeepCut" in scorer:
             DC = pd.read_hdf(pfn, 'df_with_missing')
             print("Found output file for scorer:", scorer)
             print("Converting to csv...")

print("All pose files were converted.")
1 Like