:py:mod:`kwcoco.demo.toydata_image` =================================== .. py:module:: kwcoco.demo.toydata_image .. autoapi-nested-parse:: Generates "toydata" for demo and testing purposes. Loose image version of the toydata generators. .. note:: The implementation of `demodata_toy_img` and `demodata_toy_dset` should be redone using the tools built for `random_video_dset`, which have more extensible implementations. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: kwcoco.demo.toydata_image.demodata_toy_dset kwcoco.demo.toydata_image.demodata_toy_img Attributes ~~~~~~~~~~ .. autoapisummary:: kwcoco.demo.toydata_image.profile kwcoco.demo.toydata_image.TOYDATA_IMAGE_VERSION .. py:data:: profile .. py:data:: TOYDATA_IMAGE_VERSION :annotation: = 20 .. py:function:: demodata_toy_dset(image_size=(600, 600), n_imgs=5, verbose=3, rng=0, newstyle=True, dpath=None, bundle_dpath=None, aux=None, use_cache=True, **kwargs) Create a toy detection problem :Parameters: * **image_size** (*Tuple[int, int]*) -- The width and height of the generated images * **n_imgs** (*int*) -- number of images to generate * **rng** (*int | RandomState, default=0*) -- random number generator or seed * **newstyle** (*bool, default=True*) -- create newstyle kwcoco data * **dpath** (*str*) -- path to the directory that will contain the bundle, (defaults to a kwcoco cache dir). Ignored if `bundle_dpath` is given. * **bundle_dpath** (*str*) -- path to the directory that will store images. If specified, dpath is ignored. If unspecified, a bundle will be written inside `dpath`. * **aux** (*bool*) -- if True generates dummy auxiliary channels * **verbose** (*int, default=3*) -- verbosity mode * **use_cache** (*bool, default=True*) -- if True caches the generated json in the `dpath`. * **\*\*kwargs** -- used for old backwards compatible argument names gsize - alias for image_size :rtype: kwcoco.CocoDataset SeeAlso: random_video_dset .. rubric:: CommandLine .. code-block:: bash xdoctest -m kwcoco.demo.toydata_image demodata_toy_dset --show .. todo:: - [ ] Non-homogeneous images sizes .. rubric:: Example >>> from kwcoco.demo.toydata_image import * >>> import kwcoco >>> dset = demodata_toy_dset(image_size=(300, 300), aux=True, use_cache=False) >>> # xdoctest: +REQUIRES(--show) >>> print(ub.repr2(dset.dataset, nl=2)) >>> import kwplot >>> kwplot.autompl() >>> dset.show_image(gid=1) >>> ub.startfile(dset.bundle_dpath) dset._tree() >>> from kwcoco.demo.toydata_image import * >>> import kwcoco dset = demodata_toy_dset(image_size=(300, 300), aux=True, use_cache=False) print(dset.imgs[1]) dset._tree() dset = demodata_toy_dset(image_size=(300, 300), aux=True, use_cache=False, bundle_dpath='test_bundle') print(dset.imgs[1]) dset._tree() dset = demodata_toy_dset( image_size=(300, 300), aux=True, use_cache=False, dpath='test_cache_dpath') .. py:function:: demodata_toy_img(anchors=None, image_size=(104, 104), categories=None, n_annots=(0, 50), fg_scale=0.5, bg_scale=0.8, bg_intensity=0.1, fg_intensity=0.9, gray=True, centerobj=None, exact=False, newstyle=True, rng=None, aux=None, **kwargs) Generate a single image with non-overlapping toy objects of available categories. .. todo:: DEPRECATE IN FAVOR OF random_single_video_dset + render_toy_image :Parameters: * **anchors** (*ndarray*) -- Nx2 base width / height of boxes * **gsize** (*Tuple[int, int]*) -- width / height of the image * **categories** (*List[str]*) -- list of category names * **n_annots** (*Tuple | int*) -- controls how many annotations are in the image. if it is a tuple, then it is interpreted as uniform random bounds * **fg_scale** (*float*) -- standard deviation of foreground intensity * **bg_scale** (*float*) -- standard deviation of background intensity * **bg_intensity** (*float*) -- mean of background intensity * **fg_intensity** (*float*) -- mean of foreground intensity * **centerobj** (*bool*) -- if 'pos', then the first annotation will be in the center of the image, if 'neg', then no annotations will be in the center. * **exact** (*bool*) -- if True, ensures that exactly the number of specified annots are generated. * **newstyle** (*bool*) -- use new-sytle kwcoco format * **rng** (*RandomState*) -- the random state used to seed the process * **aux** -- if specified builds auxiliary channels * **\*\*kwargs** -- used for old backwards compatible argument names. gsize - alias for image_size .. rubric:: CommandLine .. code-block:: bash xdoctest -m kwcoco.demo.toydata_image demodata_toy_img:0 --profile xdoctest -m kwcoco.demo.toydata_image demodata_toy_img:1 --show .. rubric:: Example >>> from kwcoco.demo.toydata_image import * # NOQA >>> img, anns = demodata_toy_img(image_size=(32, 32), anchors=[[.3, .3]], rng=0) >>> img['imdata'] = ''.format(img['imdata'].shape) >>> print('img = {}'.format(ub.repr2(img))) >>> print('anns = {}'.format(ub.repr2(anns, nl=2, cbr=True))) >>> # xdoctest: +IGNORE_WANT img = { 'height': 32, 'imdata': '', 'width': 32, } anns = [{'bbox': [15, 10, 9, 8], 'category_name': 'star', 'keypoints': [], 'segmentation': {'counts': '[`06j0000O20N1000e8', 'size': [32, 32]},}, {'bbox': [11, 20, 7, 7], 'category_name': 'star', 'keypoints': [], 'segmentation': {'counts': 'g;1m04N0O20N102L[=', 'size': [32, 32]},}, {'bbox': [4, 4, 8, 6], 'category_name': 'superstar', 'keypoints': [{'keypoint_category': 'left_eye', 'xy': [7.25, 6.8125]}, {'keypoint_category': 'right_eye', 'xy': [8.75, 6.8125]}], 'segmentation': {'counts': 'U4210j0300O01010O00MVO0ed0', 'size': [32, 32]},}, {'bbox': [3, 20, 6, 7], 'category_name': 'star', 'keypoints': [], 'segmentation': {'counts': 'g31m04N000002L[f0', 'size': [32, 32]},},] .. rubric:: Example >>> # xdoctest: +REQUIRES(--show) >>> img, anns = demodata_toy_img(image_size=(172, 172), rng=None, aux=True) >>> print('anns = {}'.format(ub.repr2(anns, nl=1))) >>> import kwplot >>> kwplot.autompl() >>> kwplot.imshow(img['imdata'], pnum=(1, 2, 1), fnum=1) >>> auxdata = img['auxiliary'][0]['imdata'] >>> kwplot.imshow(auxdata, pnum=(1, 2, 2), fnum=1) >>> kwplot.show_if_requested() .. rubric:: Example >>> # xdoctest: +REQUIRES(--show) >>> img, anns = demodata_toy_img(image_size=(172, 172), rng=None, aux=True) >>> print('anns = {}'.format(ub.repr2(anns, nl=1))) >>> import kwplot >>> kwplot.autompl() >>> kwplot.imshow(img['imdata'], pnum=(1, 2, 1), fnum=1) >>> auxdata = img['auxiliary'][0]['imdata'] >>> kwplot.imshow(auxdata, pnum=(1, 2, 2), fnum=1) >>> kwplot.show_if_requested()