single_model_pipeline.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .base import BasePipeline
  15. class _SingleModelPipeline(BasePipeline):
  16. def __init__(self, model, batch_size=1, **predictor_kwargs):
  17. super().__init__(**predictor_kwargs)
  18. self._build_predictor(model)
  19. self.set_predictor(batch_size)
  20. def _build_predictor(self, model):
  21. self.model = self._create_model(model)
  22. def set_predictor(self, batch_size):
  23. self.model.set_predictor(batch_size=batch_size)
  24. def predict(self, input, **kwargs):
  25. yield from self.model(input, **kwargs)
  26. class ImageClassification(_SingleModelPipeline):
  27. entities = "image_classification"
  28. class ObjectDetection(_SingleModelPipeline):
  29. entities = "object_detection"
  30. class InstanceSegmentation(_SingleModelPipeline):
  31. entities = "instance_segmentation"
  32. class SemanticSegmentation(_SingleModelPipeline):
  33. entities = "semantic_segmentation"
  34. class TSFc(_SingleModelPipeline):
  35. entities = "ts_fc"
  36. class TSAd(_SingleModelPipeline):
  37. entities = "ts_ad"
  38. class TSCls(_SingleModelPipeline):
  39. entities = "ts_cls"
  40. class MultiLableImageClas(_SingleModelPipeline):
  41. entities = "multi_label_image_classification"
  42. class SmallObjDet(_SingleModelPipeline):
  43. entities = "small_object_detection"
  44. class AnomolyDetection(_SingleModelPipeline):
  45. entities = "anomaly_detection"