3030from vgi .metadata import FunctionExample
3131from vgi .table_function import (
3232 BindParams ,
33- OutputCollector ,
3433 ProcessParams ,
3534 TableCardinality ,
3635 TableFunctionGenerator ,
3736 bind_fixed_schema ,
3837 init_single_worker ,
3938)
39+ from vgi_rpc .rpc import OutputCollector
4040
4141from . import model
4242from .scalars import _read_path
@@ -99,6 +99,8 @@ class ClassifyFunction(TableFunctionGenerator[_ClassifyBlobArgs]):
9999 FIXED_SCHEMA : ClassVar [pa .Schema ] = _CLASSIFY_SCHEMA
100100
101101 class Meta :
102+ """VGI function metadata."""
103+
102104 name = "classify"
103105 description = "Top-5 ImageNet predictions (label, confidence) for an image BLOB"
104106 categories = ["vision" , "classification" ]
@@ -111,10 +113,12 @@ class Meta:
111113
112114 @classmethod
113115 def cardinality (cls , params : BindParams [_ClassifyBlobArgs ]) -> TableCardinality :
116+ """Estimate the output row count (the default top-k)."""
114117 return TableCardinality (estimate = _DEFAULT_TOP_K , max = _DEFAULT_TOP_K )
115118
116119 @classmethod
117120 def process (cls , params : ProcessParams [_ClassifyBlobArgs ], state : None , out : OutputCollector ) -> None :
121+ """Classify the image BLOB and emit the top-5 predictions."""
118122 preds = model .classify_image (params .args .image , top_k = _DEFAULT_TOP_K )
119123 _emit_classify (preds , out , params .output_schema )
120124
@@ -128,6 +132,8 @@ class ClassifyTopKFunction(TableFunctionGenerator[_ClassifyBlobTopKArgs]):
128132 FIXED_SCHEMA : ClassVar [pa .Schema ] = _CLASSIFY_SCHEMA
129133
130134 class Meta :
135+ """VGI function metadata."""
136+
131137 name = "classify"
132138 description = "Top-k ImageNet predictions (label, confidence) for an image BLOB"
133139 categories = ["vision" , "classification" ]
@@ -140,11 +146,13 @@ class Meta:
140146
141147 @classmethod
142148 def cardinality (cls , params : BindParams [_ClassifyBlobTopKArgs ]) -> TableCardinality :
149+ """Estimate the output row count (the requested top-k)."""
143150 k = max (1 , params .args .top_k )
144151 return TableCardinality (estimate = k , max = k )
145152
146153 @classmethod
147154 def process (cls , params : ProcessParams [_ClassifyBlobTopKArgs ], state : None , out : OutputCollector ) -> None :
155+ """Classify the image BLOB and emit the top-k predictions."""
148156 preds = model .classify_image (params .args .image , top_k = params .args .top_k )
149157 _emit_classify (preds , out , params .output_schema )
150158
@@ -174,6 +182,8 @@ class ClassifyPathFunction(TableFunctionGenerator[_ClassifyPathArgs]):
174182 FIXED_SCHEMA : ClassVar [pa .Schema ] = _CLASSIFY_SCHEMA
175183
176184 class Meta :
185+ """VGI function metadata."""
186+
177187 name = "classify"
178188 description = "Top-5 ImageNet predictions for an image file path"
179189 categories = ["vision" , "classification" ]
@@ -186,10 +196,12 @@ class Meta:
186196
187197 @classmethod
188198 def cardinality (cls , params : BindParams [_ClassifyPathArgs ]) -> TableCardinality :
199+ """Estimate the output row count (the default top-k)."""
189200 return TableCardinality (estimate = _DEFAULT_TOP_K , max = _DEFAULT_TOP_K )
190201
191202 @classmethod
192203 def process (cls , params : ProcessParams [_ClassifyPathArgs ], state : None , out : OutputCollector ) -> None :
204+ """Read the image off disk, classify it, and emit the top-5 predictions."""
193205 preds = model .classify_image (_read_path (params .args .path ), top_k = _DEFAULT_TOP_K )
194206 _emit_classify (preds , out , params .output_schema )
195207
@@ -203,6 +215,8 @@ class ClassifyPathTopKFunction(TableFunctionGenerator[_ClassifyPathTopKArgs]):
203215 FIXED_SCHEMA : ClassVar [pa .Schema ] = _CLASSIFY_SCHEMA
204216
205217 class Meta :
218+ """VGI function metadata."""
219+
206220 name = "classify"
207221 description = "Top-k ImageNet predictions for an image file path"
208222 categories = ["vision" , "classification" ]
@@ -215,11 +229,13 @@ class Meta:
215229
216230 @classmethod
217231 def cardinality (cls , params : BindParams [_ClassifyPathTopKArgs ]) -> TableCardinality :
232+ """Estimate the output row count (the requested top-k)."""
218233 k = max (1 , params .args .top_k )
219234 return TableCardinality (estimate = k , max = k )
220235
221236 @classmethod
222237 def process (cls , params : ProcessParams [_ClassifyPathTopKArgs ], state : None , out : OutputCollector ) -> None :
238+ """Read the image off disk, classify it, and emit the top-k predictions."""
223239 preds = model .classify_image (_read_path (params .args .path ), top_k = params .args .top_k )
224240 _emit_classify (preds , out , params .output_schema )
225241
@@ -243,6 +259,8 @@ class ImageClassesFunction(TableFunctionGenerator[_NoArgs]):
243259 FIXED_SCHEMA : ClassVar [pa .Schema ] = _CLASSES_SCHEMA
244260
245261 class Meta :
262+ """VGI function metadata."""
263+
246264 name = "image_classes"
247265 description = "The model's ImageNet label set: (idx, label), 1000 rows"
248266 categories = ["vision" , "classification" ]
@@ -255,10 +273,12 @@ class Meta:
255273
256274 @classmethod
257275 def cardinality (cls , params : BindParams [_NoArgs ]) -> TableCardinality :
276+ """Estimate the output row count (the model's full label set)."""
258277 return TableCardinality (estimate = model .NUM_CLASSES , max = model .NUM_CLASSES )
259278
260279 @classmethod
261280 def process (cls , params : ProcessParams [_NoArgs ], state : None , out : OutputCollector ) -> None :
281+ """Emit every ``(idx, label)`` the classifier can predict."""
262282 rows = model .class_table ()
263283 out .emit (
264284 pa .RecordBatch .from_pydict (
0 commit comments