Пример #1
0
def __vital_algorithm_register__():
    """
    Note:

        We may be able to refactor somethign like this

        # In vital.py

        def _register_algorithm(cls, name=None, desc=''):
            if name is None:
                name = cls.__name__
            from vital.algo import algorithm_factory
            if not algorithm_factory.has_algorithm_impl_name(cls.static_type_name(), name):
                algorithm_factory.add_algorithm(name, desc, cls)
                algorithm_factory.mark_algorithm_as_loaded(name)

        def register_algorithm(name=None, desc=''):
            '''
            POC refactor of __vital_algorithm_register__ into a decorator
            '''
            def _wrapper(cls):
                _register_algorithm(cls, name, desc)
                return cls
            return _wrapper

        def lazy_register(cls, name=None, desc=''):
            ''' Alternate Proof-of-Concept '''
            def __vital_algorithm_register__():
                return _register_algorithm(cls, name, desc)
            return __vital_algorithm_register__

        # Then in your class
        import vital
        @vial.register_algorithm(desc="PyTorch Netharn classification routine")
        class MyAlgorithm(BaseAlgo):
            ...

        # OR if the currenty lazy structure is important
        import vital
        class MyAlgorithm(BaseAlgo):
            ...

        __vital_algorithm_register__ = vital.lazy_register(MyAlgorithm, desc="PyTorch Netharn classification routine")

        # We could also play with adding class member variables for the lazy
        # initialization. There is lots of room to make this better / easier.
    """
    from vital.algo import algorithm_factory

    # Register Algorithm
    implementation_name = "netharn_classifier"

    if not algorithm_factory.has_algorithm_impl_name(
            NetharnClassifier.static_type_name(), implementation_name):
        algorithm_factory.add_algorithm(
            implementation_name, "PyTorch Netharn classification routine",
            NetharnClassifier)

        algorithm_factory.mark_algorithm_as_loaded(implementation_name)
def __vital_algorithm_register__():
    from vital.algo import algorithm_factory
    # Register Algorithm
    implementation_name = "SimpleImageObjectDetector"
    if algorithm_factory.has_algorithm_impl_name(
            SimpleImageObjectDetector.static_type_name(), implementation_name):
        return
    algorithm_factory.add_algorithm(implementation_name,
                                    "test image object detector arrow",
                                    SimpleImageObjectDetector)
    algorithm_factory.mark_algorithm_as_loaded(implementation_name)
Пример #3
0
def __vital_algorithm_register__():
    from vital.algo import algorithm_factory
    # Register Algorithm
    implementation_name = "CascadeClassifier"
    if algorithm_factory.has_algorithm_impl_name(
            CascadeClassifier.static_type_name(), implementation_name):
        return
    algorithm_factory.add_algorithm(
        implementation_name,
        "Opencv implementation of Haar cascade classifier", CascadeClassifier)
    algorithm_factory.mark_algorithm_as_loaded(implementation_name)
Пример #4
0
def __vital_algorithm_register__():
    from vital.algo import algorithm_factory
    # Register Algorithm
    implementation_name  = "SimpleImageObjectDetector"
    if algorithm_factory.has_algorithm_impl_name(
                                SimpleImageObjectDetector.static_type_name(),
                                implementation_name):
        return
    algorithm_factory.add_algorithm( implementation_name,
                                "test image object detector arrow",
                                 SimpleImageObjectDetector )
    algorithm_factory.mark_algorithm_as_loaded( implementation_name )
Пример #5
0
def __vital_algorithm_register__():
  from vital.algo import algorithm_factory

  # Register Algorithm
  implementation_name  = "npy_percentile_norm"
  if algorithm_factory.has_algorithm_impl_name(
      PercentileNorm16BitTo8Bit.static_type_name(), implementation_name ):
    return

  algorithm_factory.add_algorithm( implementation_name,
    "Numpy percentile normalization", PercentileNorm16BitTo8Bit )

  algorithm_factory.mark_algorithm_as_loaded( implementation_name )
Пример #6
0
def __vital_algorithm_register__():
  from vital.algo import algorithm_factory

  # Register Algorithm
  implementation_name  = "mmdet"

  if algorithm_factory.has_algorithm_impl_name(
      MMDetDetector.static_type_name(), implementation_name ):
    return

  algorithm_factory.add_algorithm( implementation_name,
    "PyTorch MMDetection testing routine", MMDetDetector )

  algorithm_factory.mark_algorithm_as_loaded( implementation_name )
Пример #7
0
def __vital_algorithm_register__():
    from vital.algo import algorithm_factory

    # Register Algorithm
    implementation_name = "netharn"

    if algorithm_factory.has_algorithm_impl_name(
      NetHarnTrainer.static_type_name(), implementation_name ):
        return

    algorithm_factory.add_algorithm( implementation_name,
      "PyTorch NetHarn detection training routine", NetHarnTrainer )

    algorithm_factory.mark_algorithm_as_loaded( implementation_name )
Пример #8
0
def __vital_algorithm_register__():
  from vital.algo import algorithm_factory

  # Register Algorithm
  implementation_name  = "tensorflow"

  if algorithm_factory.has_algorithm_impl_name(
      TFDetector.static_type_name(), implementation_name ):
    return

  algorithm_factory.add_algorithm( implementation_name,
  "Tensorflow detector testing routine", TFDetector )

  algorithm_factory.mark_algorithm_as_loaded( implementation_name )
Пример #9
0
def __vital_algorithm_register__():
  from vital.algo import algorithm_factory

  # Register Algorithm
  implementation_name  = "mmdet"

  if algorithm_factory.has_algorithm_impl_name(
      MMDetDetector.static_type_name(), implementation_name ):
    return

  algorithm_factory.add_algorithm( implementation_name,
    "PyTorch MMDetection testing routine", MMDetDetector )

  algorithm_factory.mark_algorithm_as_loaded( implementation_name )
def test_algorithm_factory():
    from vital.algo import ImageObjectDetector

    class TestImageObjectDetector(ImageObjectDetector):
        def __init__(self):
            ImageObjectDetector.__init__(self)

    # Add algorithm
    algorithm_factory.add_algorithm("test_detector", "test detector",
                                    TestImageObjectDetector)

    nose.tools.ok_(
        algorithm_factory.has_algorithm_impl_name("image_object_detector",
                                                  "test_detector"),
        "test_detector not found by the factory")

    # Check with an empty implementation
    nose.tools.assert_equal(
        algorithm_factory.has_algorithm_impl_name("image_object_detector", ""),
        False)
    # Check with dummy implementation
    nose.tools.assert_equal(
        algorithm_factory.has_algorithm_impl_name("image_object_detector",
                                                  "NotAnObjectDetector"),
        False)

    # Check that a registered implementation is returned by implementations
    nose.tools.ok_(
        "test_detector"
        in algorithm_factory.implementations("image_object_detector"),
        "Dummy example_detector not registered")
    # Check with an empty algorithm return empty list
    nose.tools.assert_equal(len(algorithm_factory.implementations("")), 0)
    # Check with dummy algorithm returns empty list
    nose.tools.assert_equal(
        len(algorithm_factory.implementations("NotAnAlgorithm")), 0)