def ResNet152(include_top=True, pretrained=True, freeze_features=False, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape)==3: input_shape=tuple(input_shape) else: input_shape=(3, 224, 224) resnet152 =ResNet(bottleneck, [3, 8, 36, 3], input_shape,num_classes=classes,include_top=include_top, model_name='resnet152') if pretrained==True: download_model_from_google_drive(model_urls['resnet152'],dirname,'resnet152.pth') recovery_model=load(os.path.join(dirname,'resnet152.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top(recovery_model,input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet152.model = recovery_model else: resnet152.model = _make_recovery_model_include_top(resnet152.model, include_top=include_top, classes=classes, freeze_features=False) resnet152.model.input_shape = input_shape resnet152.model.to(_device) return resnet152 # # # resnet34=ResNet(basic_block, [3, 4, 6, 3], (3, 224, 224)) # resnet50=ResNet(bottleneck, [3, 4, 6, 3], (3, 224, 224)) # resnet101=ResNet(bottleneck, [3, 4, 23, 3], (3, 224, 224)) # resnet152=ResNet(bottleneck, [3, 8, 36, 3], (3, 224, 224))
def VGG11(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) vgg11 = make_vgg_layers(cfgs['A'], classes) vgg11.input_shape = input_shape if pretrained: download_model_from_google_drive('1PV9-AwgD1v-JxDRzduOjjGduIR7MDhPW', dirname, 'vgg11.pth') recovery_model = load(os.path.join(dirname, 'vgg11.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'vgg11' recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) vgg11.model = recovery_model else: vgg11.model = _make_recovery_model_include_top(vgg11.model, include_top=include_top, classes=classes, freeze_features=True) vgg11.model.input_shape = input_shape vgg11.model.to(_device) return vgg11
def VGG13(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) vgg13 = make_vgg_layers(cfgs['B'], classes) if pretrained == True: download_model_from_google_drive('1wx67gmQ8eHWXs2mhJmNl-t-cFNw7dJ7O', dirname, 'vgg13.pth') recovery_model = load(os.path.join(dirname, 'vgg13.pth')) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) vgg13.model = recovery_model else: vgg13.model = _make_recovery_model_include_top(vgg13.model, include_top=include_top, classes=classes, freeze_features=True) vgg13.model.input_shape = input_shape vgg13.model.to(_device) return vgg13
def VGG16(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) vgg16 = make_vgg_layers(cfgs['D'], classes) vgg16.input_shape = input_shape if pretrained == True: download_model_from_google_drive('1uXiH5MSy1rvxrHjW4uB9E2BHMM8b0Fwr', dirname, 'vgg16.pth') recovery_model = load(os.path.join(dirname, 'vgg16.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'vgg16' recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) vgg16.model = recovery_model else: vgg16.model = _make_recovery_model_include_top(vgg16.model, include_top=include_top, classes=classes, freeze_features=True) vgg16.model.input_shape = input_shape vgg16.model.to(_device) return vgg16
def VGG19(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) vgg19 = make_vgg_layers(cfgs['E'], classes) vgg19.input_shape = input_shape if pretrained == True: download_model_from_google_drive('1nqQJLYMzeiUX9hji39-rrBUG42YyjhYg', dirname, 'vgg19.pth') recovery_model = load(os.path.join(dirname, 'vgg19.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'vgg19' recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) vgg19.model = recovery_model else: vgg19.model = _make_recovery_model_include_top(vgg19.model, include_top=include_top, classes=classes, freeze_features=True) vgg19.model.input_shape = input_shape vgg19.model.to(_device) return vgg19
def EfficientNetB5(include_top=True, pretrained=True, freeze_features=True, input_shape=(456, 456, 3), classes=1000, **kwargs): """ Args: freeze_features (): include_top (): pretrained (): input_shape (): classes (): **kwargs (): Returns: """ if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (456, 456, 3) effb5 = EfficientNet(1.6, 2.2, default_size=input_shape, dropout_rate=0.4, model_name='efficientnet-b5', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1o_JQkIFUP1_-9AkiTs-x8q7gyDMyqiJz', dirname, 'efficientnet-b5_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b5_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb5.model = recovery_model else: effb5.model = _make_recovery_model_include_top( effb5.model, include_top=include_top, classes=classes, freeze_features=True) effb5.model.input_shape = input_shape effb5.model.name = 'efficientnet-b5' return effb5
def EfficientNetB7(include_top=True, pretrained=True, freeze_features=True, input_shape=(600, 600, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (600, 600, 3) effb7 = EfficientNet(2.0, 3.1, default_size=input_shape, dropout_rate=0.5, model_name='efficientnet-b7', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained: download_model_from_google_drive( '1NcsqfYpnIXme8nk8qrrvNAVQOGK-EOZz', dirname, 'efficientnet-b7_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b7_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb7.model = recovery_model else: effb7.model = _make_recovery_model_include_top( effb7.model, include_top=include_top, classes=classes, freeze_features=True) effb7.model.input_shape = input_shape effb7.model.name = 'efficientnet-b7' return effb7
def EfficientNetB6(include_top=True, pretrained=True, freeze_features=True, input_shape=(528, 528, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (528, 528, 3) effb6 = EfficientNet(1.8, 2.6, default_size=input_shape, dropout_rate=0.5, model_name='efficientnet-b6', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1-dUqwaLzv2V7m8w4jkvFBlHTCsZq54JY', dirname, 'efficientnet-b6_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b6_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb6.model = recovery_model else: effb6.model = _make_recovery_model_include_top( effb6.model, include_top=include_top, classes=classes, freeze_features=True) effb6.model.input_shape = input_shape effb6.model.name = 'efficientnet-b6' return effb6
def EfficientNetB4(include_top=True, pretrained=True, freeze_features=True, input_shape=(380, 380, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (380, 380, 3) effb4 = EfficientNet(1.4, 1.8, 380, 0.4, model_name='efficientnet-b4', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1eOUvMemIysmAa0ePdGKz01NO1EYWI2Dp', dirname, 'efficientnet-b4_tf.pth') recovery_model = load( sanitize_path(os.path.join(dirname, 'efficientnet-b4_tf.pth'))) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb4.model = recovery_model else: effb4.model = _make_recovery_model_include_top( effb4.model, include_top=include_top, classes=classes, freeze_features=True) effb4.model.input_shape = input_shape effb4.model.name = 'efficientnet-b4' return effb4
def EfficientNetB3(include_top=True, pretrained=True, freeze_features=True, input_shape=(300, 300, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (300, 300, 3) effb3 = EfficientNet(1.2, 1.4, default_size=input_shape, dropout_rate=0.3, model_name='efficientnet-b3', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1LgG4bsYnkY-uj6sLqbebRP0va3gDEkgS', dirname, 'efficientnet-b3_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b3_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb3.model = recovery_model else: effb3.model = _make_recovery_model_include_top( effb3.model, include_top=include_top, classes=classes, freeze_features=True) effb3.model.input_shape = input_shape effb3.model.name = 'efficientnet-b3' return effb3
def EfficientNetB2(include_top=True, pretrained=True, freeze_features=True, input_shape=(260, 260, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (260, 260, 3) effb2 = EfficientNet(1.1, 1.2, default_size=input_shape, dropout_rate=0.3, model_name='efficientnet-b2', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1YQgy7PTgj8VereQfaxKJCZshIZK_uqtI', dirname, 'efficientnet-b2_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b2_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb2.model = recovery_model else: effb2.model = _make_recovery_model_include_top( effb2.model, include_top=include_top, classes=classes, freeze_features=True) effb2.model.input_shape = input_shape effb2.model.name = 'efficientnet-b2' return effb2
def EfficientNetB1(include_top=True, pretrained=True, freeze_features=True, input_shape=(240, 240, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (240, 240, 3) effb1 = EfficientNet(1.0, 1.1, default_size=input_shape, dropout_rate=0.2, model_name='efficientnet-b1', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1zCWDn4lwHCn4exAnGfBSPh9YHYTGdIYt', dirname, 'efficientnet-b1_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b1_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb1.model = recovery_model else: effb1.model = _make_recovery_model_include_top( effb1.model, include_top=include_top, classes=classes, freeze_features=True) effb1.model.input_shape = input_shape effb1.model.name = 'efficientnet-b1' return effb1
def EfficientNetB0(include_top=True, pretrained=True, freeze_features=True, input_shape=(224, 224, 3), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (224, 224, 3) effb0 = EfficientNet(1.0, 1.0, default_size=input_shape, dropout_rate=0.2, model_name='efficientnet-b0', include_top=include_top, num_classes=classes) with tf.device(get_device()): if pretrained: download_model_from_google_drive( '1pO4wRWY6N4e7U_7E2H-NhBPEF4MlR4ru', dirname, 'efficientnet-b0_tf.pth') recovery_model = load( os.path.join(dirname, 'efficientnet-b0_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) effb0.model = recovery_model else: effb0.model = _make_recovery_model_include_top( effb0.model, include_top=include_top, classes=classes, freeze_features=True) effb0.model.input_shape = input_shape effb0.model.name = 'efficientnet-b0' return effb0
def SE_ResNet50(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) resnet50 = SE_ResNet(se_bottleneck, [3, 4, 6, 3], input_shape, num_classes=classes, include_top=include_top, model_name='se_resnet50') if pretrained == True: download_model_from_google_drive(model_urls['se_resnet50'], dirname, 'se_resnet50.pth') recovery_model = load(os.path.join(dirname, 'se_resnet50.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'se_resnet50' recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, default_shape=(3, 224, 224), input_shape=input_shape, freeze_features=freeze_features) resnet50.model = recovery_model else: resnet50.model = _make_recovery_model_include_top( resnet50.model, include_top=include_top, classes=classes, default_shape=(3, 224, 224), input_shape=input_shape, freeze_features=True) resnet50.model.input_shape = input_shape resnet50.model.to(_device) return resnet50
def MobileNetV2(include_top=True, pretrained=True, freeze_features=True, input_shape=(3, 224, 224), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) mob = MobileNet(input_shape=(3, 224, 224), classes=classes, use_bias=False, width_mult=1.0, round_nearest=8, include_top=include_top, model_name='mobilenet') if pretrained == True: download_model_from_google_drive('1ULenXTjOO5PdT3fHv6N8bPXEfoJAn5yL', dirname, 'mobilenet_v2.pth') recovery_model = load(os.path.join(dirname, 'mobilenet_v2.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) mob.model = recovery_model else: mob.model = _make_recovery_model_include_top(mob.model, include_top=include_top, classes=classes, freeze_features=True) mob.model.input_shape = input_shape mob.model.to(_device) return mob
def ResNet18(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) resnet18 = ResNet(basic_block, [2, 2, 2, 2], input_shape, use_bias=False, include_top=include_top, model_name='resnet18') with tf.device(get_device()): if pretrained: download_model_from_google_drive( '1vReSW_l8fldyYQ6ay5HCYFGoMaGbdW2T', dirname, 'resnet50_tf.pth') recovery_model = load(os.path.join(dirname, 'resnet50_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet18.model = recovery_model else: resnet18.model = _make_recovery_model_include_top( resnet18.model, include_top=include_top, classes=classes, freeze_features=True) resnet18.model.input_shape = input_shape return resnet18
def EfficientNetB6(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 528, 528), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 528, 528) effb6 = EfficientNet(1.8, 2.6, input_shape, 0.5, model_name='efficientnet-b6', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1XJrKmcmMObN_nnjP2Z-YH_BQ3img58qF', dirname, 'efficientnet-b6.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b6.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb6.model = recovery_model else: effb6.model = _make_recovery_model_include_top(effb6.model, include_top=include_top, classes=classes, freeze_features=False) effb6.model.input_shape = input_shape effb6.model.to(get_device()) return effb6
def ResNet101(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (224, 224, 3) resnet101 = ResNet(bottleneck, [3, 4, 23, 3], input_shape, num_classes=classes, include_top=include_top, use_bias=True, model_name='resnet101') with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '13QYdFX3CvsNiegi-iUX1PUC0KKKgPNwr', dirname, 'resnet101_tf.pth') recovery_model = load(os.path.join(dirname, 'resnet101_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet101.model = recovery_model else: resnet101.model = _make_recovery_model_include_top( resnet101.model, include_top=include_top, classes=classes, freeze_features=True) resnet101.model.input_shape = input_shape return resnet101
def EfficientNetB7(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 600, 600), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 600, 600) effb7 = EfficientNet(2.0, 3.1, input_shape, 0.5, model_name='efficientnet-b7', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1M2DfvsNPRCWSo_CeXnUCQOR46rvOrhLl', dirname, 'efficientnet-b7.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b7.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb7.model = recovery_model else: effb7.model = _make_recovery_model_include_top(effb7.model, include_top=include_top, classes=classes, freeze_features=False) effb7.model.input_shape = input_shape effb7.model.to(get_device()) return effb7
def EfficientNetB4(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 380, 380), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 380, 380) effb4 = EfficientNet(1.4, 1.8, input_shape, 0.4, model_name='efficientnet-b4', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1X4ZOBR_ETRHZJeffJHvCmWTTy9_aW8SP', dirname, 'efficientnet-b4.pth') recovery_model = fix_layer( load(sanitize_path(os.path.join(dirname, 'efficientnet-b4.pth')))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb4.model = recovery_model else: effb4.model = _make_recovery_model_include_top(effb4.model, include_top=include_top, classes=classes, freeze_features=False) effb4.model.input_shape = input_shape effb4.model.to(get_device()) return effb4
def EfficientNetB5(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 456, 456), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 456, 456) effb5 = EfficientNet(1.6, 2.2, input_shape, 0.4, model_name='efficientnet-b5', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('17iTD12G9oW3jYAui84MKtdY4gjd9vpgG', dirname, 'efficientnet-b5.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b5.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb5.model = recovery_model else: effb5.model = _make_recovery_model_include_top(effb5.model, include_top=include_top, classes=classes, freeze_features=False) effb5.model.input_shape = input_shape effb5.model.to(get_device()) return effb5
def EfficientNetB2(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 260, 260), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 260, 260) effb2 = EfficientNet(1.1, 1.2, input_shape, 0.3, model_name='efficientnet-b2', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1PjqhB7WJasF_hqOwYtSBNSXSGBY-cRLU', dirname, 'efficientnet-b2.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b2.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb2.model = recovery_model else: effb2.model = _make_recovery_model_include_top(effb2.model, include_top=include_top, classes=classes, freeze_features=False) effb2.model.input_shape = input_shape effb2.model.to(get_device()) return effb2
def EfficientNetB3(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 300, 300), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 300, 300) effb3 = EfficientNet(1.2, 1.4, input_shape, 0.3, model_name='efficientnet-b3', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('11tMxdYdFfaEREwnESO4cwjtcoEB42zB_', dirname, 'efficientnet-b3.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b3.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb3.model = recovery_model else: effb3.model = _make_recovery_model_include_top(effb3.model, include_top=include_top, classes=classes, freeze_features=False) effb3.model.input_shape = input_shape effb3.model.to(get_device()) return effb3
def EfficientNetB1(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 240, 240), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 240, 240) effb1 = EfficientNet(1.0, 1.1, input_shape, 0.2, model_name='efficientnet-b1', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1F3BtnAjmDz4G9RS9Q0hqU_K7WWXCni1G', dirname, 'efficientnet-b1.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b1.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb1.model = recovery_model else: effb1.model = _make_recovery_model_include_top(effb1.model, include_top=include_top, classes=classes, freeze_features=False) effb1.model.input_shape = input_shape effb1.model.to(get_device()) return effb1
def EfficientNetB0(include_top=True, pretrained=True, freeze_features=False, input_shape=(3, 224, 224), classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) effb0 = EfficientNet(1.0, 1.0, input_shape, 0.2, model_name='efficientnet-b0', include_top=include_top, num_classes=classes) if pretrained: download_model_from_google_drive('1bxnoDerzoNfiZZLft4ocD3DAgx4v6aTN', dirname, 'efficientnet-b0.pth') recovery_model = fix_layer( load(os.path.join(dirname, 'efficientnet-b0.pth'))) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) effb0.model = recovery_model else: effb0.model = _make_recovery_model_include_top(effb0.model, include_top=include_top, classes=classes, freeze_features=False) effb0.model.input_shape = input_shape effb0.model.to(get_device()) return effb0
def ResNet18(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) resnet18 = ResNet(basic_block, [2, 2, 2, 2], input_shape, use_bias=False, include_top=include_top, model_name='resnet18') if pretrained == True: download_model_from_google_drive(model_urls['resnet18'], dirname, 'resnet18.pth') recovery_model = load(os.path.join(dirname, 'resnet18.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top( recovery_model, input_shape=input_shape, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet18.model = recovery_model else: resnet18.model = _make_recovery_model_include_top( resnet18.model, include_top=include_top, classes=classes, freeze_features=True) resnet18.model.input_shape = input_shape resnet18.model.to(_device) return resnet18
def SEResNet_IR_50_512(include_top=True, pretrained=True, freeze_features=False, input_shape=(3,112,112), classes=1000, **kwargs): if input_shape is not None and len(input_shape)==3: input_shape=tuple(input_shape) else: input_shape=(3, 112, 112) seresnet = SEResNet_IR(include_top=include_top,num_layers=50,Bottleneck=BottleNeck_IR_SE,drop_ratio=0.4,feature_dim=512,input_shape=input_shape) if pretrained == True: download_model_from_google_drive('1aLYbFvtvsV2gQ16D_vwzrKdbCgij7IoZ', dirname, 'arcface_se_50_512.pth') recovery_model = load(os.path.join(dirname, 'arcface_se_50_512.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'arcface_se_50_512' recovery_model = _make_recovery_model_include_top(recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) seresnet.model = recovery_model else: seresnet.model = _make_recovery_model_include_top(seresnet.model, include_top=include_top, classes=classes, freeze_features=False) seresnet.model.input_shape = input_shape seresnet.model.to(_device) return seresnet
def ResNet152(include_top=True, pretrained=True, freeze_features=False, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape)==3: input_shape=tuple(input_shape) else: input_shape=(224, 224,3) resnet152 =ResNet(bottleneck, [3, 8, 36, 3], input_shape,num_classes=classes,include_top=include_top, model_name='resnet152') with tf.device(get_device()): if pretrained==True: download_model_from_google_drive('1TeVBB5ynW9E4_EgxIdjugLT8oaXnQH_c',dirname,'resnet152_tf.pth') recovery_model=load(os.path.join(dirname,'resnet152_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model = _make_recovery_model_include_top(recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet152.model = recovery_model else: resnet152.model = _make_recovery_model_include_top(resnet152.model, include_top=include_top, classes=classes, freeze_features=False) resnet152.model.input_shape = input_shape return resnet152
def SE_ResNet101(include_top=True, pretrained=True, freeze_features=True, input_shape=None, classes=1000, **kwargs): if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) else: input_shape = (3, 224, 224) resnet101 = SE_ResNet(se_bottleneck, [3, 4, 23, 3], input_shape, num_classes=classes, include_top=include_top, model_name='resnet101') if pretrained == True: download_model_from_google_drive('1BO92ONsWnLQPWs9JVS-4SdpoPo5M4ABR', dirname, 'se_resnet101.pth') recovery_model = load(os.path.join(dirname, 'se_resnet101.pth')) recovery_model = fix_layer(recovery_model) recovery_model.name = 'se_resnet101' recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) resnet101.model = recovery_model else: resnet101.model = _make_recovery_model_include_top( resnet101.model, include_top=include_top, classes=classes, freeze_features=True) resnet101.model.input_shape = input_shape resnet101.model.to(_device) return resnet101
def DenseNet201(include_top=True, pretrained=True, input_shape=(224, 224, 3), freeze_features=False, classes=1000, **kwargs): """ Constructor the image classicication model with DenseNet201 as backbond Args: freeze_features (): include_top (): pretrained (bool): If True, returns a model pre-trained on ImageNet. input_shape (tuple or list): the default input image size in CHW order (C, H, W) classes (int): number of classes References Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf Returns: the image classicication model with DenseNet201 Examples: >>> dense201 = DenseNet201(include_top=True,pretrained=True,input_shape=(224,224,3),classes=1000) >>> 'n02124075' in dense201.infer_single_image(get_image_from_google_drive('1SwablQsZO8mBuB84xnr1IoOisE3pm03l'),1).key_list[0] True """ if input_shape is not None and len(input_shape) == 3: input_shape = tuple(input_shape) densenet201 = DenseNet([6, 12, 48, 32], 32, 64, include_top=include_top, pretrained=True, input_shape=input_shape, num_classes=classes, name='densenet201') with tf.device(get_device()): if pretrained == True: download_model_from_google_drive( '1dJfgus11jXVoCLWfZqTgZ6jKKtrB70om', dirname, 'densenet201_tf.pth') recovery_model = load(os.path.join(dirname, 'densenet201_tf.pth')) recovery_model = fix_layer(recovery_model) recovery_model._name = 'densenet201' recovery_model = _make_recovery_model_include_top( recovery_model, include_top=include_top, classes=classes, freeze_features=freeze_features) densenet201.model = recovery_model else: densenet201.model = _make_recovery_model_include_top( densenet201.model, include_top=include_top, classes=classes, freeze_features=False) densenet201.model.input_shape = input_shape return densenet201