lacss.data
Lacss Data Pipeline API
TF Dataset
dataset_from_coco_annotations(annotation_file, image_path, image_shape=[None, None, 3], mask_shape=[48, 48])
Obtaining a tensowflow dataset from coco annotations. See coco_generator_full()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_file
|
str
|
Path to coco annotation files |
required |
image_path
|
str
|
Path to image directory |
required |
image_shape
|
tuple
|
The expect image shapes. Use None to represent variable dimensions. |
[None, None, 3]
|
mask_shape
|
tuple
|
If supplied, all the instance segmentations will be croped and resized to the specifed size. Otherwise, the segmentations are uncropped (in original image size) |
[48, 48]
|
Returns:
Type | Description |
---|---|
'Dataset'
|
A tensorflow dataset. |
dataset_from_simple_annotations(annotation_file, image_path, image_shape=[None, None, 1], has_binary_mask=False)
Obtaining a tensowflow dataset from simple annotatiion. See simple_generator()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_file
|
str
|
Path to the json format annotation file. |
required |
image_path
|
str
|
Path to the image directory. |
required |
image_shape
|
Sequence[int | None]
|
The expect image shapes. Use None to represent variable dimensions. |
[None, None, 1]
|
has_binary_mask
|
bool
|
whether the annotation specific a binary mask |
False
|
Returns:
Type | Description |
---|---|
'Dataset'
|
A tensorflow dataset object |
dataset_from_img_mask_pairs(imgfiles, maskfiles, *, image_shape=[None, None, 3], generate_masks=False, mask_shape=[48, 48])
Obtaining a tensowflow dataset from image/label pairs. See img_mask_pair_generator()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imgfiles
|
Sequence[str | Path]
|
List of file pathes to input image file. |
required |
maskfiles
|
Sequence[str | Path]
|
List of file pathes to label image file. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
image_shape |
Sequence[int | None]
|
The expect image shapes. Use None to represent variable dimensions. |
generate_masks |
bool
|
Whether to convert label images to indiviudal instance masks. This should be True if your data augmentation pipeline include rescaling ops or cropping ops., becasue these ops does not recompute the label image. |
mask_shape |
tuple[int, int]
|
Only when generate_mask=True. The resolution of the generated masks. |
Returns:
Type | Description |
---|---|
'Dataset'
|
A tensorflow dataset object |
Data augmentation
The augmentation functions for TF Dataset inputs.
crop_to_roi(inputs, *, roi, area_ratio_threshold=1.0, clip_boxes=True, p=1.0)
Crop image to bounding-box ROI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
roi |
tuple[int, ...]
|
Rectangle roi in yxyx format |
area_ratio_threshold |
float
|
remove instances if the bbox's relative remaining area is below this threshold |
p |
float
|
probability of applying transformation |
flip_left_right(inputs, *, p=1.0)
Flip image left-right
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
p |
float
|
probability of applying transformation |
flip_top_bottom(inputs, *, p=1.0)
Flip image up-down
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
p |
float
|
probability of applying transformation |
flip_up_down(inputs, *, p=1.0)
Flip image up-down
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
p |
float
|
probability of applying transformation |
pad(inputs, *, paddings, constant_values=0, p=1.0)
Pad image and labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
paddings |
int | tuple[int, ...]
|
either a tuple or a single value. If latter, use the same padding for both x and y axis |
constant_values |
float
|
the value to fill the padded area |
p |
float
|
probability of applying transformation |
pad_to_size(inputs, *, target_size, constant_values=0, p=1.0)
Pad image and labels to a target size. Padding is applied so that the orginal scene is centered in the output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
target_size |
int | tuple[int, ...]
|
target image size |
constant_values |
float
|
the value to fill the padded area |
p |
float
|
probability of applying transformation |
random_crop(inputs, *, target_size, area_ratio_threshold=1.0, clip_boxes=True, p=1.0)
Random crop to a set target size
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
target_size |
int | tuple[int, ...]
|
the target size |
area_ratio_threshold |
float
|
remove instances if the bbox's relative remaining area is below this threshold |
p |
float
|
probability of applying transformation |
random_crop_or_pad(inputs, *, target_size, constant_values=0, area_ratio_threshold=1.0, clip_boxes=True, p=1.0)
Random crop or pad image to specified target_size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
target_size |
tuple[int, int]
|
target size |
constant_values |
float
|
the value to fill the padded area |
area_ratio_threshold |
float
|
remove instances if the bbox's relative remaining area is below this threshold |
p |
float
|
probability of applying transformation |
random_resize(inputs, *, scaling, keep_aspect_ratio=False, p=1.0)
Resize image by a random amount
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
scaling |
float | tuple[float, float]
|
range of scale, e.g, [0.8, 1.5]. |
keep_aspect_ratio |
bool
|
Whether to scale x/y the same amount. |
p |
float
|
probability of applying transformation |
resize(inputs, *, target_size, p=1.0)
Resize image and labels
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
data from TF dataset. Affected elements are:
|
required |
Other Parameters:
Name | Type | Description |
---|---|---|
target_size |
tuple[int, int]
|
target size |
p |
float
|
probability of applying transformation |
Python generator
coco_generator_full(annotation_file, image_path, mask_shape=None)
A generator function to produce coco-annotated data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_file
|
str
|
Path to coco annotation files |
required |
image_path
|
str
|
Path to image directory |
required |
mask_shape
|
Optional[tuple[int, int]]
|
If supplied, all the instance segmentations will be croped and resized to the specifed size. Otherwise, the segmentations are uncropped (in original image size) |
None
|
Yields:
Type | Description |
---|---|
dict
|
A data dictionary with thse keys:
|
simple_generator(annotation_file, image_path)
A simple generator function to produce image data labeled with points and image-level segmentaion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_file
|
str
|
Path to the json format annotation file. |
required |
image_path
|
str
|
Path to the image directory. |
required |
Yields:
Type | Description |
---|---|
dict
|
A data dictionary with thse keys:
|
img_mask_pair_generator(imgfiles, maskfiles, *, mask_shape=None)
A generator function to produce image data labeled with segmentation labels. In this case, one has paired input images and label images as files on disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imgfiles
|
Sequence[str | Path]
|
List of file pathes to input image file. |
required |
maskfiles
|
Sequence[str | Path]
|
List of file pathes to label image file. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
mask_shape |
tuple[int] | None
|
if not None, generate cropped masks at specified shape |
Yields:
Type | Description |
---|---|
dict
|
A data dictionary with thse keys:
|