當前位置: 首頁>>代碼示例>>Python>>正文


Python mobilenet.MobileNet方法代碼示例

本文整理匯總了Python中keras.applications.mobilenet.MobileNet方法的典型用法代碼示例。如果您正苦於以下問題:Python mobilenet.MobileNet方法的具體用法?Python mobilenet.MobileNet怎麽用?Python mobilenet.MobileNet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras.applications.mobilenet的用法示例。


在下文中一共展示了mobilenet.MobileNet方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mobilenet_retinanet

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_retinanet(num_classes, backbone='mobilenet224_1.0', inputs=None, modifier=None, **kwargs):
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((None, None, 3))

    mobilenet = MobileNet(input_tensor=inputs, alpha=alpha, include_top=False, pooling=None, weights=None)

    # get last layer from each depthwise convolution blocks 3, 5, 11 and 13
    outputs = [mobilenet.get_layer(name='conv_pw_{}_relu'.format(i)).output for i in [3, 5, 11, 13]]

    # create the mobilenet backbone
    mobilenet = keras.models.Model(inputs=inputs, outputs=outputs, name=mobilenet.name)

    # invoke modifier if given
    if modifier:
        mobilenet = modifier(mobilenet)

    # create the full model
    model = retinanet.retinanet_bbox(inputs=inputs, num_classes=num_classes, backbone=mobilenet, **kwargs)

    return model 
開發者ID:OlafenwaMoses,項目名稱:ImageAI,代碼行數:25,代碼來源:mobilenet.py

示例2: __call__

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def __call__(self):
        logging.debug("Creating model...")

        inputs = Input(shape=self._input_shape)
        model_mobilenet = MobileNet(input_shape=self._input_shape, alpha=self.alpha, depth_multiplier=1, dropout=1e-3, include_top=False, weights=None, input_tensor=None, pooling=None)
        x = model_mobilenet(inputs)
        #flatten = Flatten()(x)
        
        feat_a = Conv2D(20,(1,1),activation='relu')(x)
        feat_a = Flatten()(feat_a)
        feat_a = Dropout(0.2)(feat_a)
        feat_a = Dense(32,activation='relu',name='feat_a')(feat_a)

        pred_a = Dense(1,name='pred_a')(feat_a)
        model = Model(inputs=inputs, outputs=[pred_a])


        return model 
開發者ID:shamangary,項目名稱:SSR-Net,代碼行數:20,代碼來源:TYY_model.py

示例3: mobilenet_retinanet

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_retinanet(num_classes, backbone='mobilenet224_1.0', inputs=None, modifier=None, cfg=None, **kwargs):
    """ Constructs a retinanet model using a mobilenet backbone.

    Args
        num_classes: Number of classes to predict.
        backbone: Which backbone to use (one of ('mobilenet128', 'mobilenet160', 'mobilenet192', 'mobilenet224')).
        inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)).
        modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example).

    Returns
        RetinaNet model with a MobileNet backbone.
    """
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((None, None, 3))
    elif isinstance(inputs, tuple):
        inputs = keras.layers.Input(inputs)
        
    backbone = mobilenet.MobileNet(input_tensor=inputs, alpha=alpha, include_top=False, pooling=None, weights=None)

    # create the full model
    layer_names = ['conv_pw_5_relu', 'conv_pw_11_relu', 'conv_pw_13_relu']
    layer_outputs = [backbone.get_layer(name).output for name in layer_names]
    backbone = keras.models.Model(inputs=inputs, outputs=layer_outputs, name=backbone.name)

    # invoke modifier if given
    if modifier:
        backbone = modifier(backbone)

    return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=backbone.outputs, **kwargs) 
開發者ID:TUMFTM,項目名稱:CameraRadarFusionNet,代碼行數:34,代碼來源:mobilenet.py

示例4: __init__

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def __init__(self, input_size):
        input_image = Input(shape=(input_size, input_size, 3))

        mobilenet = MobileNet(input_shape=(224,224,3), include_top=False)
        mobilenet.load_weights(MOBILENET_BACKEND_PATH)

        x = mobilenet(input_image)

        self.feature_extractor = Model(input_image, x) 
