1111from pydantic import validator
1212from pydantic .error_wrappers import ErrorWrapper
1313from pydantic .error_wrappers import ValidationError
14+ from superannotate_schemas .schemas .classes import AttributeGroup as AttributeGroupSchema
1415
1516NotEmptyStr = constr (strict = True , min_length = 1 )
1617
18+ AttributeGroup = AttributeGroupSchema
19+
1720
1821class AnnotationType (StrictStr ):
1922 @classmethod
@@ -25,160 +28,6 @@ def validate(cls, value: str) -> Union[str]:
2528 return value
2629
2730
28- class Attribute (BaseModel ):
29- name : NotEmptyStr
30-
31-
32- class AttributeGroup (BaseModel ):
33- name : StrictStr
34- is_multiselect : Optional [int ] = False
35- attributes : List [Attribute ]
36-
37-
38- class ClassesJson (BaseModel ):
39- name : StrictStr
40- color : StrictStr
41- attribute_groups : List [AttributeGroup ]
42-
43-
44- class Metadata (BaseModel ):
45- name : Optional [NotEmptyStr ]
46- width : Optional [int ]
47- height : Optional [int ]
48-
49-
50- class PointLabels (BaseModel ):
51- __root__ : Dict [constr (regex = r"^[0-9]+$" ), str ] # noqa: F722
52-
53-
54- class BaseInstance (BaseModel ):
55- type : AnnotationType
56- classId : Optional [int ]
57- groupId : Optional [int ]
58- attributes : List [Attribute ]
59- # point_labels: Optional[PointLabels]
60-
61- class Config :
62- error_msg_templates = {
63- "value_error.missing" : "field required for annotation" ,
64- }
65-
66-
67- class Point (BaseInstance ):
68- x : float
69- y : float
70-
71-
72- class PolyLine (BaseInstance ):
73- points : List [float ]
74-
75-
76- class Polygon (BaseInstance ):
77- points : List [float ]
78-
79-
80- class BboxPoints (BaseModel ):
81- x1 : float
82- x2 : float
83- y1 : float
84- y2 : float
85-
86-
87- class Bbox (BaseInstance ):
88- points : BboxPoints
89-
90-
91- class Ellipse (BaseInstance ):
92- cx : float
93- cy : float
94- rx : float
95- ry : float
96-
97-
98- class TemplatePoint (BaseModel ):
99- id : Optional [int ]
100- x : float
101- y : float
102-
103-
104- class TemplateConnection (BaseModel ):
105- id : Optional [int ]
106- to : int
107-
108-
109- class Template (BaseInstance ):
110- points : List [TemplatePoint ]
111- connections : List [Optional [TemplateConnection ]]
112- templateId : Optional [int ]
113-
114-
115- class EmptyPoint (BaseModel ):
116- x : float
117- y : float
118-
119-
120- class CuboidPoint (BaseModel ):
121- f1 : EmptyPoint
122- f2 : EmptyPoint
123- r1 : EmptyPoint
124- r2 : EmptyPoint
125-
126-
127- class Cuboid (BaseInstance ):
128- points : CuboidPoint
129-
130-
131- class PixelAnnotationPart (BaseModel ):
132- color : NotEmptyStr
133-
134-
135- class PixelAnnotationInstance (BaseModel ):
136- classId : Optional [int ]
137- groupId : Optional [int ]
138- parts : List [PixelAnnotationPart ]
139- attributes : List [Attribute ]
140-
141-
142- class VectorInstance (BaseModel ):
143- __root__ : Union [Template , Cuboid , Point , PolyLine , Polygon , Bbox , Ellipse ]
144-
145-
146- ANNOTATION_TYPES = {
147- "bbox" : Bbox ,
148- "ellipse" : Ellipse ,
149- "template" : Template ,
150- "cuboid" : Cuboid ,
151- "polyline" : PolyLine ,
152- "polygon" : Polygon ,
153- "point" : Point ,
154- }
155-
156-
157- class VectorAnnotation (BaseModel ):
158- metadata : Metadata
159- instances : Optional [
160- List [Union [Template , Cuboid , Point , PolyLine , Polygon , Bbox , Ellipse ]]
161- ]
162-
163- @validator ("instances" , pre = True , each_item = True )
164- def check_instances (cls , instance ):
165- annotation_type = AnnotationType .validate (instance .get ("type" ))
166- if not annotation_type :
167- raise ValidationError (
168- [ErrorWrapper (TypeError ("value not specified" ), "type" )], cls
169- )
170- result = validate_model (ANNOTATION_TYPES [annotation_type ], instance )
171- if result [2 ]:
172- raise ValidationError (
173- result [2 ].raw_errors , model = ANNOTATION_TYPES [annotation_type ]
174- )
175- return instance
176-
177-
178- class PixelAnnotation (BaseModel ):
179- metadata : Metadata
180- instances : List [PixelAnnotationInstance ]
181-
18231
18332class Project (BaseModel ):
18433 name : NotEmptyStr
@@ -198,40 +47,3 @@ class Config:
19847 extra = Extra .allow
19948
20049
201- class VideoMetaData (BaseModel ):
202- name : StrictStr
203- width : Optional [int ]
204- height : Optional [int ]
205- duration : Optional [int ]
206-
207-
208- class VideoInstanceMeta (BaseModel ):
209- type : NotEmptyStr
210- classId : Optional [int ]
211-
212-
213- class VideoTimeStamp (BaseModel ):
214- timestamp : int
215- attributes : List [Attribute ]
216-
217-
218- class VideoInstanceParameter (BaseModel ):
219- start : int
220- end : int
221- timestamps : List [VideoTimeStamp ]
222-
223-
224- class VideoInstance (BaseModel ):
225- meta : VideoInstanceMeta
226- parameters : List [VideoInstanceParameter ]
227-
228-
229- class VideoAnnotation (BaseModel ):
230- metadata : VideoMetaData
231- instances : Optional [List [VideoInstance ]]
232- tags : Optional [List [str ]]
233-
234-
235- class DocumentAnnotation (BaseModel ):
236- instances : list
237- tags : Optional [List [str ]]
0 commit comments