kwimage.structs._generic module

kwimage.structs._generic.isinstance_arraytypes(obj)[source]

workaround so we dont need to import torch at the global level

class kwimage.structs._generic.Spatial[source]

Bases: NiceRepr

Abstract base class defining the spatial annotation API

class kwimage.structs._generic.ObjectList(data, meta=None)[source]

Bases: Spatial

Stores a list of potentially heterogenous structures, each item usually corresponds to a different object.

property shape
property dtype
translate(offset, output_dims=None, inplace=False)[source]
scale(factor, output_dims=None, inplace=False)[source]
warp(transform, input_dims=None, output_dims=None, inplace=False)[source]
apply(func)[source]
to_coco(style='orig')[source]
compress(flags, axis=0)[source]
take(indices, axis=0)[source]
draw(**kwargs)[source]
draw_on(image, **kwargs)[source]

Todo

document fastdraw - it flattens all subobjects into the same layer and then does any alpha blending. Is there a better name?

tensor(device=NoParam)[source]
numpy()[source]
classmethod concatenate(items, axis=0)[source]
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

Return type:

ObjectList

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
is_tensor()[source]
is_numpy()[source]
kwimage.structs._generic._handle_perinstance_color_arg(selflen, instkw_list, kwargs, argname)[source]

helper to expand any color argument into multiple color arguments for each instance handled by the generic draw on method. This allows the user to specify a list of colors for each member, or a single color to be applied to everyone.

kwimage.structs._generic._coerce_color_list_for(image, color, num)[source]

Get a list of colors for each item

kwimage.structs._generic._consistent_dtype_fixer(data)[source]

helper for ensuring out.dtype == in.dtype

kwimage.structs._generic._safe_take(data, indices, axis)[source]
kwimage.structs._generic._safe_compress(data, flags, axis)[source]
kwimage.structs._generic._issubclass2(child, parent)[source]

Uses string comparisons to avoid ipython reload errors. Much less robust though.

kwimage.structs._generic._isinstance2(obj, cls)[source]

Uses string comparisons to avoid ipython reload errors. Much less robust though.

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)

)

kwimage.structs._generic._setlim(xmin, ymin, xmax, ymax, setlim=False, ax=None)[source]

Helper for setlim argument for draw function

kwimage.structs._generic._handle_color_args_for(color, alpha, border, fill, edgecolor, facecolor, image)[source]

Common logic for boxes and polygons