Caffe2 - Python API
A deep learning, cross platform ML framework
__init__.py
1 from __future__ import absolute_import
2 from __future__ import division
3 from __future__ import print_function
4 from __future__ import unicode_literals
5 
6 from importlib import import_module
7 import pkgutil
8 import sys
9 from . import layers
10 
11 
12 def import_recursive(package):
13  """
14  Takes a package and imports all modules underneath it
15  """
16 
17  pkg_dir = package.__path__
18  module_location = package.__name__
19  for (_module_loader, name, ispkg) in pkgutil.iter_modules(pkg_dir):
20  module_name = "{}.{}".format(module_location, name) # Module/package
21  module = import_module(module_name)
22  if ispkg:
23  import_recursive(module)
24 
25 
26 def find_subclasses_recursively(base_cls, sub_cls):
27  cur_sub_cls = base_cls.__subclasses__()
28  sub_cls.update(cur_sub_cls)
29  for cls in cur_sub_cls:
30  find_subclasses_recursively(cls, sub_cls)
31 
32 
33 import_recursive(sys.modules[__name__])
34 
35 model_layer_subcls = set()
36 find_subclasses_recursively(layers.ModelLayer, model_layer_subcls)
37 
38 for cls in list(model_layer_subcls):
39  layers.register_layer(cls.__name__, cls)