未验证 提交 1303affa 编写于 作者: W Wei Shengyu 提交者: GitHub

Merge pull request #720 from lyuwenyu/hub_L_b

Release unnecessary dependent pkgs
......@@ -12,21 +12,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.
dependencies = ['paddle', 'numpy']
dependencies = ['paddle']
import paddle
from ppcls.modeling import architectures
import os
import sys
def _load_pretrained_parameters(model, name):
class _SysPathG(object):
"""
_SysPathG used to add/clean path for sys.path. Making sure minimal pkgs dependents by skiping parent dirs.
__enter__
add path into sys.path
__exit__
clean user's sys.path to avoid unexpect behaviors
"""
def __init__(self, path):
self.path = path
def __enter__(self, ):
sys.path.insert(0, self.path)
def __exit__(self, type, value, traceback):
_p = sys.path.pop(0)
assert _p == self.path, 'Make sure sys.path cleaning {} correctly.'.format(
self.path)
with _SysPathG(
os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'ppcls', 'modeling')):
import architectures
def _load_pretrained_parameters(model, name):
url = 'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/{}_pretrained.pdparams'.format(
name)
path = paddle.utils.download.get_weights_path_from_url(url)
model.set_state_dict(paddle.load(path))
return model
def alexnet(pretrained=False, **kwargs):
def alexnet(pretrained=False, **kwargs):
"""
AlexNet
Args:
......@@ -42,8 +69,7 @@ def alexnet(pretrained=False, **kwargs):
return model
def vgg11(pretrained=False, **kwargs):
def vgg11(pretrained=False, **kwargs):
"""
VGG11
Args:
......@@ -60,8 +86,7 @@ def vgg11(pretrained=False, **kwargs):
return model
def vgg13(pretrained=False, **kwargs):
def vgg13(pretrained=False, **kwargs):
"""
VGG13
Args:
......@@ -78,8 +103,7 @@ def vgg13(pretrained=False, **kwargs):
return model
def vgg16(pretrained=False, **kwargs):
def vgg16(pretrained=False, **kwargs):
"""
VGG16
Args:
......@@ -96,8 +120,7 @@ def vgg16(pretrained=False, **kwargs):
return model
def vgg19(pretrained=False, **kwargs):
def vgg19(pretrained=False, **kwargs):
"""
VGG19
Args:
......@@ -114,8 +137,7 @@ def vgg19(pretrained=False, **kwargs):
return model
def resnet18(pretrained=False, **kwargs):
def resnet18(pretrained=False, **kwargs):
"""
ResNet18
Args:
......@@ -133,8 +155,7 @@ def resnet18(pretrained=False, **kwargs):
return model
def resnet34(pretrained=False, **kwargs):
def resnet34(pretrained=False, **kwargs):
"""
ResNet34
Args:
......@@ -152,8 +173,7 @@ def resnet34(pretrained=False, **kwargs):
return model
def resnet50(pretrained=False, **kwargs):
def resnet50(pretrained=False, **kwargs):
"""
ResNet50
Args:
......@@ -171,8 +191,7 @@ def resnet50(pretrained=False, **kwargs):
return model
def resnet101(pretrained=False, **kwargs):
def resnet101(pretrained=False, **kwargs):
"""
ResNet101
Args:
......@@ -190,8 +209,7 @@ def resnet101(pretrained=False, **kwargs):
return model
def resnet152(pretrained=False, **kwargs):
def resnet152(pretrained=False, **kwargs):
"""
ResNet152
Args:
......@@ -209,8 +227,7 @@ def resnet152(pretrained=False, **kwargs):
return model
def squeezenet1_0(pretrained=False, **kwargs):
def squeezenet1_0(pretrained=False, **kwargs):
"""
SqueezeNet1_0
Args:
......@@ -226,8 +243,7 @@ def squeezenet1_0(pretrained=False, **kwargs):
return model
def squeezenet1_1(pretrained=False, **kwargs):
def squeezenet1_1(pretrained=False, **kwargs):
"""
SqueezeNet1_1
Args:
......@@ -243,8 +259,7 @@ def squeezenet1_1(pretrained=False, **kwargs):
return model
def densenet121(pretrained=False, **kwargs):
def densenet121(pretrained=False, **kwargs):
"""
DenseNet121
Args:
......@@ -262,8 +277,7 @@ def densenet121(pretrained=False, **kwargs):
return model
def densenet161(pretrained=False, **kwargs):
def densenet161(pretrained=False, **kwargs):
"""
DenseNet161
Args:
......@@ -281,8 +295,7 @@ def densenet161(pretrained=False, **kwargs):
return model
def densenet169(pretrained=False, **kwargs):
def densenet169(pretrained=False, **kwargs):
"""
DenseNet169
Args:
......@@ -300,8 +313,7 @@ def densenet169(pretrained=False, **kwargs):
return model
def densenet201(pretrained=False, **kwargs):
def densenet201(pretrained=False, **kwargs):
"""
DenseNet201
Args:
......@@ -319,8 +331,7 @@ def densenet201(pretrained=False, **kwargs):
return model
def densenet264(pretrained=False, **kwargs):
def densenet264(pretrained=False, **kwargs):
"""
DenseNet264
Args:
......@@ -338,8 +349,7 @@ def densenet264(pretrained=False, **kwargs):
return model
def inceptionv3(pretrained=False, **kwargs):
def inceptionv3(pretrained=False, **kwargs):
"""
InceptionV3
Args:
......@@ -355,8 +365,7 @@ def inceptionv3(pretrained=False, **kwargs):
return model
def inceptionv4(pretrained=False, **kwargs):
def inceptionv4(pretrained=False, **kwargs):
"""
InceptionV4
Args:
......@@ -372,8 +381,7 @@ def inceptionv4(pretrained=False, **kwargs):
return model
def googlenet(pretrained=False, **kwargs):
def googlenet(pretrained=False, **kwargs):
"""
GoogLeNet
Args:
......@@ -389,8 +397,7 @@ def googlenet(pretrained=False, **kwargs):
return model
def shufflenetv2_x0_25(pretrained=False, **kwargs):
def shufflenetv2_x0_25(pretrained=False, **kwargs):
"""
ShuffleNetV2_x0_25
Args:
......@@ -406,8 +413,7 @@ def shufflenetv2_x0_25(pretrained=False, **kwargs):
return model
def mobilenetv1(pretrained=False, **kwargs):
def mobilenetv1(pretrained=False, **kwargs):
"""
MobileNetV1
Args:
......@@ -423,8 +429,7 @@ def mobilenetv1(pretrained=False, **kwargs):
return model
def mobilenetv1_x0_25(pretrained=False, **kwargs):
def mobilenetv1_x0_25(pretrained=False, **kwargs):
"""
MobileNetV1_x0_25
Args:
......@@ -440,8 +445,7 @@ def mobilenetv1_x0_25(pretrained=False, **kwargs):
return model
def mobilenetv1_x0_5(pretrained=False, **kwargs):
def mobilenetv1_x0_5(pretrained=False, **kwargs):
"""
MobileNetV1_x0_5
Args:
......@@ -457,8 +461,7 @@ def mobilenetv1_x0_5(pretrained=False, **kwargs):
return model
def mobilenetv1_x0_75(pretrained=False, **kwargs):
def mobilenetv1_x0_75(pretrained=False, **kwargs):
"""
MobileNetV1_x0_75
Args:
......@@ -474,8 +477,7 @@ def mobilenetv1_x0_75(pretrained=False, **kwargs):
return model
def mobilenetv2_x0_25(pretrained=False, **kwargs):
def mobilenetv2_x0_25(pretrained=False, **kwargs):
"""
MobileNetV2_x0_25
Args:
......@@ -491,8 +493,7 @@ def mobilenetv2_x0_25(pretrained=False, **kwargs):
return model
def mobilenetv2_x0_5(pretrained=False, **kwargs):
def mobilenetv2_x0_5(pretrained=False, **kwargs):
"""
MobileNetV2_x0_5
Args:
......@@ -508,8 +509,7 @@ def mobilenetv2_x0_5(pretrained=False, **kwargs):
return model
def mobilenetv2_x0_75(pretrained=False, **kwargs):
def mobilenetv2_x0_75(pretrained=False, **kwargs):
"""
MobileNetV2_x0_75
Args:
......@@ -525,8 +525,7 @@ def mobilenetv2_x0_75(pretrained=False, **kwargs):
return model
def mobilenetv2_x1_5(pretrained=False, **kwargs):
def mobilenetv2_x1_5(pretrained=False, **kwargs):
"""
MobileNetV2_x1_5
Args:
......@@ -542,8 +541,7 @@ def mobilenetv2_x1_5(pretrained=False, **kwargs):
return model
def mobilenetv2_x2_0(pretrained=False, **kwargs):
def mobilenetv2_x2_0(pretrained=False, **kwargs):
"""
MobileNetV2_x2_0
Args:
......@@ -559,8 +557,7 @@ def mobilenetv2_x2_0(pretrained=False, **kwargs):
return model
def mobilenetv3_large_x0_35(pretrained=False, **kwargs):
def mobilenetv3_large_x0_35(pretrained=False, **kwargs):
"""
MobileNetV3_large_x0_35
Args:
......@@ -572,12 +569,12 @@ def mobilenetv3_large_x0_35(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_large_x0_35(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_35')
model = _load_pretrained_parameters(model,
'MobileNetV3_large_x0_35')
return model
def mobilenetv3_large_x0_5(pretrained=False, **kwargs):
def mobilenetv3_large_x0_5(pretrained=False, **kwargs):
"""
MobileNetV3_large_x0_5
Args:
......@@ -589,12 +586,12 @@ def mobilenetv3_large_x0_5(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_large_x0_5(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_5')
model = _load_pretrained_parameters(model,
'MobileNetV3_large_x0_5')
return model
def mobilenetv3_large_x0_75(pretrained=False, **kwargs):
def mobilenetv3_large_x0_75(pretrained=False, **kwargs):
"""
MobileNetV3_large_x0_75
Args:
......@@ -606,12 +603,12 @@ def mobilenetv3_large_x0_75(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_large_x0_75(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_75')
model = _load_pretrained_parameters(model,
'MobileNetV3_large_x0_75')
return model
def mobilenetv3_large_x1_0(pretrained=False, **kwargs):
def mobilenetv3_large_x1_0(pretrained=False, **kwargs):
"""
MobileNetV3_large_x1_0
Args:
......@@ -623,12 +620,12 @@ def mobilenetv3_large_x1_0(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_large_x1_0(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_large_x1_0')
model = _load_pretrained_parameters(model,
'MobileNetV3_large_x1_0')
return model
def mobilenetv3_large_x1_25(pretrained=False, **kwargs):
def mobilenetv3_large_x1_25(pretrained=False, **kwargs):
"""
MobileNetV3_large_x1_25
Args:
......@@ -640,12 +637,12 @@ def mobilenetv3_large_x1_25(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_large_x1_25(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_large_x1_25')
model = _load_pretrained_parameters(model,
'MobileNetV3_large_x1_25')
return model
def mobilenetv3_small_x0_35(pretrained=False, **kwargs):
def mobilenetv3_small_x0_35(pretrained=False, **kwargs):
"""
MobileNetV3_small_x0_35
Args:
......@@ -657,12 +654,12 @@ def mobilenetv3_small_x0_35(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_small_x0_35(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_35')
model = _load_pretrained_parameters(model,
'MobileNetV3_small_x0_35')
return model
def mobilenetv3_small_x0_5(pretrained=False, **kwargs):
def mobilenetv3_small_x0_5(pretrained=False, **kwargs):
"""
MobileNetV3_small_x0_5
Args:
......@@ -674,12 +671,12 @@ def mobilenetv3_small_x0_5(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_small_x0_5(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_5')
model = _load_pretrained_parameters(model,
'MobileNetV3_small_x0_5')
return model
def mobilenetv3_small_x0_75(pretrained=False, **kwargs):
def mobilenetv3_small_x0_75(pretrained=False, **kwargs):
"""
MobileNetV3_small_x0_75
Args:
......@@ -691,12 +688,12 @@ def mobilenetv3_small_x0_75(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_small_x0_75(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_75')
model = _load_pretrained_parameters(model,
'MobileNetV3_small_x0_75')
return model
def mobilenetv3_small_x1_0(pretrained=False, **kwargs):
def mobilenetv3_small_x1_0(pretrained=False, **kwargs):
"""
MobileNetV3_small_x1_0
Args:
......@@ -708,12 +705,12 @@ def mobilenetv3_small_x1_0(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_small_x1_0(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_small_x1_0')
model = _load_pretrained_parameters(model,
'MobileNetV3_small_x1_0')
return model
def mobilenetv3_small_x1_25(pretrained=False, **kwargs):
def mobilenetv3_small_x1_25(pretrained=False, **kwargs):
"""
MobileNetV3_small_x1_25
Args:
......@@ -725,12 +722,12 @@ def mobilenetv3_small_x1_25(pretrained=False, **kwargs):
"""
model = architectures.MobileNetV3_small_x1_25(**kwargs)
if pretrained:
model = _load_pretrained_parameters(model, 'MobileNetV3_small_x1_25')
model = _load_pretrained_parameters(model,
'MobileNetV3_small_x1_25')
return model
def resnext101_32x4d(pretrained=False, **kwargs):
def resnext101_32x4d(pretrained=False, **kwargs):
"""
ResNeXt101_32x4d
Args:
......@@ -746,8 +743,7 @@ def resnext101_32x4d(pretrained=False, **kwargs):
return model
def resnext101_64x4d(pretrained=False, **kwargs):
def resnext101_64x4d(pretrained=False, **kwargs):
"""
ResNeXt101_64x4d
Args:
......@@ -763,8 +759,7 @@ def resnext101_64x4d(pretrained=False, **kwargs):
return model
def resnext152_32x4d(pretrained=False, **kwargs):
def resnext152_32x4d(pretrained=False, **kwargs):
"""
ResNeXt152_32x4d
Args:
......@@ -780,8 +775,7 @@ def resnext152_32x4d(pretrained=False, **kwargs):
return model
def resnext152_64x4d(pretrained=False, **kwargs):
def resnext152_64x4d(pretrained=False, **kwargs):
"""
ResNeXt152_64x4d
Args:
......@@ -797,8 +791,7 @@ def resnext152_64x4d(pretrained=False, **kwargs):
return model
def resnext50_32x4d(pretrained=False, **kwargs):
def resnext50_32x4d(pretrained=False, **kwargs):
"""
ResNeXt50_32x4d
Args:
......@@ -814,8 +807,7 @@ def resnext50_32x4d(pretrained=False, **kwargs):
return model
def resnext50_64x4d(pretrained=False, **kwargs):
def resnext50_64x4d(pretrained=False, **kwargs):
"""
ResNeXt50_64x4d
Args:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册