@@ -39,7 +39,6 @@ def to_common(self):
3939 # Labelbox doesn't support subclasses on image level classifications
4040 # These are added to top level classifications
4141 classifications = [],
42- #keyframe = classification.keyframe,
4342 frame = self .frame_number ,
4443 name = classification .title )
4544 for classification in self .classifications
@@ -58,7 +57,7 @@ def to_common(self):
5857 'feature_id' : cls .feature_id ,
5958 'title' : cls .title ,
6059 'value' : cls .value ,
61- 'keyframe' : getattr (cls , 'keyframe' , None )
60+ # 'keyframe': getattr(cls, 'keyframe', None)
6261 }) for cls in obj .classifications
6362 ],
6463 name = obj .title ,
@@ -111,76 +110,63 @@ class LBV1Label(BaseModel):
111110 data_row_id : str = Field (..., alias = "DataRow ID" )
112111 row_data : str = Field (..., alias = "Labeled Data" )
113112 external_id : Optional [str ] = Field (None , alias = "External ID" )
114- created_by : Optional [str ] = Field (None , alias = 'Created By' )
115-
116- id : Optional [str ] = Field (None , alias = 'ID' )
117- project_name : Optional [str ] = Field (None , alias = 'Project Name' )
118- created_at : Optional [str ] = Field (None , alias = 'Created At' )
119- updated_at : Optional [str ] = Field (None , alias = 'Updated At' )
120- seconds_to_label : Optional [float ] = Field (None , alias = 'Seconds to Label' )
121- agreement : Optional [float ] = Field (None , alias = 'Agreement' )
122- benchmark_agreement : Optional [float ] = Field (None ,
123- alias = 'Benchmark Agreement' )
124- benchmark_id : Optional [float ] = Field (None , alias = 'Benchmark ID' )
125- dataset_name : Optional [str ] = Field (None , alias = 'Dataset Name' )
126- reviews : Optional [List [Review ]] = Field (None , alias = 'Reviews' )
127- label_url : Optional [str ] = Field (None , alias = 'View Label' )
128- has_open_issues : Optional [float ] = Field (None , alias = 'Has Open Issues' )
129- skipped : Optional [bool ] = Field (None , alias = 'Skipped' )
130-
131- def construct_data_ref (self , is_video ):
132- # TODO: Let users specify the type ...
133- keys = {'external_id' : self .external_id , 'uid' : self .data_row_id }
134113
135- if is_video :
136- return VideoData (url = self .row_data , ** keys )
137- if any ([x in self .row_data for x in (".jpg" , ".png" , ".jpeg" )
138- ]) and self .row_data .startswith (("http://" , "https://" )):
139- return RasterData (url = self .row_data , ** keys )
140- elif any ([x in self .row_data for x in (".txt" , ".text" , ".html" )
141- ]) and self .row_data .startswith (("http://" , "https://" )):
142- return TextData (url = self .row_data , ** keys )
143- elif isinstance (self .row_data , str ):
144- return TextData (text = self .row_data , ** keys )
145- elif len ([
146- annotation for annotation in self .label .objects
147- if isinstance (annotation , TextEntity )
148- ]):
149- return TextData (url = self .row_data , ** keys )
150- else :
151- raise TypeError ("Can't infer data type from row data." )
114+ created_by : Optional [str ] = Field (None ,
115+ alias = 'Created By' ,
116+ extra_field = True )
117+ project_name : Optional [str ] = Field (None ,
118+ alias = 'Project Name' ,
119+ extra_field = True )
120+ id : Optional [str ] = Field (None , alias = 'ID' , extra_field = True )
121+ created_at : Optional [str ] = Field (None ,
122+ alias = 'Created At' ,
123+ extra_field = True )
124+ updated_at : Optional [str ] = Field (None ,
125+ alias = 'Updated At' ,
126+ extra_field = True )
127+ seconds_to_label : Optional [float ] = Field (None ,
128+ alias = 'Seconds to Label' ,
129+ extra_field = True )
130+ agreement : Optional [float ] = Field (None ,
131+ alias = 'Agreement' ,
132+ extra_field = True )
133+ benchmark_agreement : Optional [float ] = Field (None ,
134+ alias = 'Benchmark Agreement' ,
135+ extra_field = True )
136+ benchmark_id : Optional [float ] = Field (None ,
137+ alias = 'Benchmark ID' ,
138+ extra_field = True )
139+ dataset_name : Optional [str ] = Field (None ,
140+ alias = 'Dataset Name' ,
141+ extra_field = True )
142+ reviews : Optional [List [Review ]] = Field (None ,
143+ alias = 'Reviews' ,
144+ extra_field = True )
145+ label_url : Optional [str ] = Field (None , alias = 'View Label' , extra_field = True )
146+ has_open_issues : Optional [float ] = Field (None ,
147+ alias = 'Has Open Issues' ,
148+ extra_field = True )
149+ skipped : Optional [bool ] = Field (None , alias = 'Skipped' , extra_field = True )
152150
153151 def to_common (self ) -> Label :
154- is_video = False
155152 if isinstance (self .label , list ):
156153 annotations = []
157154 for lbl in self .label :
158155 annotations .extend (lbl .to_common ())
159- is_video = True
156+ data = VideoData (url = self .row_data ,
157+ external_id = self .external_id ,
158+ uid = self .data_row_id )
160159 else :
161160 annotations = self .label .to_common ()
161+ data = self ._infer_media_type ()
162162
163- return Label (
164- data = self .construct_data_ref (is_video ),
165- annotations = annotations ,
166- extra = {
167- 'Created By' : self .created_by ,
168- 'Project Name' : self .project_name ,
169- 'ID' : self .id ,
170- 'Created At' : self .created_at ,
171- 'Updated At' : self .updated_at ,
172- 'Seconds to Label' : self .seconds_to_label ,
173- 'Agreement' : self .agreement ,
174- 'Benchmark Agreement' : self .benchmark_agreement ,
175- 'Benchmark ID' : self .benchmark_id ,
176- 'Dataset Name' : self .dataset_name ,
177- 'Reviews' : [
178- review .dict (by_alias = True ) for review in self .reviews
179- ],
180- 'View Label' : self .label_url ,
181- 'Has Open Issues' : self .has_open_issues ,
182- 'Skipped' : self .skipped
183- })
163+ return Label (data = data ,
164+ annotations = annotations ,
165+ extra = {
166+ field .alias : getattr (self , field_name )
167+ for field_name , field in self .__fields__ .items ()
168+ if field .field_info .extra .get ('extra_field' )
169+ })
184170
185171 @classmethod
186172 def from_common (cls , label : Label , signer : Callable [[bytes ], str ]):
@@ -196,5 +182,23 @@ def from_common(cls, label: Label, signer: Callable[[bytes], str]):
196182 external_id = label .data .external_id ,
197183 ** label .extra )
198184
185+ def _infer_media_type (self ):
186+ keys = {'external_id' : self .external_id , 'uid' : self .data_row_id }
187+ if any ([x in self .row_data for x in (".jpg" , ".png" , ".jpeg" )
188+ ]) and self .row_data .startswith (("http://" , "https://" )):
189+ return RasterData (url = self .row_data , ** keys )
190+ elif any ([x in self .row_data for x in (".txt" , ".text" , ".html" )
191+ ]) and self .row_data .startswith (("http://" , "https://" )):
192+ return TextData (url = self .row_data , ** keys )
193+ elif isinstance (self .row_data , str ):
194+ return TextData (text = self .row_data , ** keys )
195+ elif len ([
196+ annotation for annotation in self .label .objects
197+ if isinstance (annotation , TextEntity )
198+ ]):
199+ return TextData (url = self .row_data , ** keys )
200+ else :
201+ raise TypeError ("Can't infer data type from row data." )
202+
199203 class Config :
200204 allow_population_by_field_name = True
0 commit comments