開發者ID:pranoyr,項目名稱:head-detection-using-yolo,代碼行數:11,代碼來源:backend.py

示例5: __init__

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def __init__(self, input_size):
        input_image = Input(shape=(input_size, input_size, 3))

        mobilenet = MobileNet(input_shape=(224,224,3), include_top=False)
        mobilenet.load_weights("data/mobilenet_backend.h5")
        x = mobilenet(input_image)

        self.feature_extractor = Model(input_image, x) 
開發者ID:tlkh,項目名稱:SmartBin,代碼行數:10,代碼來源:object_detection_model.py

示例6: mobilenet_retinanet

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_retinanet(num_classes, backbone='mobilenet224_1.0', inputs=None, modifier=None, **kwargs):
    """ Constructs a retinanet model using a mobilenet backbone.

    Args
        num_classes: Number of classes to predict.
        backbone: Which backbone to use (one of ('mobilenet128', 'mobilenet160', 'mobilenet192', 'mobilenet224')).
        inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)).
        modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example).

    Returns
        RetinaNet model with a MobileNet backbone.
    """
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((None, None, 3))

    backbone = mobilenet.MobileNet(input_tensor=inputs, alpha=alpha, include_top=False, pooling=None, weights=None)

    # create the full model
    layer_names = ['conv_pw_5_relu', 'conv_pw_11_relu', 'conv_pw_13_relu']
    layer_outputs = [backbone.get_layer(name).output for name in layer_names]
    backbone = keras.models.Model(inputs=inputs, outputs=layer_outputs, name=backbone.name)

    # invoke modifier if given
    if modifier:
        backbone = modifier(backbone)

    return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=backbone.outputs, **kwargs) 
開發者ID:weecology,項目名稱:DeepForest,代碼行數:32,代碼來源:mobilenet.py

示例7: get_model_pretrain

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def get_model_pretrain(arch):
    modlrate = 1
    if   "VGG16" in arch:       base_model = vgg16.VGG16
    elif "VGG19" in arch:       base_model = vgg19.VGG19
    elif "RESNET50" in arch:    base_model = resnet50.ResNet50
    elif "DENSENET121" in arch: base_model = densenet.DenseNet121
    elif "MOBILENET" in arch:
        base_model = mobilenet.MobileNet
        modlrate = 10
    else: print("model not avaiable"); exit()
    base_model = base_model(weights='imagenet', include_top=False)
    return base_model, modlrate 
開發者ID:mhaut,項目名稱:hyperspectral_deeplearning_review,代碼行數:14,代碼來源:pretrain_imagenet_cnn.py

示例8: mobilenet_retinanet

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_retinanet(num_classes, backbone='mobilenet224_1.0', inputs=None, modifier=None, **kwargs):
    """ Constructs a retinanet model using a mobilenet backbone.

    Args
        num_classes: Number of classes to predict.
        backbone: Which backbone to use (one of ('mobilenet128', 'mobilenet160', 'mobilenet192', 'mobilenet224')).
        inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)).
        modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example).

    Returns
        RetinaNet model with a MobileNet backbone.
    """
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((None, None, 3))

    backbone = mobilenet.MobileNet(input_tensor=inputs, alpha=alpha, include_top=False, pooling=None, weights=None)

    # create the full model
    layer_names = ['conv_pw_5_relu', 'conv_pw_11_relu', 'conv_pw_13_relu']
    layer_outputs = [backbone.get_layer(name).output for name in layer_names]
    backbone = keras.models.Model(inputs=inputs, outputs=layer_outputs, name=backbone.name)

    # invoke modifier if given
    if modifier:
        backbone = modifier(backbone)

    # C2 not provided
    backbone_layers = {
        'C3': backbone.outputs[0],
        'C4': backbone.outputs[1],
        'C5': backbone.outputs[2]
    }

    return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=backbone_layers, **kwargs) 
