@@ -76,8 +76,17 @@ def train_network(
7676 superanimal_name : str = "" ,
7777 superanimal_transfer_learning : bool = False ,
7878 engine : Engine | None = None ,
79- ** torch_kwargs ,
79+ device : str | None = None ,
80+ snapshot_path : str | Path | None = None ,
81+ detector_path : str | Path | None = None ,
82+ batch_size : int | None = None ,
83+ detector_batch_size : int | None = None ,
84+ detector_epochs : int | None = None ,
85+ detector_save_epochs : int | None = None ,
86+ pose_threshold : float | None = 0.1 ,
87+ pytorch_cfg_updates : dict | None = None ,
8088):
89+
8190 """
8291 Trains the network with the labels in the training dataset.
8392
@@ -135,6 +144,7 @@ def train_network(
135144 Only for the PyTorch engine (equivalent to the `saveiters` parameter for the
136145 TensorFlow engine). The number of epochs between each snapshot save. If
137146 None, the value will be read from the `pytorch_config.yaml` file.
147+
138148 allow_growth: bool, optional, default=True.
139149 Only for the TensorFlow engine.
140150 For some smaller GPUs the memory issues happen. If ``True``, the memory
@@ -180,18 +190,38 @@ def train_network(
180190 overwrite this by passing the engine as an argument, but this should generally
181191 not be done.
182192
183- torch_kwargs:
184- You can add any keyword arguments for the deeplabcut.pose_estimation_pytorch
185- train_network method here. These arguments are passed to the downstream method.
186- Some of the parameters that can be passed are
187- * ``device`` (the CUDA device to use for training)
188- * ``batch_size`` (the batch size to use while training)
189- * ``snapshot_path`` (the pose model snapshot to resume training from)
190- * ``detector_path`` (the detector model snapshot to resume training from)
193+ device: str, optional, default = None.
194+ Only for the PyTorch engine. The device to run the training on (e.g. "cuda:0")
195+
196+ snapshot_path: str or Path, optional, default = None.
197+ Only for the PyTorch engine. The path to the pose model snapshot to resume training from.
198+
199+ detector_path: str or Path, optional, default = None.
200+ Only for the PyTorch engine. The path to the detector model snapshot to resume training from.
201+
202+ batch_size: int, optional, default = None.
203+ Only for the PyTorch engine. The batch size to use while training.
204+
205+ detector_batch_size: int, optional, default = None.
206+ Only for the PyTorch engine. The batch size to use while training the detector.
191207
192- When training a top-down model, these parameters are also available for the
193- detector, with the parameters ``detector_batch_size``, ``detector_epochs`` and
194- ``detector_save_epochs``.
208+ detector_epochs: int, optional, default = None.
209+ Only for the PyTorch engine. The number of epochs to train the detector for.
210+
211+ detector_save_epochs: int, optional, default = None.
212+ Only for the PyTorch engine. The number of epochs between each detector snapshot save.
213+
214+ pose_threshold: float, optional, default = 0.1.
215+ Only for the PyTorch engine. Used for memory-replay. Pseudo-predictions with confidence lower
216+ than this threshold are discarded for memory-replay
217+
218+ pytorch_cfg_updates: dict, optional, default = None.
219+ A dictionary of updates to the pytorch config. The keys are the dot-separated
220+ paths to the values to update in the config.
221+ For example, to update the gpus to run the training on, you can use:
222+ ```
223+ pytorch_cfg_updates={"runner.gpus": [0,1,2,3]}
224+ ```
195225
196226 Returns
197227 -------
@@ -255,20 +285,25 @@ def train_network(
255285 elif engine == Engine .PYTORCH :
256286 from deeplabcut .pose_estimation_pytorch .apis import train_network
257287
258- _update_device (gputouse , torch_kwargs )
259- if "display_iters" not in torch_kwargs :
260- torch_kwargs ["display_iters" ] = displayiters
261-
262288 return train_network (
263289 config ,
264290 shuffle = shuffle ,
265291 trainingsetindex = trainingsetindex ,
266292 modelprefix = modelprefix ,
267- max_snapshots_to_keep = max_snapshots_to_keep ,
293+ device = device ,
294+ snapshot_path = snapshot_path ,
295+ detector_path = detector_path ,
268296 load_head_weights = keepdeconvweights ,
297+ batch_size = batch_size ,
269298 epochs = epochs ,
270299 save_epochs = save_epochs ,
271- ** torch_kwargs ,
300+ detector_batch_size = detector_batch_size ,
301+ detector_epochs = detector_epochs ,
302+ detector_save_epochs = detector_save_epochs ,
303+ display_iters = displayiters ,
304+ max_snapshots_to_keep = max_snapshots_to_keep ,
305+ pose_threshold = pose_threshold ,
306+ pytorch_cfg_updates = pytorch_cfg_updates ,
272307 )
273308
274309 raise NotImplementedError (f"This function is not implemented for { engine } " )
0 commit comments