jrmccluskey commented on code in PR #31564:
URL: https://github.com/apache/beam/pull/31564#discussion_r1636553320
##########
sdks/python/apache_beam/ml/transforms/embeddings/tensorflow_hub.py:
##########
@@ -132,3 +133,42 @@ def get_ptransform_for_processing(self, **kwargs) ->
beam.PTransform:
model_handler=_TextEmbeddingHandler(self),
inference_args=self.inference_args,
))
+
+
+class TensorflowHubImageEmbeddings(EmbeddingsManager):
+ def __init__(self, columns: List[str], hub_url: str, **kwargs):
+ """
+ Embedding config for tensorflow hub models. This config can be used with
+ MLTransform to embed image data. Models are loaded using the RunInference
+ PTransform with the help of a ModelHandler.
+
+ Args:
+ columns: The columns containing the images to be embedded.
+ hub_url: The url of the tensorflow hub model.
+ min_batch_size: The minimum batch size to be used for inference.
+ max_batch_size: The maximum batch size to be used for inference.
+ large_model: Whether to share the model across processes.
+ """
+ super().__init__(columns=columns, **kwargs)
+ self.model_uri = hub_url
+
+ def get_model_handler(self) -> ModelHandler:
+ # override the default inference function
+ return _TensorflowHubModelHandler(
+ model_uri=self.model_uri,
+ preprocessing_url=None,
+ min_batch_size=self.min_batch_size,
+ max_batch_size=self.max_batch_size,
+ large_model=self.large_model,
+ )
+
+ def get_ptransform_for_processing(self, **kwargs) -> beam.PTransform:
+ """
+ Returns a RunInference object that is used to run inference on the text
+ input using _TextEmbeddingHandler.
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]