開發者ID:fizyr,項目名稱:keras-retinanet,代碼行數:39,代碼來源:mobilenet.py

示例9: __init__

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def __init__(self):
        logger.info('Loading MobileNet')
        self.model = MobileNet(weights='imagenet') 
開發者ID:EliotAndres,項目名稱:pretrained.ml,代碼行數:5,代碼來源:models.py

示例10: get_small_model_with_other_model_as_layer

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def get_small_model_with_other_model_as_layer():
    from keras.layers import Input, Dense
    from keras.models import Model
    from keras.applications.mobilenet import MobileNet

    inp_mask = Input(shape=(128, 128, 3))
    pretrain_model_mask = MobileNet(input_shape=(128, 128, 3), include_top=False, weights='imagenet', pooling='avg')
    pretrain_model_mask.name = 'mobilenet'
    x = pretrain_model_mask(inp_mask)
    out = Dense(2, activation='sigmoid')(x)
    model = Model(inputs=inp_mask, outputs=[out])
    return model 
開發者ID:ZFTurbo,項目名稱:Keras-inference-time-optimizer,代碼行數:14,代碼來源:test_bench.py

示例11: mobilenet_m2det

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_m2det(num_classes, backbone='mobilenet224_1.0', inputs=None, modifier=None, **kwargs):
    """ Constructs a m2det model using a mobilenet backbone.

    Args
        num_classes: Number of classes to predict.
        backbone: Which backbone to use (one of ('mobilenet128', 'mobilenet160', 'mobilenet192', 'mobilenet224')).
        inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)).
        modifier: A function handler which can modify the backbone before using it in m2det (this can be used to freeze backbone layers for example).

    Returns
        RetinaNet model with a MobileNet backbone.
    """
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((640, 640, 3))

    backbone = mobilenet.MobileNet(input_tensor=inputs, alpha=alpha, include_top=False, pooling=None, weights=None)

    # create the full model
    layer_names = ['conv_pw_5_relu', 'conv_pw_11_relu', 'conv_pw_13_relu']
    layer_outputs = [backbone.get_layer(name).output for name in layer_names]
    backbone = keras.models.Model(inputs=inputs, outputs=layer_outputs, name=backbone.name)

    # invoke modifier if given
    if modifier:
        backbone = modifier(backbone)

    print(backbone.summary())

    return m2det.m2det(inputs=inputs, num_classes=num_classes, backbone_layers=backbone.outputs, **kwargs) 
開發者ID:LeeDongYeun,項目名稱:keras-m2det,代碼行數:34,代碼來源:mobilenet.py

示例12: mobilenet_retinanet

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def mobilenet_retinanet(num_classes, backbone='mobilenet224_1.0',
                        inputs=None, modifier=None, **kwargs):
    """ Constructs a retinanet model using a mobilenet backbone.

    Parameters
    ----------
    num_classes: int
        Number of classes to predict.
    backbone : str
        Which backbone to use (one of ('mobilenet128', 'mobilenet160', 
        'mobilenet192', 'mobilenet224')).
    inputs : tensor
        The inputs to the network (defaults to a Tensor of shape 
        (None, None, 3)).
    modifier : function
        A function handler which can modify the backbone before using 
        it in retinanet (this can be used to freeze backbone layers for 
        example).

    Returns
        RetinaNet model with a MobileNet backbone.
    """
    alpha = float(backbone.split('_')[1])

    # choose default input
    if inputs is None:
        inputs = keras.layers.Input((None, None, 3))

    backbone = mobilenet.MobileNet(
        input_tensor=inputs,
        alpha=alpha,
        include_top=False,
        pooling=None,
        weights=None)

    # create the full model
    layer_names = ['conv_pw_5_relu', 'conv_pw_11_relu', 'conv_pw_13_relu']
    layer_outputs = [backbone.get_layer(name).output for name in layer_names]
    backbone = keras.models.Model(
        inputs=inputs,
        outputs=layer_outputs,
        name=backbone.name)

    # invoke modifier if given
    if modifier:
        backbone = modifier(backbone)

    return retinanet.retinanet(
        inputs=inputs, 
        num_classes=num_classes, 
        backbone_layers=backbone.outputs, **kwargs) 
