umyelab / LabGym

Quantify user-defined behaviors.
GNU General Public License v3.0
64 stars 5 forks source link

[ANALYSE BEHAVIOR WITH DETECTOR] Error in analyzebehaviorsdetector.py #76

Closed karinmcode closed 7 months ago

karinmcode commented 10 months ago

Hi,

I have trained a categorizer with detector and now would like to analyse a video. When doing so I get this error:

Preparation started...
2023-11-14 14:01:49.123483
The total categories of animals / objects in this Detector: ['mouse']
The animals / objects of interest in this Detector: ['mouse']
The inferencing framesize of this Detector: 320
[11/14 14:01:49 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from /Users/karinmorandell/miniconda3/envs/labgym/lib/python3.10/site-packages/LabGym/detectors/detector_231110_01/model_final.pth ...
Video fps: 10
The original video framesize: 576 X 704
Preparation completed!

Acquiring information in each frame...
2023-11-14 14:01:50.152808
/Users/karinmorandell/miniconda3/envs/labgym/lib/python3.10/site-packages/LabGym/analyzebehaviorsdetector.py:410: RuntimeWarning: invalid value encountered in divide
  exclusion_mask[np.where((np.sum(np.logical_and(masks[:,None],masks),axis=(2,3))/mask_area[:,None]>0.8) & (mask_area[:,None]<mask_area[None,:]))[0]]=True

Traceback (most recent call last):

  File "/Users/karinmorandell/miniconda3/envs/labgym/lib/python3.10/site-packages/LabGym/gui_analyzers.py", line 873, in analyze_behaviors
    AAD.acquire_information(batch_size=self.detector_batch,background_free=self.background_free)

  File "/Users/karinmorandell/miniconda3/envs/labgym/lib/python3.10/site-packages/LabGym/analyzebehaviorsdetector.py", line 706, in acquire_information
    self.detect_track_individuals(batch,batch_size,frame_count_analyze,background_free=background_free,animation=animation)

  File "/Users/karinmorandell/miniconda3/envs/labgym/lib/python3.10/site-packages/LabGym/analyzebehaviorsdetector.py", line 447, in detect_track_individuals
    goodcontours.append(sorted(cnts,key=cv2.contourArea,reverse=True)[0])

IndexError: list index out of range

Thank you for your help.

yujiahu415 commented 10 months ago

Hi,

This error was possibly because the Detector was not able to detect the mouse well in some frames. You can try to train a new Detector with the inferencing frame size increased to 480 (I saw currently it was 320). But increasing the inferencing frame size will reduce the processing speed. If you don't want to compromise the speed, you can try to increase the number of annotated images (maybe double the current amount) for training the Detector. By the way, how many images did you annotate for training the current Detector?

Let me know if you still have the error after trying the two ways.

karinmcode commented 10 months ago

Hi,

Thank you for your quick answer. I changed the size of the inferencing frame from 320 to 480 worked. I do not get the error message anymore. I trained the detector with 120 frames for a start. I will try increasing the number of training frames for the detector as well.