1 from __future__
import absolute_import
2 from __future__
import division
3 from __future__
import print_function
4 from __future__
import unicode_literals
6 from importlib
import import_module
12 def import_recursive(package):
14 Takes a package and imports all modules underneath it 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)
21 module = import_module(module_name)
23 import_recursive(module)
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)
33 import_recursive(sys.modules[__name__])
35 model_layer_subcls = set()
36 find_subclasses_recursively(layers.ModelLayer, model_layer_subcls)
38 for cls
in list(model_layer_subcls):
39 layers.register_layer(cls.__name__, cls)