You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

new_algorithm.md 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Algorithm Development Guide
  2. New algorithms, such as `hard example mining` in `incremental_learning` and `joint_inference`, `aggreagtion` in `federated_learning`, `multiple task learning` and `unseen task detect` in `lifelong learning`, need to be extended based on the basic classes provided by Sedna.
  3. ## 1. Add an hard example mining algorithm
  4. The algorithm named `Threshold` is used as an example to describe how to add an HEM algorithm to the Sedna hard example mining algorithm library.
  5. ### 1.1 Starting from the `class_factory.py`
  6. First, let's start from the `class_factory.py`. Two classes are defined in `class_factory.py`, namely `ClassType` and `ClassFactory`.
  7. `ClassFactory` can register the modules you want to reuse through decorators. For the new `ClassType.HEM` algorithm, the code is as follows:
  8. ```python
  9. @ClassFactory.register(ClassType.HEM, alias="Threshold")
  10. class ThresholdFilter(BaseFilter, abc.ABC):
  11. def __init__(self, threshold=0.5, **kwargs):
  12. self.threshold = float(threshold)
  13. def __call__(self, infer_result=None):
  14. # if invalid input, return False
  15. if not (infer_result
  16. and all(map(lambda x: len(x) > 4, infer_result))):
  17. return False
  18. image_score = 0
  19. for bbox in infer_result:
  20. image_score += bbox[4]
  21. average_score = image_score / (len(infer_result) or 1)
  22. return average_score < self.threshold
  23. ```
  24. ## 2. Configuring in the CRD yaml
  25. After registration, you only need to change the name of the hem and parameters in the yaml file, and then the corresponding class will be automatically called according to the name.
  26. ```yaml
  27. deploySpec:
  28. hardExampleMining:
  29. name: "Threshold"
  30. parameters:
  31. - key: "threshold"
  32. value: "0.9"
  33. ```