ndsampler.toydata

Module Contents

Classes

DynamicToySampler

Generates positive and negative samples on the fly.

class ndsampler.toydata.DynamicToySampler(n_positives=100000.0, seed=None, gsize=(416, 416), categories=None)

Bases: ndsampler.abstract_sampler.AbstractSampler

Generates positive and negative samples on the fly.

Note

Its probably more robust to generate a static fixed-size dataset with ‘demodata_toy_dset’ or kwcoco.CocoDataset.demo. However, if you need a sampler that dynamically generates toydata, this is for you.

Ignore:
>>> from ndsampler.toydata import *
>>> self = DynamicToySampler()
>>> window_dims = (96, 96)

img, anns = self.load_positive(window_dims=window_dims) kwplot.autompl() kwplot.imshow(img[‘imdata’])

img, anns = self.load_negative(window_dims=window_dims) kwplot.autompl() kwplot.imshow(img[‘imdata’])

CommandLine:

xdoctest -m ndsampler.toydata DynamicToySampler –show

Example

>>> # Test that this sampler works with the dataset
>>> from ndsampler.toydata import *
>>> self = DynamicToySampler(1e3)
>>> imgs = [self.load_positive()['im'] for _ in range(9)]
>>> # xdoctest: +REQUIRES(--show)
>>> stacked = kwimage.stack_images_grid(imgs, overlap=-10)
>>> import kwplot
>>> kwplot.autompl()
>>> kwplot.imshow(stacked)
>>> kwplot.show_if_requested()
property class_ids
property n_positives
abstract property n_annots
abstract property n_images
property n_categories
load_item(index, pad=None, window_dims=None)

Loads from positives and then negatives.

__len__()
_depends()
image_ids()
lookup_class_name(class_id)
lookup_class_id(class_name)
_lookup_kpnames(class_id)
preselect(n_pos=None, n_neg=None, neg_to_pos_ratio=None, window_dims=None, rng=None, verbose=0)

Setup a pool of training examples before the epoch begins

load_image(image_id=None, rng=None)
load_image_with_annots(image_id=None, rng=None)

Returns a random image and its annotations

abstract load_sample(tr, pad=None, window_dims=None)
_load_toy_sample(window_dims, pad, rng, centerobj, n_annots)
load_positive(index=None, pad=None, window_dims=None, rng=None)

Note: window_dims is height / width

Example

>>> from ndsampler.toydata import *
>>> self = DynamicToySampler(1e2)
>>> sample = self.load_positive()
>>> annots = sample['annots']
>>> assert len(annots['aids']) > 0
>>> assert len(annots['rel_cxywh']) == len(annots['aids'])
>>> # xdoc: +REQUIRES(--show)
>>> import kwplot
>>> kwplot.autompl()
>>> # Draw box in relative sample context
>>> kwplot.imshow(sample['im'], pnum=(1, 1, 1), fnum=1)
>>> annots['rel_boxes'].translate([-.5, -.5]).draw()
>>> annots['rel_ssegs'].draw(color='red', alpha=.6)
>>> annots['rel_kpts'].draw(color='green', alpha=.8, radius=4)
load_negative(index=None, pad=None, window_dims=None, rng=None)