geowatch.cli.coco_add_ignore_buffer module

class geowatch.cli.coco_add_ignore_buffer.CocoAddIgnoreBufferConfig(*args, **kwargs)[source]

Bases: DataConfig

Given a kwcoco file and buffer size update annotations to include ignore buffer regions around polygons

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

default = {'dst': <Value(None)>, 'ignore_buffer_size': <Value('10@10GSD')>, 'src': <Value(None)>}
geowatch.cli.coco_add_ignore_buffer.main(cmdline=1, **kwargs)[source]
IGNORE:
python $HOME/Desktop/geowatch/geowatch/cli/coco_add_ignore_buffer.py

–src $HOME/Desktop/dvc_repos/smart_phase3_data/Aligned-Drop8-ARA/KR_R002/imganns-KR_R002-rawbands.kwcoco.zip –dst $HOME/Desktop/dvc_repos/smart_phase3_data/Aligned-Drop8-ARA/KR_R002/imganns-KR_R002_modified-rawbands.kwcoco.zip

CommandLine

xdoctest -m geowatch.cli.coco_add_ignore_buffer
xdoctest $HOME/Desktop/geowatch/geowatch/cli/coco_add_ignore_buffer.py

Example

>>> from geowatch.cli.coco_add_ignore_buffer import *
>>> import geowatch
>>> import ubelt as ub
>>> import kwcoco
>>> dpath = ub.Path.appdir('geowatch/tests/ignore_buffer')
>>> dpath.ensuredir()
>>> ignore_buffer_size = '10@10GSD'
>>> dst = dpath / 'out.kwcoco.zip'
>>> src = geowatch.coerce_kwcoco('geowatch-msi', geodata=True, dates=True)
>>> kwargs = dict(src=src.data_fpath, dst=dst)
>>> main(cmdline=0, **kwargs)
>>> result_dest = kwcoco.CocoDataset(dst)
>>> # Check non of the ignore polygons are overlaping non-ignore
>>> from shapely.ops import unary_union
>>> for video_id in result_dest.videos():
>>>     images = result_dest.images(video_id=video_id)
>>>     for image_id in images:
>>>         src_coco_img = src.coco_image(image_id)
>>>         dst_coco_img = result_dest.coco_image(image_id)
>>>         src_annots = src_coco_img.annots()
>>>         dst_annots = dst_coco_img.annots()
>>>         new_aids = ub.oset(dst_annots) - ub.oset(src_annots)
>>>         old_aids = list(src_annots)
>>>         # The old polygons (new polys should not intersect these)
>>>         old_polys = [p.to_shapely() for p in result_dest.annots(old_aids).detections.data['segmentations']]
>>>         # The new polygons that should be the ignored regions
>>>         new_polys = [p.to_shapely() for p in result_dest.annots(new_aids).detections.data['segmentations']]
>>>         new_poly = unary_union(new_polys)
>>>         old_poly = unary_union(old_polys)
>>>         isect_poly = new_poly.intersection(old_poly)
>>>         union_poly = new_poly.union(old_poly)
>>>         iou = isect_poly.area / union_poly.area
>>>         print(f'image_id={image_id}, iou = {ub.urepr(iou, nl=1)}')
>>>         # The iou should be nearly zero (up to float errors)
>>>         assert iou < 1e-5