denkproto 1.0.91__py3-none-any.whl → 1.0.93__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of denkproto might be problematic. Click here for more details.

@@ -0,0 +1,510 @@
1
+ from uuid import UUID
2
+ from typing import Any, Dict, List, Optional, TypeVar, Callable, Type, cast
3
+ from enum import Enum
4
+
5
+
6
+ T = TypeVar("T")
7
+ EnumT = TypeVar("EnumT", bound=Enum)
8
+
9
+
10
+ def from_int(x: Any) -> int:
11
+ assert isinstance(x, int) and not isinstance(x, bool)
12
+ return x
13
+
14
+
15
+ def from_dict(f: Callable[[Any], T], x: Any) -> Dict[str, T]:
16
+ assert isinstance(x, dict)
17
+ return { k: f(v) for (k, v) in x.items() }
18
+
19
+
20
+ def from_bool(x: Any) -> bool:
21
+ assert isinstance(x, bool)
22
+ return x
23
+
24
+
25
+ def from_str(x: Any) -> str:
26
+ assert isinstance(x, str)
27
+ return x
28
+
29
+
30
+ def to_class(c: Type[T], x: Any) -> dict:
31
+ assert isinstance(x, c)
32
+ return cast(Any, x).to_dict()
33
+
34
+
35
+ def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
36
+ assert isinstance(x, list)
37
+ return [f(y) for y in x]
38
+
39
+
40
+ def from_float(x: Any) -> float:
41
+ assert isinstance(x, (float, int)) and not isinstance(x, bool)
42
+ return float(x)
43
+
44
+
45
+ def from_none(x: Any) -> Any:
46
+ assert x is None
47
+ return x
48
+
49
+
50
+ def from_union(fs, x):
51
+ for f in fs:
52
+ try:
53
+ return f(x)
54
+ except:
55
+ pass
56
+ assert False
57
+
58
+
59
+ def to_float(x: Any) -> float:
60
+ assert isinstance(x, (int, float))
61
+ return x
62
+
63
+
64
+ def to_enum(c: Type[EnumT], x: Any) -> EnumT:
65
+ assert isinstance(x, c)
66
+ return x.value
67
+
68
+
69
+ class Image:
70
+ blob_id: UUID
71
+ height: int
72
+ owned_by_group_id: UUID
73
+ width: int
74
+
75
+ def __init__(self, blob_id: UUID, height: int, owned_by_group_id: UUID, width: int) -> None:
76
+ self.blob_id = blob_id
77
+ self.height = height
78
+ self.owned_by_group_id = owned_by_group_id
79
+ self.width = width
80
+
81
+ @staticmethod
82
+ def from_dict(obj: Any) -> 'Image':
83
+ assert isinstance(obj, dict)
84
+ blob_id = UUID(obj.get("blob_id"))
85
+ height = from_int(obj.get("height"))
86
+ owned_by_group_id = UUID(obj.get("owned_by_group_id"))
87
+ width = from_int(obj.get("width"))
88
+ return Image(blob_id, height, owned_by_group_id, width)
89
+
90
+ def to_dict(self) -> dict:
91
+ result: dict = {}
92
+ result["blob_id"] = str(self.blob_id)
93
+ result["height"] = from_int(self.height)
94
+ result["owned_by_group_id"] = str(self.owned_by_group_id)
95
+ result["width"] = from_int(self.width)
96
+ return result
97
+
98
+
99
+ class ClassLabel:
100
+ id: UUID
101
+ idx: int
102
+
103
+ def __init__(self, id: UUID, idx: int) -> None:
104
+ self.id = id
105
+ self.idx = idx
106
+
107
+ @staticmethod
108
+ def from_dict(obj: Any) -> 'ClassLabel':
109
+ assert isinstance(obj, dict)
110
+ id = UUID(obj.get("id"))
111
+ idx = from_int(obj.get("idx"))
112
+ return ClassLabel(id, idx)
113
+
114
+ def to_dict(self) -> dict:
115
+ result: dict = {}
116
+ result["id"] = str(self.id)
117
+ result["idx"] = from_int(self.idx)
118
+ return result
119
+
120
+
121
+ class Config:
122
+ metadata: Dict[str, Any]
123
+ uses_validation_tiling: bool
124
+
125
+ def __init__(self, metadata: Dict[str, Any], uses_validation_tiling: bool) -> None:
126
+ self.metadata = metadata
127
+ self.uses_validation_tiling = uses_validation_tiling
128
+
129
+ @staticmethod
130
+ def from_dict(obj: Any) -> 'Config':
131
+ assert isinstance(obj, dict)
132
+ metadata = from_dict(lambda x: x, obj.get("metadata"))
133
+ uses_validation_tiling = from_bool(obj.get("uses_validation_tiling"))
134
+ return Config(metadata, uses_validation_tiling)
135
+
136
+ def to_dict(self) -> dict:
137
+ result: dict = {}
138
+ result["metadata"] = from_dict(lambda x: x, self.metadata)
139
+ result["uses_validation_tiling"] = from_bool(self.uses_validation_tiling)
140
+ return result
141
+
142
+
143
+ class OcrCharacterRestrictionPreset:
144
+ characters: str
145
+ value: str
146
+
147
+ def __init__(self, characters: str, value: str) -> None:
148
+ self.characters = characters
149
+ self.value = value
150
+
151
+ @staticmethod
152
+ def from_dict(obj: Any) -> 'OcrCharacterRestrictionPreset':
153
+ assert isinstance(obj, dict)
154
+ characters = from_str(obj.get("characters"))
155
+ value = from_str(obj.get("value"))
156
+ return OcrCharacterRestrictionPreset(characters, value)
157
+
158
+ def to_dict(self) -> dict:
159
+ result: dict = {}
160
+ result["characters"] = from_str(self.characters)
161
+ result["value"] = from_str(self.value)
162
+ return result
163
+
164
+
165
+ class OcrCharacterRestriction:
166
+ allowed_characters: str
167
+ index: int
168
+ number_of_characters: int
169
+ ocr_character_restriction_preset: OcrCharacterRestrictionPreset
170
+
171
+ def __init__(self, allowed_characters: str, index: int, number_of_characters: int, ocr_character_restriction_preset: OcrCharacterRestrictionPreset) -> None:
172
+ self.allowed_characters = allowed_characters
173
+ self.index = index
174
+ self.number_of_characters = number_of_characters
175
+ self.ocr_character_restriction_preset = ocr_character_restriction_preset
176
+
177
+ @staticmethod
178
+ def from_dict(obj: Any) -> 'OcrCharacterRestriction':
179
+ assert isinstance(obj, dict)
180
+ allowed_characters = from_str(obj.get("allowed_characters"))
181
+ index = from_int(obj.get("index"))
182
+ number_of_characters = from_int(obj.get("number_of_characters"))
183
+ ocr_character_restriction_preset = OcrCharacterRestrictionPreset.from_dict(obj.get("ocr_character_restriction_preset"))
184
+ return OcrCharacterRestriction(allowed_characters, index, number_of_characters, ocr_character_restriction_preset)
185
+
186
+ def to_dict(self) -> dict:
187
+ result: dict = {}
188
+ result["allowed_characters"] = from_str(self.allowed_characters)
189
+ result["index"] = from_int(self.index)
190
+ result["number_of_characters"] = from_int(self.number_of_characters)
191
+ result["ocr_character_restriction_preset"] = to_class(OcrCharacterRestrictionPreset, self.ocr_character_restriction_preset)
192
+ return result
193
+
194
+
195
+ class Onnx:
196
+ blob_id: UUID
197
+ owned_by_group_id: UUID
198
+
199
+ def __init__(self, blob_id: UUID, owned_by_group_id: UUID) -> None:
200
+ self.blob_id = blob_id
201
+ self.owned_by_group_id = owned_by_group_id
202
+
203
+ @staticmethod
204
+ def from_dict(obj: Any) -> 'Onnx':
205
+ assert isinstance(obj, dict)
206
+ blob_id = UUID(obj.get("blob_id"))
207
+ owned_by_group_id = UUID(obj.get("owned_by_group_id"))
208
+ return Onnx(blob_id, owned_by_group_id)
209
+
210
+ def to_dict(self) -> dict:
211
+ result: dict = {}
212
+ result["blob_id"] = str(self.blob_id)
213
+ result["owned_by_group_id"] = str(self.owned_by_group_id)
214
+ return result
215
+
216
+
217
+ class Pytorch:
218
+ blob_id: UUID
219
+ owned_by_group_id: UUID
220
+
221
+ def __init__(self, blob_id: UUID, owned_by_group_id: UUID) -> None:
222
+ self.blob_id = blob_id
223
+ self.owned_by_group_id = owned_by_group_id
224
+
225
+ @staticmethod
226
+ def from_dict(obj: Any) -> 'Pytorch':
227
+ assert isinstance(obj, dict)
228
+ blob_id = UUID(obj.get("blob_id"))
229
+ owned_by_group_id = UUID(obj.get("owned_by_group_id"))
230
+ return Pytorch(blob_id, owned_by_group_id)
231
+
232
+ def to_dict(self) -> dict:
233
+ result: dict = {}
234
+ result["blob_id"] = str(self.blob_id)
235
+ result["owned_by_group_id"] = str(self.owned_by_group_id)
236
+ return result
237
+
238
+
239
+ class Snapshot:
240
+ onnx: Onnx
241
+ pytorch: Pytorch
242
+
243
+ def __init__(self, onnx: Onnx, pytorch: Pytorch) -> None:
244
+ self.onnx = onnx
245
+ self.pytorch = pytorch
246
+
247
+ @staticmethod
248
+ def from_dict(obj: Any) -> 'Snapshot':
249
+ assert isinstance(obj, dict)
250
+ onnx = Onnx.from_dict(obj.get("onnx"))
251
+ pytorch = Pytorch.from_dict(obj.get("pytorch"))
252
+ return Snapshot(onnx, pytorch)
253
+
254
+ def to_dict(self) -> dict:
255
+ result: dict = {}
256
+ result["onnx"] = to_class(Onnx, self.onnx)
257
+ result["pytorch"] = to_class(Pytorch, self.pytorch)
258
+ return result
259
+
260
+
261
+ class NetworkExperiment:
262
+ class_labels: List[ClassLabel]
263
+ config: Config
264
+ flavor: str
265
+ network_typename: str
266
+ ocr_character_restrictions: List[OcrCharacterRestriction]
267
+ snapshot: Snapshot
268
+
269
+ def __init__(self, class_labels: List[ClassLabel], config: Config, flavor: str, network_typename: str, ocr_character_restrictions: List[OcrCharacterRestriction], snapshot: Snapshot) -> None:
270
+ self.class_labels = class_labels
271
+ self.config = config
272
+ self.flavor = flavor
273
+ self.network_typename = network_typename
274
+ self.ocr_character_restrictions = ocr_character_restrictions
275
+ self.snapshot = snapshot
276
+
277
+ @staticmethod
278
+ def from_dict(obj: Any) -> 'NetworkExperiment':
279
+ assert isinstance(obj, dict)
280
+ class_labels = from_list(ClassLabel.from_dict, obj.get("class_labels"))
281
+ config = Config.from_dict(obj.get("config"))
282
+ flavor = from_str(obj.get("flavor"))
283
+ network_typename = from_str(obj.get("network_typename"))
284
+ ocr_character_restrictions = from_list(OcrCharacterRestriction.from_dict, obj.get("ocr_character_restrictions"))
285
+ snapshot = Snapshot.from_dict(obj.get("snapshot"))
286
+ return NetworkExperiment(class_labels, config, flavor, network_typename, ocr_character_restrictions, snapshot)
287
+
288
+ def to_dict(self) -> dict:
289
+ result: dict = {}
290
+ result["class_labels"] = from_list(lambda x: to_class(ClassLabel, x), self.class_labels)
291
+ result["config"] = to_class(Config, self.config)
292
+ result["flavor"] = from_str(self.flavor)
293
+ result["network_typename"] = from_str(self.network_typename)
294
+ result["ocr_character_restrictions"] = from_list(lambda x: to_class(OcrCharacterRestriction, x), self.ocr_character_restrictions)
295
+ result["snapshot"] = to_class(Snapshot, self.snapshot)
296
+ return result
297
+
298
+
299
+ class AnnotationType(Enum):
300
+ IGNORE = "IGNORE"
301
+ NEGATIVE = "NEGATIVE"
302
+ POSITIVE = "POSITIVE"
303
+ ROI = "ROI"
304
+
305
+
306
+ class BoundingBox:
307
+ angle: Optional[float]
308
+ bottom_right_x: float
309
+ bottom_right_y: float
310
+ full_orientation: Optional[bool]
311
+ top_left_x: float
312
+ top_left_y: float
313
+
314
+ def __init__(self, angle: Optional[float], bottom_right_x: float, bottom_right_y: float, full_orientation: Optional[bool], top_left_x: float, top_left_y: float) -> None:
315
+ self.angle = angle
316
+ self.bottom_right_x = bottom_right_x
317
+ self.bottom_right_y = bottom_right_y
318
+ self.full_orientation = full_orientation
319
+ self.top_left_x = top_left_x
320
+ self.top_left_y = top_left_y
321
+
322
+ @staticmethod
323
+ def from_dict(obj: Any) -> 'BoundingBox':
324
+ assert isinstance(obj, dict)
325
+ angle = from_union([from_float, from_none], obj.get("angle"))
326
+ bottom_right_x = from_float(obj.get("bottom_right_x"))
327
+ bottom_right_y = from_float(obj.get("bottom_right_y"))
328
+ full_orientation = from_union([from_bool, from_none], obj.get("full_orientation"))
329
+ top_left_x = from_float(obj.get("top_left_x"))
330
+ top_left_y = from_float(obj.get("top_left_y"))
331
+ return BoundingBox(angle, bottom_right_x, bottom_right_y, full_orientation, top_left_x, top_left_y)
332
+
333
+ def to_dict(self) -> dict:
334
+ result: dict = {}
335
+ if self.angle is not None:
336
+ result["angle"] = from_union([to_float, from_none], self.angle)
337
+ result["bottom_right_x"] = to_float(self.bottom_right_x)
338
+ result["bottom_right_y"] = to_float(self.bottom_right_y)
339
+ if self.full_orientation is not None:
340
+ result["full_orientation"] = from_union([from_bool, from_none], self.full_orientation)
341
+ result["top_left_x"] = to_float(self.top_left_x)
342
+ result["top_left_y"] = to_float(self.top_left_y)
343
+ return result
344
+
345
+
346
+ class Point:
347
+ x: float
348
+ y: float
349
+
350
+ def __init__(self, x: float, y: float) -> None:
351
+ self.x = x
352
+ self.y = y
353
+
354
+ @staticmethod
355
+ def from_dict(obj: Any) -> 'Point':
356
+ assert isinstance(obj, dict)
357
+ x = from_float(obj.get("x"))
358
+ y = from_float(obj.get("y"))
359
+ return Point(x, y)
360
+
361
+ def to_dict(self) -> dict:
362
+ result: dict = {}
363
+ result["x"] = to_float(self.x)
364
+ result["y"] = to_float(self.y)
365
+ return result
366
+
367
+
368
+ class OcrPredictionRequestSchema:
369
+ """A single closed loop (ring) of a polygon, defining either an outer boundary or a hole."""
370
+
371
+ hierarchy: int
372
+ """Nesting level: 0=outer, 1=hole in level 0, 2=poly in level 1 hole, etc. Even levels are
373
+ filled areas, odd levels are holes.
374
+ """
375
+ points: List[Point]
376
+ """Vertices of the ring."""
377
+
378
+ def __init__(self, hierarchy: int, points: List[Point]) -> None:
379
+ self.hierarchy = hierarchy
380
+ self.points = points
381
+
382
+ @staticmethod
383
+ def from_dict(obj: Any) -> 'OcrPredictionRequestSchema':
384
+ assert isinstance(obj, dict)
385
+ hierarchy = from_int(obj.get("hierarchy"))
386
+ points = from_list(Point.from_dict, obj.get("points"))
387
+ return OcrPredictionRequestSchema(hierarchy, points)
388
+
389
+ def to_dict(self) -> dict:
390
+ result: dict = {}
391
+ result["hierarchy"] = from_int(self.hierarchy)
392
+ result["points"] = from_list(lambda x: to_class(Point, x), self.points)
393
+ return result
394
+
395
+
396
+ class Polygon:
397
+ """A polygon defined by one or more rings, allowing for holes and nested structures."""
398
+
399
+ rings: List[OcrPredictionRequestSchema]
400
+ """Array of polygon rings. The hierarchy field within each ring determines nesting and
401
+ fill/hole status.
402
+ """
403
+
404
+ def __init__(self, rings: List[OcrPredictionRequestSchema]) -> None:
405
+ self.rings = rings
406
+
407
+ @staticmethod
408
+ def from_dict(obj: Any) -> 'Polygon':
409
+ assert isinstance(obj, dict)
410
+ rings = from_list(OcrPredictionRequestSchema.from_dict, obj.get("rings"))
411
+ return Polygon(rings)
412
+
413
+ def to_dict(self) -> dict:
414
+ result: dict = {}
415
+ result["rings"] = from_list(lambda x: to_class(OcrPredictionRequestSchema, x), self.rings)
416
+ return result
417
+
418
+
419
+ class Object:
420
+ annotation_type: AnnotationType
421
+ average_width: float
422
+ bounding_box: Optional[BoundingBox]
423
+ id: UUID
424
+ label_id: UUID
425
+ polygon: Optional[Polygon]
426
+
427
+ def __init__(self, annotation_type: AnnotationType, average_width: float, bounding_box: Optional[BoundingBox], id: UUID, label_id: UUID, polygon: Optional[Polygon]) -> None:
428
+ self.annotation_type = annotation_type
429
+ self.average_width = average_width
430
+ self.bounding_box = bounding_box
431
+ self.id = id
432
+ self.label_id = label_id
433
+ self.polygon = polygon
434
+
435
+ @staticmethod
436
+ def from_dict(obj: Any) -> 'Object':
437
+ assert isinstance(obj, dict)
438
+ annotation_type = AnnotationType(obj.get("annotation_type"))
439
+ average_width = from_float(obj.get("average_width"))
440
+ bounding_box = from_union([BoundingBox.from_dict, from_none], obj.get("bounding_box"))
441
+ id = UUID(obj.get("id"))
442
+ label_id = UUID(obj.get("label_id"))
443
+ polygon = from_union([Polygon.from_dict, from_none], obj.get("polygon"))
444
+ return Object(annotation_type, average_width, bounding_box, id, label_id, polygon)
445
+
446
+ def to_dict(self) -> dict:
447
+ result: dict = {}
448
+ result["annotation_type"] = to_enum(AnnotationType, self.annotation_type)
449
+ result["average_width"] = to_float(self.average_width)
450
+ if self.bounding_box is not None:
451
+ result["bounding_box"] = from_union([lambda x: to_class(BoundingBox, x), from_none], self.bounding_box)
452
+ result["id"] = str(self.id)
453
+ result["label_id"] = str(self.label_id)
454
+ if self.polygon is not None:
455
+ result["polygon"] = from_union([lambda x: to_class(Polygon, x), from_none], self.polygon)
456
+ return result
457
+
458
+
459
+ class OcrPredictionRequest:
460
+ created_by_user_id: UUID
461
+ hasura_url: str
462
+ id: UUID
463
+ image: Image
464
+ network_experiment: NetworkExperiment
465
+ objects: List[Object]
466
+ owned_by_group_id: UUID
467
+ prediction_priority: int
468
+
469
+ def __init__(self, created_by_user_id: UUID, hasura_url: str, id: UUID, image: Image, network_experiment: NetworkExperiment, objects: List[Object], owned_by_group_id: UUID, prediction_priority: int) -> None:
470
+ self.created_by_user_id = created_by_user_id
471
+ self.hasura_url = hasura_url
472
+ self.id = id
473
+ self.image = image
474
+ self.network_experiment = network_experiment
475
+ self.objects = objects
476
+ self.owned_by_group_id = owned_by_group_id
477
+ self.prediction_priority = prediction_priority
478
+
479
+ @staticmethod
480
+ def from_dict(obj: Any) -> 'OcrPredictionRequest':
481
+ assert isinstance(obj, dict)
482
+ created_by_user_id = UUID(obj.get("created_by_user_id"))
483
+ hasura_url = from_str(obj.get("hasura_url"))
484
+ id = UUID(obj.get("id"))
485
+ image = Image.from_dict(obj.get("image"))
486
+ network_experiment = NetworkExperiment.from_dict(obj.get("network_experiment"))
487
+ objects = from_list(Object.from_dict, obj.get("objects"))
488
+ owned_by_group_id = UUID(obj.get("owned_by_group_id"))
489
+ prediction_priority = from_int(obj.get("prediction_priority"))
490
+ return OcrPredictionRequest(created_by_user_id, hasura_url, id, image, network_experiment, objects, owned_by_group_id, prediction_priority)
491
+
492
+ def to_dict(self) -> dict:
493
+ result: dict = {}
494
+ result["created_by_user_id"] = str(self.created_by_user_id)
495
+ result["hasura_url"] = from_str(self.hasura_url)
496
+ result["id"] = str(self.id)
497
+ result["image"] = to_class(Image, self.image)
498
+ result["network_experiment"] = to_class(NetworkExperiment, self.network_experiment)
499
+ result["objects"] = from_list(lambda x: to_class(Object, x), self.objects)
500
+ result["owned_by_group_id"] = str(self.owned_by_group_id)
501
+ result["prediction_priority"] = from_int(self.prediction_priority)
502
+ return result
503
+
504
+
505
+ def ocr_prediction_request_from_dict(s: Any) -> OcrPredictionRequest:
506
+ return OcrPredictionRequest.from_dict(s)
507
+
508
+
509
+ def ocr_prediction_request_to_dict(x: OcrPredictionRequest) -> Any:
510
+ return to_class(OcrPredictionRequest, x)