:py:mod:`kwimage.structs._generic` ================================== .. py:module:: kwimage.structs._generic Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: kwimage.structs._generic.Spatial kwimage.structs._generic.ObjectList Functions ~~~~~~~~~ .. autoapisummary:: kwimage.structs._generic._consistent_dtype_fixer kwimage.structs._generic._safe_take kwimage.structs._generic._safe_compress kwimage.structs._generic._issubclass2 kwimage.structs._generic._isinstance2 Attributes ~~~~~~~~~~ .. autoapisummary:: kwimage.structs._generic.torch .. py:data:: torch .. py:class:: Spatial Bases: :py:obj:`ubelt.NiceRepr` Abstract base class defining the spatial annotation API .. py:class:: ObjectList(data, meta=None) Bases: :py:obj:`Spatial` Stores a list of potentially heterogenous structures, each item usually corresponds to a different object. .. py:method:: __len__(self) .. py:method:: shape(self) :property: .. py:method:: dtype(self) :property: .. py:method:: __nice__(self) .. py:method:: __getitem__(self, index) .. py:method:: __iter__(self) .. py:method:: translate(self, offset, output_dims=None, inplace=False) .. py:method:: scale(self, factor, output_dims=None, inplace=False) .. py:method:: warp(self, transform, input_dims=None, output_dims=None, inplace=False) .. py:method:: apply(self, func) .. py:method:: to_coco(self, style='orig') .. py:method:: compress(self, flags, axis=0) .. py:method:: take(self, indices, axis=0) .. py:method:: draw(self, **kwargs) .. py:method:: draw_on(self, image, **kwargs) .. py:method:: tensor(self, device=ub.NoParam) .. py:method:: numpy(self) .. py:method:: concatenate(cls, items, axis=0) :classmethod: :Parameters: * **items** (*Sequence[ObjectList]*) -- multiple object lists of the same type * **axis** (*int | None*) -- unused, always implied to be axis 0 :returns: combined object list :rtype: ObjectList .. rubric:: Example >>> import kwimage >>> cls = kwimage.MaskList >>> sub_cls = kwimage.Mask >>> item1 = cls([sub_cls.random(), sub_cls.random()]) >>> item2 = cls([sub_cls.random()]) >>> items = [item1, item2] >>> new = cls.concatenate(items) >>> assert len(new) == 3 .. py:method:: is_tensor(cls) :abstractmethod: .. py:method:: is_numpy(cls) :abstractmethod: .. py:method:: random(cls) :classmethod: :abstractmethod: .. py:function:: _consistent_dtype_fixer(data) helper for ensuring out.dtype == in.dtype .. py:function:: _safe_take(data, indices, axis) .. py:function:: _safe_compress(data, flags, axis) .. py:function:: _issubclass2(child, parent) Uses string comparisons to avoid ipython reload errors. Much less robust though. .. py:function:: _isinstance2(obj, cls) Uses string comparisons to avoid ipython reload errors. Much less robust though. .. rubric:: Example import kwimage from kwimage.structs import _generic cls = kwimage.structs._generic.ObjectList obj = kwimage.MaskList([]) _generic._isinstance2(obj, cls) _generic._isinstance2(kwimage.MaskList([]), _generic.ObjectList) dets = kwimage.Detections( boxes=kwimage.Boxes.random(3).numpy(), class_idxs=[0, 1, 1], segmentations=kwimage.MaskList([None] * 3) )