artus.prepare package
Submodules
artus.prepare.coco_splitting module
The module provides a splitter to prepare coco annotations files for deep learning training process.
The class: COCOSplitter splits a coco annnotations file into 3 files : the coco_train, coco_test and coco_val. Annotations are firstly parsed so under-reprensentated classes are removed. Proportions of annotations per class are maintained in the splits.
Typical usage examples:
- `splitter = COCOSplitter(
coco_path=’/path/to/coco.json’, export_dir=’/path/to/export/coco/splits/’, coco_train_name=’coco_train’, coco_test_name=’coco_test’, coco_val_name=’coco_val’, min_nb_occurences=50, train_pct=.8, val_pct=.1, test_pct=.1, batch_size=8
)` splitter.split()
- class artus.prepare.coco_splitting.COCOSplitter(coco_path, export_dir, coco_train_name, coco_test_name, coco_val_name, min_nb_occurrences=None, train_pct=0.8, val_pct=0.1, test_pct=0.1, batch_size=8)
Bases:
COCOStatsSplits a coco file into a train, test and (optional) validation coco files.
Under-reprensentated classes are optionnally removed according the min_nb_occurrences set. Proportions of class annotations are kept into the splits. If no train_pct, val_pct or test_pct are set, proportions of annotations in th splits will be set to 0.8, 0.1 and 0.1 respectively.
- coco_path
a path to a coco file
- Type:
str
- export_dir
a directory where the splits of the coco files will be exported
- Type:
str
- coco_train_name
the name of the file with the annotations for training
- Type:
str
- coco_test_name
the name of the file with the annotations for testing
- Type:
str
- coco_val_name
the name of the file with the annotations for validation
- Type:
str
- min_nb_occurrences
the minimum number of occurrences of a class to be
- Type:
int
- kept in the dataset to remove under representated classes
- train_pct
the fraction of annotations that will go into the train coco file
- Type:
float
- val_pct
the fraction of annotations that will go into the validation coco file
- Type:
float
- test_pct
the fraction of annotations that will go into the test coco file
- Type:
float
- batch_size
number of images per batch process
- Type:
int
- create_train_test_val_datasets()
Create dataset in the pylabel format to be populated by annotations aftersplitting.
- Returns:
a training dataset in the pylabel format dataset_val: a validation dataset in the pylabel format dataset_test: a test dataset in the pylabel format
- Return type:
dataset_train
- split_coco()
Splits coco files and export them in COCO format in the :py:attribute: export_dir.
- Returns:
The proportions of class between the splits.
artus.prepare.crs_settings module
- artus.prepare.crs_settings.check_crs(obj, crs_code)
Check if the layers provided are set to the correct CRS.
- Parameters:
obj – a raster or vector layer read with rasterio or geopandas
crs_code (str) – the CRS number to check
- Returns:
True or False. True means that CRS of the layer is the one expected.