deeplabcut.generate_training_dataset.metadata
File containing methods to load and parse shuffle metadata.
Classes:
| Name | Description |
|---|---|
DataSplit |
Class representing the metadata for a shuffle. |
ShuffleMetadata |
Class representing the metadata for a shuffle. |
TrainingDatasetMetadata |
An immutable class containing the metadata for a dataset. |
Functions:
| Name | Description |
|---|---|
find_engines_from_model_folders |
Determines which engines are used with a given shuffle. |
get_shuffle_engine |
Args: |
update_metadata |
Updates the metadata for a training-dataset. |
DataSplit
dataclass
Class representing the metadata for a shuffle.
Methods:
| Name | Description |
|---|---|
__post_init__ |
Raises: |
Source code in deeplabcut/generate_training_dataset/metadata.py
__post_init__
Source code in deeplabcut/generate_training_dataset/metadata.py
ShuffleMetadata
dataclass
Class representing the metadata for a shuffle.
Methods:
| Name | Description |
|---|---|
load_split |
Loads the data split for this shuffle. |
Source code in deeplabcut/generate_training_dataset/metadata.py
load_split
Loads the data split for this shuffle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the config for the DeepLabCut project |
required |
|
Path
|
the path to the training dataset folder |
required |
Returns:
| Type | Description |
|---|---|
ShuffleMetadata
|
a new instance with the data split defined |
Source code in deeplabcut/generate_training_dataset/metadata.py
TrainingDatasetMetadata
dataclass
An immutable class containing the metadata for a dataset.
When creating a new "training-datasets" folder (e.g., when creating the first training set for a project, or when creating the first training for a given iteration of a project), TrainingDatasetMetadata.create(cfg) should be called when the "training-datasets" folder is still empty.
For existing projects (created with DeepLabCut < 3.0), calling TrainingDatasetMetadata.create(cfg) will go over documentation data for all existing shuffles in the training-datasets folder and add them to a new metadata instance. All shuffles will be given Engine.TF as an engine.
Examples:
Creating the metadata file for an existing project
config = "/data/my-dlc-project/config.yaml" trainset_metadata = TrainingDatasetMetadata.create(config) trainset_metadata.save()
Adding a new shuffle to the metadata file
config = "/data/my-dlc-project-2008-06-17/config.yaml" trainset_metadata = TrainingDatasetMetadata.load(config) new_shuffle = ShuffleMetadata( name="my-dlc-projectJun17-trainset60shuffle5", train_fraction=0.6, index=5, engine=compat.Engine.PYTORCH, split=DataSplit(train_indices=(1, 3, 4), test_indices=(0, 2)), ) trainset_metadata = trainset_metadata.add(new_shuffle) trainset_metadata.save() # saves to disk
Methods:
| Name | Description |
|---|---|
__post_init__ |
Raises: |
add |
Adds a new shuffle to the metadata file. |
create |
Function to create the metadata file. |
get |
Args: |
load |
Loads the metadata from disk. |
path |
Args: |
save |
Saves the training dataset metadata to disk. |
Source code in deeplabcut/generate_training_dataset/metadata.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
__post_init__
Source code in deeplabcut/generate_training_dataset/metadata.py
add
Adds a new shuffle to the metadata file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ShuffleMetadata
|
the shuffle to add |
required |
|
bool
|
if a shuffle with the same index is already stored in the metadata file, whether to overwrite it |
False
|
Returns:
| Type | Description |
|---|---|
TrainingDatasetMetadata
|
A new instance of TrainingDatasetMetadata with updated shuffles |
Raises:
| Type | Description |
|---|---|
ValueError
|
if overwrite=False and there is already a shuffle with the given index in the metadata file. |
Source code in deeplabcut/generate_training_dataset/metadata.py
create
staticmethod
Function to create the metadata file.
Assumes that all existing shuffles use the TensorFlow engine, as this file should have already been created for PyTorch shuffles.
Args; config: the config for the DeepLabCut project (or its path) default_engine: the default engine to set for shuffles in the project
Returns:
| Type | Description |
|---|---|
TrainingDatasetMetadata
|
the metadata for the existing shuffles in the project |
Source code in deeplabcut/generate_training_dataset/metadata.py
get
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
the index of the trainset fraction as defined in config.yaml |
0
|
|
int
|
the index of the shuffle |
0
|
Returns:
| Type | Description |
|---|---|
ShuffleMetadata
|
the shuffle with the given trainset index and shuffle index |
Source code in deeplabcut/generate_training_dataset/metadata.py
load
staticmethod
Loads the metadata from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | dict
|
the config for the DeepLabCut project (or its path) |
required |
|
bool
|
whether to load the data split for each shuffle |
False
|
Source code in deeplabcut/generate_training_dataset/metadata.py
path
staticmethod
save
Saves the training dataset metadata to disk.
Source code in deeplabcut/generate_training_dataset/metadata.py
find_engines_from_model_folders
find_engines_from_model_folders(cfg: dict, trainingsetindex: int, shuffle: int, modelprefix: str = '') -> set[Engine]
Determines which engines are used with a given shuffle.
This method can be useful when using modelprefix, as the engine for a shuffle stored under a "modelprefix" might not be the same as the base shuffle (for which the engine is stored in the training-datasets folder).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the config for the DeepLabCut project |
required |
|
int
|
the training set index used |
required |
|
int
|
the shuffle for which to get the engine |
required |
|
str
|
the model prefix, if there is one |
''
|
Returns:
| Type | Description |
|---|---|
set[Engine]
|
the engines for which a model folder exists for the given shuffle |
Source code in deeplabcut/generate_training_dataset/metadata.py
get_shuffle_engine
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the config for the DeepLabCut project |
required |
|
int
|
the training set index used |
required |
|
int
|
the shuffle for which to get the engine |
required |
|
str
|
the model prefix, if there is one |
''
|
Returns:
| Type | Description |
|---|---|
Engine
|
the engine that the shuffle was created with |
Source code in deeplabcut/generate_training_dataset/metadata.py
update_metadata
update_metadata(
cfg: dict,
train_fraction: float,
shuffle: int,
engine: Engine,
train_indices: list[int],
test_indices: list[int],
overwrite: bool = False,
) -> None
Updates the metadata for a training-dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the config for the DeepLabCut project |
required |
|
float
|
the train_fraction of the new shuffle |
required |
|
int
|
the index of the shuffle to add |
required |
|
Engine
|
the engine for the shuffle |
required |
|
list[int]
|
the indices of images in the training set |
required |
|
list[int]
|
the indices of images in the test set |
required |
|
bool
|
whether to overwrite a shuffle with the same index and train fraction if one exists |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if overwrite=False and there is already a shuffle with the given index in the metadata file. |