cuvis_ai.data.cocolabels.Image
- class cuvis_ai.data.cocolabels.Image(id: int, file_name: str, height: int, width: int, license: Optional[int] = None, flickr_url: Optional[str] = None, coco_url: Optional[str] = None, date_captured: Optional[str] = None, wavelength: Optional[list[float]] = <factory>)[source]
Bases:
JSONSerializable
- __init__(id: int, file_name: str, height: int, width: int, license: int | None = None, flickr_url: str | None = None, coco_url: str | None = None, date_captured: str | None = None, wavelength: list[float] | None = <factory>) None
Methods
__init__
(id, file_name, height, width[, ...])from_dict
(d)Converts a Python dictionary object to a dataclass instance.
from_json
(string, *[, decoder])from_list
(list_of_dict)Converts a Python list object to a list of dataclass instances.
list_to_json
(instances[, encoder])to_dict
(*[, cls, dict_factory, exclude])Return the fields of a dataclass instance as a new dictionary mapping field names to field values.
to_json
(*[, encoder])Attributes
- class Meta
Bases:
BaseJSONWizardMeta
- all_fields = frozenset({'auto_assign_tags', 'debug_enabled', 'json_key_to_field', 'key_transform_with_dump', 'key_transform_with_load', 'marshal_date_time_as', 'raise_on_unknown_json_key', 'recursive', 'recursive_classes', 'skip_defaults', 'skip_defaults_if', 'skip_if', 'tag', 'tag_key', 'v1', 'v1_debug', 'v1_field_to_alias', 'v1_key_case', 'v1_on_unknown_key', 'v1_unsafe_parse_dataclass_in_union'})
- classmethod bind_to(dataclass: type, create=True, is_default=True, base_loader=None)
Initialize hook which applies the Meta config to dataclass, which is typically a subclass of
JSONWizard
.- Parameters:
dataclass – A class which has been decorated by the @dataclass decorator; typically this is a sub-class of
JSONWizard
.create – When true, a separate loader/dumper will be created for the class. If disabled, this will access the root loader/dumper, so modifying this should affect global settings across all dataclasses that use the JSON load/dump process.
is_default – When enabled, the Meta will be cached as the default Meta config for the dataclass. Defaults to true.
- debug_enabled: ClassVar['bool | int | str'] = False
- fields_to_merge = frozenset({'auto_assign_tags', 'debug_enabled', 'key_transform_with_dump', 'key_transform_with_load', 'marshal_date_time_as', 'raise_on_unknown_json_key', 'recursive_classes', 'skip_defaults', 'skip_defaults_if', 'skip_if', 'tag_key', 'v1', 'v1_debug', 'v1_key_case', 'v1_on_unknown_key', 'v1_unsafe_parse_dataclass_in_union'})
- skip_defaults_if: ClassVar[Condition] = None
- skip_if: ClassVar[Condition] = None
- v1_debug: ClassVar['bool | int | str'] = False
- v1_on_unknown_key: ClassVar[KeyAction] = None
- classmethod from_dict(d: dict[str, Any]) T
Converts a Python dictionary object to a dataclass instance.
Iterates over each dataclass field recursively; lists, dicts, and nested dataclasses will likewise be initialized as expected.
When directly invoking this function, an optional Meta configuration for the dataclass can be specified via
LoadMeta
; by default, this will apply recursively to any nested dataclasses. Here’s a sample usage of this below:>>> LoadMeta(key_transform='CAMEL').bind_to(MyClass) >>> fromdict(MyClass, {"myStr": "value"})
- classmethod from_json(string, *, decoder=<function loads>, **decoder_kwargs)
- classmethod from_list(list_of_dict: list[dict[str, Any]]) list[T]
Converts a Python list object to a list of dataclass instances.
Iterates over each dataclass field recursively; lists, dicts, and nested dataclasses will likewise be initialized as expected.
- classmethod list_to_json(instances, encoder=<function dumps>, **encoder_kwargs)
- to_dict(*, cls=None, dict_factory=<class 'dict'>, exclude: ~typing.Collection[str] | None = None, **kwargs) dict[str, Any]
Return the fields of a dataclass instance as a new dictionary mapping field names to field values.
Example usage:
@dataclass class C:
x: int y: int
c = C(1, 2) assert asdict(c) == {‘x’: 1, ‘y’: 2}
When directly invoking this function, an optional Meta configuration for the dataclass can be specified via
DumpMeta
; by default, this will apply recursively to any nested dataclasses. Here’s a sample usage of this below:>>> DumpMeta(key_transform='CAMEL').bind_to(MyClass) >>> asdict(MyClass(my_str="value"))
If given, ‘dict_factory’ will be used instead of built-in dict. The function applies recursively to field values that are dataclass instances. This will also look into built-in containers: tuples, lists, and dicts.
- to_json(*, encoder=<function dumps>, **encoder_kwargs)