mlfpm / deepof

DeepLabCut based data analysis package including pose estimation and representation learning mediated behavior recognition
MIT License
36 stars 6 forks source link

Issue in Project Creation #39

Open olivialaw opened 2 months ago

olivialaw commented 2 months ago

Hello!

I'm trying to create a project, and I'm running into an error. I'm exporting tracks from SLEAP, and I've tried using an h5 and npy, but I encounter the same error. Here is my code:

my_deepof_project = deepof.data.Project(
    project_path=os.path.join("C:/Users/olaw1/Downloads"),
    video_path=os.path.join("C:/Users/olaw1/Downloads/SLEAPVIDEOS"),
    table_path=os.path.join("C:/Users/olaw1/Downloads/SLEAPTRACKED"), 
    project_name="my_deepof_project",
    arena="polygonal-autodetect",
    rename_bodyparts=['nose', 'right_ear', 'left_ear', 'neck', 'centroid', 'right_front_paw', 'left_front_paw', 'right_back_paw', 'left_back_paw', 'tail_base', 'tail_mid', 'tail_tip'],
    animal_ids=['track_0', 'track_1', 'track_2'],
    table_format=".npy",
    video_scale=380,  # Set to the arena

)

my_deepof_project = my_deepof_project.create(verbose=True)

It's able to create the folder, but when I try to run the last line, I get this error:

`>>> my_deepof_project = my_deepof_project.create(verbose=True) Setting up project directories... Loading trajectories... Traceback (most recent call last): File "", line 1, in File "C:\Users\olaw1\Miniconda3\envs\deepof\lib\site-packages\deepof\data.py", line 681, in create tables, quality = self.load_tables(verbose) File "C:\Users\olaw1\Miniconda3\envs\deepof\lib\site-packages\deepof\data.py", line 354, in load_tables loaded_tab = deepof.utils.load_table( File "C:\Users\olaw1\Miniconda3\envs\deepof\lib\site-packages\deepof\utils.py", line 611, in load_table len(rename_bodyparts) == loaded_tab.shape[2] IndexError: tuple index out of range

`

Thanks for your help!!

lucasmiranda42 commented 2 months ago

Dear @olivialaw,

Thank you very much for your interest in DeepOF! The error seems to come from a mismatch between the number of body parts in your file and the number of names you provided to rename_bodyparts. Could this be the case?

As the command stands, DeepOF will try to fit a 14-bodypart skeleton to your data. If you indeed have 12 body parts (the number of labels you provided) you would need to load a custom body part model when defining the project. It would go something like this:

deepof_custom = {
    "nose": ["left_ear", "right_ear"],
    "neck": ["left_ear", "right_ear"],
    "centroid": [
      "neck",
      "right_front_paw", 
      "left_front_paw", 
      "right_back_paw", 
      "left_back_paw", 
      "tail_base"
    ],
    "tail_base": ["tail_mid"],
    "tail_mid": ["tail_tip"],
}

my_deepof_project = deepof.data.Project(
    project_path=os.path.join("C:/Users/olaw1/Downloads"),
    video_path=os.path.join("C:/Users/olaw1/Downloads/SLEAPVIDEOS"),
    table_path=os.path.join("C:/Users/olaw1/Downloads/SLEAPTRACKED"), 
    project_name="my_deepof_project",
    arena="polygonal-autodetect",
    bodypart_graph=deepof_custom,
    rename_bodyparts=['nose', 'right_ear', 'left_ear', 'neck', 'centroid', 'right_front_paw', 'left_front_paw', 'right_back_paw', 'left_back_paw', 'tail_base', 'tail_mid', 'tail_tip'],
    animal_ids=['track_0', 'track_1', 'track_2'],
    table_format=".npy",
    video_scale=380,  # Set to the arena
)

my_deepof_project = my_deepof_project.create(verbose=True)

You can find more information on the custom body part tutorial!

Please let me know if this does the trick :) In case it doesn't, feel free to share a file that causes this error, so we can further troubleshoot.

One more thing: be careful with the video_scale parameter. I see it's set to 380, the value we use in the tutorial. This should match the length of the first side you label in your arena; otherwise, the supervised annotation pipeline will not work properly. Feel free to ask if you have any questions! But you should find details in the formatting tutorial.

Best wishes, and all the best with your analysis! Lucas

olivialaw commented 2 months ago

Hi Lucas,

Thanks for the response! I tried rerunning the code with the custom labeling, and it still isn't working for me. I still get the same errors. I tried using both an h5 file and an npy file. Here is the custom label code I used to mimic my skeleton:

deepof_custom = {
    "nose": ["left_ear", "right_ear", "neck"],
    "neck": ["right_front_paw", "left_front_paw", "centroid"],
    "centroid": [
      "right_back_paw", 
      "left_back_paw", 
      "tail_base"
    ],
    "tail_base": ["tail_mid"],
    "tail_mid": ["tail_tip"],
}

Good catch with the video_scale! I'm not sure how to get the video_scale parameter to work. It said in the formatting tutorial that a GUI should open, or there should be an automatically generated file saved in the arena detection folder, but it's not doing that.

Is there somewhere I could send the files to? I really appreciate any help you can provide with this! Thank you for helping me with the troubleshooting!

Olivia

lucasmiranda42 commented 2 months ago

Dear Olivia,

Thank you very much for your efforts! Here you have an upload link to our secure servers (the files will only be visible to us upon upload).

Best, and looking forward to solving the issue, Lucas

olivialaw commented 2 months ago

Awesome, thanks! I shared some files with you. Let me know if you need me to share any others! And thanks again for your assistance.

lucasmiranda42 commented 1 month ago

Dear @olivialaw,

First, my apologies for taking this long to reply. I tried the files you uploaded and found two small mistakes that were breaking the code.

The first one is actually on our side. It turns out that DeepOF, in its current implementation, searches for analysis.h5 in the SLEAP file name when trying to find it. Renaming C293_Baseline.h5 to C293_Baseline_analysis.h5 does the trick for now, but we'll make sure to change this in future updates.

On top of that, the body part names in the code above were not matching the h5 file you uploaded (the file uses spaces instead of underscores). The snippet below did the trick for me! I was able to run the notebooks without issue.

deepof_custom = {
    "nose": ["left ear", "right ear", "neck"],
    "neck": ["right front paw", "left front paw", "centroid"],
    "centroid": [
      "right back paw", 
      "left back paw", 
      "tail base"
    ],
    "tail base": ["tail mid"],
    "tail mid": ["tail tip"],
}

my_deepof_project_raw = deepof.data.Project(
                project_path=os.path.join("../../../../../Downloads/"),
                video_path=os.path.join("../../../../../Downloads/DeepOF_troubleshooting/Videos/"),
                table_path=os.path.join("../../../../../Downloads/DeepOF_troubleshooting/Tables/"),
                project_name="deepof_tutorial_project",
                arena="circular-autodetect",
                animal_ids=['track_0', 'track_1', 'track_2'],
                bodypart_graph=deepof_custom,
                table_format="analysis.h5",
                video_format=".mp4",
                video_scale=380, # Remember to set this to your actual scale
                smooth_alpha=1,
                exp_conditions=None,
)

I will leave the issue open and mark the SLEAP h5 naming as a potential enhancement for future patches.

Let us know if this worked!

Best, Lucas