Beispiel #1
0
def VGG19(include_top=True,
          pretrained=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)
    vgg19 = make_vgg_layers(cfgs['E'], classes)
    vgg19.input_shape = input_shape
    if pretrained == True:
        download_model_from_google_drive('1nXKMsYklBimtqs7ZRv0dQ-RIqNvgopVh',
                                         dirname, 'vgg19_tf.pth')
        recovery_model = load(os.path.join(dirname, 'vgg19_tf.pth'))
        recovery_model.name = 'vgg19'
        recovery_model.eval()
        with tf.device(get_device()):
            if include_top == False:
                [recovery_model.remove_at(-1) for i in range(7)]
            else:
                if classes != 1000:
                    recovery_model.remove_at(-1)
                    recovery_model.add_module(
                        'fc3', Dense(classes, activation=None, name='fc3'))
                    recovery_model.add_module('softmax',
                                              SoftMax(name='softmax'))

            vgg19.model = recovery_model
    return vgg19
Beispiel #2
0
def MobileNetV2(include_top=True,
                pretrained=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)
    mob = MobileNet(input_shape=(224, 224, 3),
                    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('15LtLJHpvimV6cFGqAwJ4QALNEjeATrKe',
                                         dirname, 'mobilenet_v2_tf.pth')
        recovery_model = load(os.path.join(dirname, 'mobilenet_v2_tf.pth'))
        recovery_model.eval()

        if include_top == False:
            recovery_model.remove_at(-1)
        else:
            if classes != 1000:
                new_fc = Dense(classes, activation=None, name='fc')
                new_fc.input_shape = recovery_model.fc.input_shape
                recovery_model.fc = new_fc
        mob.model = recovery_model
    return mob
Beispiel #3
0
def VGG16(include_top=True,
          pretrained=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)
    vgg16 = make_vgg_layers(cfgs['D'], classes)
    vgg16.input_shape = input_shape
    if pretrained == True:
        download_model_from_google_drive('1fozCY4Yv_ud5UGpv7q4M9tcxZ2ryDCTb',
                                         dirname, 'vgg16_tf.pth')
        recovery_model = load(os.path.join(dirname, 'vgg16_tf.pth'))
        recovery_model.name = 'vgg16'
        recovery_model.eval()
        with tf.device(get_device()):
            if include_top == False:
                [recovery_model.remove_at(-1) for i in range(7)]
            else:
                if classes != 1000:
                    recovery_model.remove_at(-1)
                    recovery_model.add_module(
                        'fc3', Dense(classes, activation=None, name='fc3'))
                    recovery_model.add_module('softmax',
                                              SoftMax(name='softmax'))

            vgg16.model = recovery_model
    return vgg16