mlfpm / deepof

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

Problem with creating a project #23

Closed rosalba3574 closed 1 year ago

rosalba3574 commented 1 year ago

Hi, thank you for developing DeepOF, I am trying to use it for multianimal tracking. I have DeepLabCut tracked files, that follow your labeling scheme "deepof_8", but I run into an error when I try to create a project:


`In [47]: proj = deepof.data.Project( project_path=r"F:\MDC\Behavior\DeepOF", video_path=r"F:\MDC\Behavior\DeepOF", table_path=r"F:\MDC\Behavior\DeepOF", project_name="testproj", exp_conditions=None, bodypart_graph="deepo
    ...: f_8", arena= "polygonal-manual", animal_ids=["test_mouse", "stimulus_mouse"], video_format=".mp4")

In [48]: proj = proj.create(verbose=True)
Setting up project directories...
Loading trajectories...
Smoothing trajectories...
Interpolating outliers...
Iterative imputation of ocluded bodyparts...
Detecting arena...
<class 'pims.pyav_reader.PyAVReaderTimed'> errored: 'NoneType' object has no attribute 'open'
<class 'pims.pyav_reader.PyAVReaderIndexed'> errored: 'NoneType' object has no attribute 'open'
Exception ignored in: <function PyAVReaderIndexed.__del__ at 0x00000189FC7361F0>
Traceback (most recent call last):
  File "C:\Users\rproce\Anaconda3\envs\deepof\lib\site-packages\pims\pyav_reader.py", line 365, in __del__
    self._container.close()
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function PyAVReaderIndexed.__del__ at 0x00000189FC7361F0>
Traceback (most recent call last):
  File "C:\Users\rproce\Anaconda3\envs\deepof\lib\site-packages\pims\pyav_reader.py", line 365, in __del__
    self._container.close()
AttributeError: 'NoneType' object has no attribute 'close'
Computing distances...
Computing angles...
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~\Anaconda3\envs\deepof\lib\site-packages\deepof\data.py:558, in Project.get_angles(self, tab_dict, verbose)
    555 for clique in bridges:
    556     dat = pd.DataFrame(
    557         deepof.utils.angle(
--> 558             np.array(tab[clique]).reshape([3, tab.shape[0], 2])
    559         ).T
    560     )
    562     dat.columns = [tuple(clique)]

File ~\Anaconda3\envs\deepof\lib\site-packages\pandas\core\frame.py:3813, in DataFrame.__getitem__(self, key)
   3812         key = list(key)
-> 3813     indexer = self.columns._get_indexer_strict(key, "columns")[1]
   3815 # take() does not accept boolean indexers

File ~\Anaconda3\envs\deepof\lib\site-packages\pandas\core\indexes\multi.py:2623, in MultiIndex._get_indexer_strict(self, key, axis_name)
   2621 indexer = self._get_indexer_level_0(keyarr)
-> 2623 self._raise_if_missing(key, indexer, axis_name)
   2624 return self[indexer], indexer

File ~\Anaconda3\envs\deepof\lib\site-packages\pandas\core\indexes\multi.py:2641, in MultiIndex._raise_if_missing(self, key, indexer, axis_name)
   2640 if cmask.any():
-> 2641     raise KeyError(f"{keyarr[cmask]} not in index")
   2642 # We get here when levels still contain values which are not
   2643 # actually in Index anymore

KeyError: "['test_mouse_Left_ear' 'test_mouse_Nose' 'test_mouse_Right_ear'] not in index"

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
Cell In[48], line 1
----> 1 proj = proj.create(verbose=True)

File ~\Anaconda3\envs\deepof\lib\site-packages\deepof\data.py:681, in Project.create(self, verbose, force)
    678     distances = self.get_distances(tables, verbose)
    680 if self.angles:
--> 681     angles = self.get_angles(tables, verbose)
    683 if self.areas:
    684     areas = self.get_areas(tables, verbose)

File ~\Anaconda3\envs\deepof\lib\site-packages\deepof\data.py:569, in Project.get_angles(self, tab_dict, verbose)
    567         angle_dict[key] = dats
    568 except KeyError:
--> 569     raise KeyError(
    570         "Are you using a custom labelling scheme? Out tutorials may help! "
    571         "In case you're not, are there multiple animals in your single-animal DLC video? Make sure to set the "
    572         "animal_ids parameter in deepof.data.Project"
    573     )
    575 # Restore original index
    576 for key in angle_dict.keys():

KeyError: "Are you using a custom labelling scheme? Out tutorials may help! In case you're not, are there multiple animals in your single-animal DLC video? Make sure to set the animal_ids parameter in deepof.data.Project"`

