__init__.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from __future__ import absolute_import
  2. from .end2end import *
  3. __factory = {
  4. 'avg_pool': End2End_AvgPooling,
  5. }
  6. def names():
  7. return sorted(__factory.keys())
  8. def create(name, *args, **kwargs):
  9. """
  10. Create a model instance.
  11. Parameters
  12. ----------
  13. name : str
  14. Model name. Can be one of 'inception', 'resnet18', 'resnet34',
  15. 'resnet50', 'resnet101', and 'resnet152'.
  16. pretrained : bool, optional
  17. Only applied for 'resnet*' models. If True, will use ImageNet pretrained
  18. model. Default: True
  19. cut_at_pooling : bool, optional
  20. If True, will cut the model before the last global pooling layer and
  21. ignore the remaining kwargs. Default: False
  22. num_features : int, optional
  23. If positive, will append a Linear layer after the global pooling layer,
  24. with this number of output units, followed by a BatchNorm layer.
  25. Otherwise these layers will not be appended. Default: 256 for
  26. 'inception', 0 for 'resnet*'
  27. norm : bool, optional
  28. If True, will normalize the feature to be unit L2-norm for each sample.
  29. Otherwise will append a ReLU layer after the above Linear layer if
  30. num_features > 0. Default: False
  31. dropout : float, optional
  32. If positive, will append a Dropout layer with this dropout rate.
  33. Default: 0
  34. num_classes : int, optional
  35. If positive, will append a Linear layer at the end as the classifier
  36. with this number of output units. Default: 0
  37. """
  38. if name not in __factory:
  39. raise KeyError("Unknown model:", name)
  40. return __factory[name](*args, **kwargs)