ndsampler.toydata module¶
- class ndsampler.toydata.DynamicToySampler(n_positives=100000.0, seed=None, gsize=(416, 416), categories=None)[source]¶
Bases:
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.
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¶
- property n_annots¶
- property n_images¶
- property n_categories¶
- preselect(n_pos=None, n_neg=None, neg_to_pos_ratio=None, window_dims=None, rng=None, verbose=0)[source]¶
- load_positive(index=None, pad=None, window_dims=None, rng=None)[source]¶
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)