COCO Processing
create_dataset
create_dataset(
description,
contributor,
version=str(Version(major=0)),
date_created=datetime.now(),
)
Instances and returns a new CocoDataset model with given kwargs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
Description of your COCO dataset |
required |
contributor |
str
|
Main contributors of your COCO dataset, its images and its annotations |
required |
version |
str
|
Initial SemVer version (defaults to 0.0.0) |
str(Version(major=0))
|
date_created |
datetime
|
Date when dataset was initially created, defaults to datetime.now() |
now()
|
Returns:
Type | Description |
---|---|
CocoDataset
|
An instance of CocoDataset without Image- and Annotation objects |
Source code in geococo\coco_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
load_dataset
load_dataset(json_path)
Dumps the contents of json_path as a string, interprets it as a CocoDataset model and returns it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_path |
Path
|
path to the JSON file containing the json-encoded COCO dataset |
required |
Returns:
Type | Description |
---|---|
CocoDataset
|
An instance of CocoDataset with loaded Image- and Annotation objects from json_path |
Source code in geococo\coco_manager.py
7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
save_dataset
save_dataset(dataset, json_path)
JSON-encodes an instance of CocoDataset and saves it to json_path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
CocoDataset
|
An instance of CocoDataset |
required |
json_path |
Path
|
where to save the JSON-encoded CocoDataset instance to |
required |
Source code in geococo\coco_manager.py
50 51 52 53 54 55 56 57 58 59 |
|
append_dataset
append_dataset(
dataset,
images_dir,
src,
window_bounds,
labels,
id_attribute=None,
name_attribute=None,
super_attribute=None,
)
Move across a given geotiff, converting all intersecting labels to COCO annotations and appending them to a COCODataset model. This is done through rasterio.Window objects, the bounds of which you can set with window_bounds (also determines the size of the output images associated with the Annotation instances). The degree of overlap between these windows is determined by the dimensions of the given labels to maximize representation in the resulting dataset.
The "iscrowd" attribute (see https://cocodataset.org/#format-data) is determined by whether the respective labels are Polygon or MultiPolygon instances. The attribute arguments are column names of the GeoDataFrame and are used to supply (super)category names, category ids, or both. If only names are given, ids are autogenerated (and vice versa). Lastly, each call to this method will increment the dataset version: patch if using the same image_path, minor if using a new image_path, and major if using a new output_dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
CocoDataset
|
CocoDataset model to append images and annotations to |
required |
images_dir |
Path
|
output directory for all label images |
required |
src |
DatasetReader
|
open rasterio reader for input raster |
required |
labels |
GeoDataFrame
|
GeoDataFrame containing labels and class_info ('category_id') |
required |
window_bounds |
List[Tuple[int, int]]
|
a list of window_bounds to attempt to use () |
required |
id_attribute |
Optional[str]
|
Column containing category_id values |
None
|
name_attribute |
Optional[str]
|
Column containing category_name values |
None
|
super_attribute |
Optional[str]
|
Column containing supercategory values |
None
|
Returns:
Type | Description |
---|---|
CocoDataset
|
CocoDataset with n appended Image, Category and Annotation instances |
Source code in geococo\coco_processing.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 |
|