開發者ID:advboxes,項目名稱:perceptron-benchmark,代碼行數:53,代碼來源:mobilenet.py

示例13: get_tst_neural_net

# 需要導入模塊: from keras.applications import mobilenet [as 別名]
# 或者: from keras.applications.mobilenet import MobileNet [as 別名]
def get_tst_neural_net(type):
    model = None
    custom_objects = dict()
    if type == 'mobilenet_small':
        from keras.applications.mobilenet import MobileNet
        model = MobileNet((128, 128, 3), depth_multiplier=1, alpha=0.25, include_top=True, weights='imagenet')
    elif type == 'mobilenet':
        from keras.applications.mobilenet import MobileNet
        model = MobileNet((224, 224, 3), depth_multiplier=1, alpha=1.0, include_top=True, weights='imagenet')
    elif type == 'mobilenet_v2':
        from keras.applications.mobilenetv2 import MobileNetV2
        model = MobileNetV2((224, 224, 3), depth_multiplier=1, alpha=1.4, include_top=True, weights='imagenet')
    elif type == 'resnet50':
        from keras.applications.resnet50 import ResNet50
        model = ResNet50(input_shape=(224, 224, 3), include_top=True, weights='imagenet')
    elif type == 'inception_v3':
        from keras.applications.inception_v3 import InceptionV3
        model = InceptionV3(input_shape=(299, 299, 3), include_top=True, weights='imagenet')
    elif type == 'inception_resnet_v2':
        from keras.applications.inception_resnet_v2 import InceptionResNetV2
        model = InceptionResNetV2(input_shape=(299, 299, 3), include_top=True, weights='imagenet')
    elif type == 'xception':
        from keras.applications.xception import Xception
        model = Xception(input_shape=(299, 299, 3), include_top=True, weights='imagenet')
    elif type == 'densenet121':
        from keras.applications.densenet import DenseNet121
        model = DenseNet121(input_shape=(224, 224, 3), include_top=True, weights='imagenet')
    elif type == 'densenet169':
        from keras.applications.densenet import DenseNet169
        model = DenseNet169(input_shape=(224, 224, 3), include_top=True, weights='imagenet')
    elif type == 'densenet201':
        from keras.applications.densenet import DenseNet201
        model = DenseNet201(input_shape=(224, 224, 3), include_top=True, weights='imagenet')
    elif type == 'nasnetmobile':
        from keras.applications.nasnet import NASNetMobile
        model = NASNetMobile(input_shape=(224, 224, 3), include_top=True, weights='imagenet')
    elif type == 'nasnetlarge':
        from keras.applications.nasnet import NASNetLarge
        model = NASNetLarge(input_shape=(331, 331, 3), include_top=True, weights='imagenet')
    elif type == 'vgg16':
        from keras.applications.vgg16 import VGG16
        model = VGG16(input_shape=(224, 224, 3), include_top=False, pooling='avg', weights='imagenet')
    elif type == 'vgg19':
        from keras.applications.vgg19 import VGG19
        model = VGG19(input_shape=(224, 224, 3), include_top=False, pooling='avg', weights='imagenet')
    elif type == 'multi_io':
        model = get_custom_multi_io_model()
    elif type == 'multi_model_layer_1':
        model = get_custom_model_with_other_model_as_layer()
    elif type == 'multi_model_layer_2':
        model = get_small_model_with_other_model_as_layer()
    elif type == 'Conv2DTranspose':
        model = get_Conv2DTranspose_model()
    elif type == 'RetinaNet':
        model, custom_objects = get_RetinaNet_model()
    elif type == 'conv3d_model':
        model = get_simple_3d_model()
    return model, custom_objects 
開發者ID:ZFTurbo,項目名稱:Keras-inference-time-optimizer,代碼行數:60,代碼來源:test_bench.py


注:本文中的keras.applications.mobilenet.MobileNet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。