When I try to analyze my multi-animal project using BUCTD models on Colab, I encounter an error during the video analysis step. I have verified that both networks were successfully trained by adjusting the shuffle number to 1 and 3, and by setting ctd_tracking=False. However, I am unsure if this error is related to previous issues (#1818, #2684).
deeplabcut.analyze_videos(
config,
videofile_path,
shuffle=CTD_SHUFFLE,
ctd_tracking=True,
save_as_csv=True,
)
Analyzing videos with /content/drive/My Drive/LDx_v4m-HLH-2025-05-14/dlc-models-pytorch/iteration-1/LDx_v4mMay14-trainset80shuffle3/train/snapshot-best-070.pt
CTD tracking can only be used with batch size 1. Updating it.
Starting to analyze /content/drive/My Drive/LDx_v4m-HLH-2025-05-14/videos/mod3.mkv
Video metadata:
Overall # of frames: 969
Duration of video [s]: 31.98
fps: 30.3
resolution: w=1920, h=1080
Running pose prediction with batch size 1
4%|▍ | 37/969 [00:03<01:21, 11.49it/s]
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-10-74060d4d252a> in <cell line: 0>()
----> 1 deeplabcut.analyze_videos(
2 config,
3 videofile_path,
4 shuffle=CTD_SHUFFLE,
5 ctd_tracking=True,
9 frames
/usr/local/lib/python3.11/dist-packages/deeplabcut/compat.py in analyze_videos(config, videos, videotype, shuffle, trainingsetindex, gputouse, save_as_csv, in_random_order, destfolder, batchsize, cropping, TFGPUinference, dynamic, modelprefix, robust_nframes, allow_growth, use_shelve, auto_track, n_tracks, animal_names, calibrate, identity_only, use_openvino, engine, **torch_kwargs)
952 torch_kwargs["batch_size"] = batchsize
953
--> 954 return analyze_videos(
955 config,
956 videos=videos,
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py in analyze_videos(config, videos, videotype, shuffle, trainingsetindex, save_as_csv, in_random_order, snapshot_index, detector_snapshot_index, device, destfolder, batch_size, detector_batch_size, dynamic, ctd_conditions, ctd_tracking, top_down_dynamic, modelprefix, use_shelve, robust_nframes, transform, auto_track, n_tracks, animal_names, calibrate, identity_only, overwrite, cropping, save_as_df)
543 else:
544 runtime = [time.time()]
--> 545 predictions = video_inference(
546 video=video_iterator,
547 pose_runner=pose_runner,
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py in video_inference(video, pose_runner, detector_runner, cropping, shelf_writer, robust_nframes)
202 shelf_writer.open()
203
--> 204 predictions = pose_runner.inference(images=tqdm(video), shelf_writer=shelf_writer)
205 if shelf_writer is not None:
206 shelf_writer.close()
/usr/local/lib/python3.11/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
117
118 return decorate_context
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in inference(self, images, shelf_writer)
392 """
393 if self.tracking:
--> 394 return self._ctd_tracking_inference(images, shelf_writer)
395
396 results = []
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in _ctd_tracking_inference(self, images, shelf_writer)
487 results = []
488 for data in images:
--> 489 inputs, context = self._prepare_ctd_inputs(data)
490 model_kwargs = context.pop("model_kwargs", {})
491 predictions = self.predict(inputs, **model_kwargs)
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in _prepare_ctd_inputs(self, data)
545 return torch.as_tensor(inputs), context
546
--> 547 inputs, context = self.preprocessor(inputs, context)
548 return inputs, context
549
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/preprocessor.py in __call__(self, image, context)
176 def __call__(self, image: Image, context: Context) -> tuple[Image, Context]:
177 for preprocessor in self.components:
--> 178 image, context = preprocessor(image, context)
179 return image, context
180
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/preprocessor.py in __call__(self, image, context)
389 images, offsets, scales = [], [], []
390 for bbox in context["bboxes"]:
--> 391 crop, offset, scale = top_down_crop(
392 image,
393 bbox,
/usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/image.py in top_down_crop(image, bbox, output_size, margin, center_padding, crop_with_context)
273 w, h = x2 - x1, y2 - y1
274 if not crop_with_context:
--> 275 input_ratio = w / h
276 output_ratio = out_w / out_h
277 if input_ratio > output_ratio: # h/w < h0/w0 => h' = w * h0/w0
ZeroDivisionError: division by zero
Is there an existing issue for this?
Operating System
COLAB
DeepLabCut version
3.0.0rc8
What engine are you using?
pytorch
DeepLabCut mode
multi animal
Device type
Tesla T4
Bug description 🐛
When I try to analyze my multi-animal project using BUCTD models on Colab, I encounter an error during the video analysis step. I have verified that both networks were successfully trained by adjusting the shuffle number to 1 and 3, and by setting ctd_tracking=False. However, I am unsure if this error is related to previous issues (#1818, #2684).
Steps To Reproduce
BU_SHUFFLE = 1( net_type: resnet_50)
CTD_SHUFFLE = 3( net_type: ctd_prenet_cspnext_m)
config.txt
Relevant log output
deeplabcut.analyze_videos( config, videofile_path, shuffle=CTD_SHUFFLE, ctd_tracking=True, save_as_csv=True, ) Analyzing videos with /content/drive/My Drive/LDx_v4m-HLH-2025-05-14/dlc-models-pytorch/iteration-1/LDx_v4mMay14-trainset80shuffle3/train/snapshot-best-070.pt CTD tracking can only be used with batch size 1. Updating it. Starting to analyze /content/drive/My Drive/LDx_v4m-HLH-2025-05-14/videos/mod3.mkv Video metadata: Overall # of frames: 969 Duration of video [s]: 31.98 fps: 30.3 resolution: w=1920, h=1080 Running pose prediction with batch size 1 4%|▍ | 37/969 [00:03<01:21, 11.49it/s] --------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) <ipython-input-10-74060d4d252a> in <cell line: 0>() ----> 1 deeplabcut.analyze_videos( 2 config, 3 videofile_path, 4 shuffle=CTD_SHUFFLE, 5 ctd_tracking=True, 9 frames /usr/local/lib/python3.11/dist-packages/deeplabcut/compat.py in analyze_videos(config, videos, videotype, shuffle, trainingsetindex, gputouse, save_as_csv, in_random_order, destfolder, batchsize, cropping, TFGPUinference, dynamic, modelprefix, robust_nframes, allow_growth, use_shelve, auto_track, n_tracks, animal_names, calibrate, identity_only, use_openvino, engine, **torch_kwargs) 952 torch_kwargs["batch_size"] = batchsize 953 --> 954 return analyze_videos( 955 config, 956 videos=videos, /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py in analyze_videos(config, videos, videotype, shuffle, trainingsetindex, save_as_csv, in_random_order, snapshot_index, detector_snapshot_index, device, destfolder, batch_size, detector_batch_size, dynamic, ctd_conditions, ctd_tracking, top_down_dynamic, modelprefix, use_shelve, robust_nframes, transform, auto_track, n_tracks, animal_names, calibrate, identity_only, overwrite, cropping, save_as_df) 543 else: 544 runtime = [time.time()] --> 545 predictions = video_inference( 546 video=video_iterator, 547 pose_runner=pose_runner, /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py in video_inference(video, pose_runner, detector_runner, cropping, shelf_writer, robust_nframes) 202 shelf_writer.open() 203 --> 204 predictions = pose_runner.inference(images=tqdm(video), shelf_writer=shelf_writer) 205 if shelf_writer is not None: 206 shelf_writer.close() /usr/local/lib/python3.11/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs) 114 def decorate_context(*args, **kwargs): 115 with ctx_factory(): --> 116 return func(*args, **kwargs) 117 118 return decorate_context /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in inference(self, images, shelf_writer) 392 """ 393 if self.tracking: --> 394 return self._ctd_tracking_inference(images, shelf_writer) 395 396 results = [] /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in _ctd_tracking_inference(self, images, shelf_writer) 487 results = [] 488 for data in images: --> 489 inputs, context = self._prepare_ctd_inputs(data) 490 model_kwargs = context.pop("model_kwargs", {}) 491 predictions = self.predict(inputs, **model_kwargs) /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/runners/inference.py in _prepare_ctd_inputs(self, data) 545 return torch.as_tensor(inputs), context 546 --> 547 inputs, context = self.preprocessor(inputs, context) 548 return inputs, context 549 /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/preprocessor.py in __call__(self, image, context) 176 def __call__(self, image: Image, context: Context) -> tuple[Image, Context]: 177 for preprocessor in self.components: --> 178 image, context = preprocessor(image, context) 179 return image, context 180 /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/preprocessor.py in __call__(self, image, context) 389 images, offsets, scales = [], [], [] 390 for bbox in context["bboxes"]: --> 391 crop, offset, scale = top_down_crop( 392 image, 393 bbox, /usr/local/lib/python3.11/dist-packages/deeplabcut/pose_estimation_pytorch/data/image.py in top_down_crop(image, bbox, output_size, margin, center_padding, crop_with_context) 273 w, h = x2 - x1, y2 - y1 274 if not crop_with_context: --> 275 input_ratio = w / h 276 output_ratio = out_w / out_h 277 if input_ratio > output_ratio: # h/w < h0/w0 => h' = w * h0/w0 ZeroDivisionError: division by zeroAnything else?
No response
Code of Conduct