I understand that the code sees the cell with "test_mouse" and the cell with "left_ear" as a single one, but they are separated, do you have any idea why this can happen? Thank you very much in advance, Rosalba

lucasmiranda42 commented 1 year ago

Dear Rosalba, thank you for your interest in DeepOF!

Have you checked that your body part labels match those depicted in the documentation? Unfortunately DeepOF is quite rigid with these names (although there are ways to work around it, and we're preparing an update to this to add some extra flexibility in the next release).

image

If body part names indeed match, we'll help you debug from there :)

Best! Lucas

rosalba3574 commented 1 year ago

Hi Lucas, thank you for the suggestion, I realize that the problem was the upper cases in the body parts names, sorry for bringing up a stupid mistake. Now it worked but I have a doubt: why if now the body parts correspond it gave me this message:

Computing distances...
Computing angles...
Computing areas...
It seems you're using a custom labelling scheme which is missing key body parts. You can proceed, but no areas will be computed.
Done!

If no areas are computed can it be a problem for the supervised analysis? because I was trying the supervised annotation and the code works but I don´t get dyadic interactions when I can clearly see those in the video. Do you have any ideas why this can happen? does it matter if the mice in the videos have the same fur color?

Thank you very much, Rosalba

lucasmiranda42 commented 1 year ago

Hi, Rosalba! And glad to see you managed to solve it (there are no stupid mistakes, and if the documentation is not clear that's on our side, not yours!).

Regarding the warning: the labelling scheme should have an impact on some of the supervised traits (such as huddling). However, dyadic interactions should be computed. Would you mind posting the header (no need to share data, just the header) of the output you get? That should help us see what went wrong.

EDIT: it shouldn't matter that the animals have the same fur color, unless this has an impact in the tracking itself. If you see the dyadic interactions in the header, but no events are reported, it could be a bug but it could also be a problem with the DLC tracking. Are you using multi-animal DLC?

Best! Lucas

rosalba3574 commented 1 year ago

Thank you Lucas! Here is the header of the supervised annotation:

In [50]: supervised_annotation
Out[50]:
{'955-1':                     test_mouse_stimulus_mouse_nose2nose  test_mouse_stimulus_mouse_sidebyside  ...  test_mouse_missing  stimulus_mouse_missing
 00:00:00                                            0.0                                   0.0  ...                   0                       0
 00:00:00.033158331                                  0.0                                   0.0  ...                   0                       0
 00:00:00.066316662                                  0.0                                   0.0  ...                   0                       0
 00:00:00.099474993                                  0.0                                   0.0  ...                   0                       0
 00:00:00.132633324                                  0.0                                   0.0  ...                   0                       0
 ...                                                 ...                                   ...  ...                 ...                     ...
 00:01:59.834208344                                  0.0                                   0.0  ...                   0                       0
 00:01:59.867366675                                  0.0                                   0.0  ...                   0                       0
 00:01:59.900525006                                  0.0                                   0.0  ...                   0                       0
 00:01:59.933683337                                  0.0                                   0.0  ...                   0                       0
 00:01:59.966841668                                  0.0                                   0.0  ...                   0                       0

 [3619 rows x 21 columns]}

I used multi-animal DLC for 2 black6 mice and the tracking looks nice to me, I could also share one example if needed... Best, Rosalba

rosalba3574 commented 1 year ago

I figure it out why was not working: I add the videoscale when making the project, I didn´t know it was essential, but now it works!! Thanks so much for developing DeepOF, I will keep working on that! Best, Rosalba

lucasmiranda42 commented 1 year ago

Amazing! Glad it helped! I'll close the issue then, but feel free to open a new one if needed :)