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


Python applications.MobileNet方法代碼示例

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


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

示例1: __call__

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications 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=self.weights, input_tensor=None, pooling=None)

        x = model_mobilenet(inputs)

        feat_a = GlobalAveragePooling2D()(x)
        feat_a = Dropout(0.5)(feat_a)
        feat_a = Dense(self.FC_LAYER_SIZE, activation="relu")(feat_a)

        pred_g_softmax = Dense(2, activation='softmax', name='gender')(feat_a)
        pred_a_softmax = Dense(self.num_neu, activation='softmax', name='age')(feat_a)

        model = Model(inputs=inputs, outputs=[pred_g_softmax, pred_a_softmax])

        return model 
開發者ID:KinarR,項目名稱:age-gender-estimator-keras,代碼行數:21,代碼來源:mobile_net.py

示例2: setUpClass

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def setUpClass(cls):
        print("******* Unit Test for Keras *******")
        cls.adapa_utility = AdapaUtility()
        cls.data_utility = DataUtility()
        model = applications.MobileNet(weights='imagenet', include_top=False,input_shape = (224, 224,3))
        activType='sigmoid'
        x = model.output
        x = Flatten()(x)
        x = Dense(1024, activation="relu")(x)
        predictions = Dense(2, activation=activType)(x)
        cls.model_final = Model(inputs =model.input, outputs = predictions,name='predictions') 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:13,代碼來源:testScoreWithAdapaKeras.py

示例3: test_02_image_classifier_with_base64string_as_input

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def test_02_image_classifier_with_base64string_as_input(self):
        model = applications.MobileNet(weights='imagenet', include_top=False,input_shape = (80, 80,3))
        activType='sigmoid'
        x = model.output
        x = Flatten()(x)
        x = Dense(1024, activation="relu")(x)
        predictions = Dense(2, activation=activType)(x)
        model_final = Model(inputs =model.input, outputs = predictions,name='predictions')
        
        cnn_pmml = KerasToPmml(model_final,model_name="MobileNetBase64",description="Demo",\
            copyright="Internal User",dataSet='imageBase64',predictedClasses=['dogs','cats'])
        cnn_pmml.export(open('2classMBNetBase64.pmml', "w"), 0)

        img = image.load_img('nyoka/tests/resizedTiger.png')
        img = img_to_array(img)
        img = preprocess_input(img)
        imgtf = np.expand_dims(img, axis=0)

        base64string = "data:float32;base64," + FloatBase64.from_floatArray(img.flatten(),12)
        base64string = base64string.replace("\n", "")
        csvContent = "imageBase64\n\"" + base64string + "\""
        text_file = open("input.csv", "w")
        text_file.write(csvContent)
        text_file.close()

        model_pred=model_final.predict(imgtf)
        model_preds = {'dogs':model_pred[0][0],'cats':model_pred[0][1]}

        model_name  = self.adapa_utility.upload_to_zserver('2classMBNetBase64.pmml')

        predictions, probabilities = self.adapa_utility.score_in_zserver(model_name, 'input.csv','DN')
  
        self.assertEqual(abs(probabilities['cats'] - model_preds['cats']) < 0.00001, True)
        self.assertEqual(abs(probabilities['dogs'] - model_preds['dogs']) < 0.00001, True) 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:36,代碼來源:testScoreWithAdapaKeras.py

示例4: test_validate_keras_mobilenet

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def test_validate_keras_mobilenet(self):
        input_tensor = Input(shape=(224, 224, 3))
        model = MobileNet(weights="imagenet", input_tensor=input_tensor)
        file_name = "keras"+model.name+".pmml"
        pmml_obj = KerasToPmml(model,dataSet="image",predictedClasses=[str(i) for i in range(1000)])
        pmml_obj.export(open(file_name,'w'),0)
        self.assertEqual(self.schema.is_valid(file_name), True) 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:9,代碼來源:_validateSchema.py

示例5: setUpClass

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def setUpClass(self):
        print("******* Unit Test for Keras *******")
        model = applications.MobileNet(weights='imagenet', include_top=False,input_shape = (224, 224,3))
        activType='sigmoid'
        x = model.output
        x = Flatten()(x)
        x = Dense(1024, activation="relu")(x)
        predictions = Dense(2, activation=activType)(x)
        self.model_final = Model(inputs =model.input, outputs = predictions,name='predictions') 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:11,代碼來源:test_keras_to_pmml_UnitTest.py

示例6: test_keras_01

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def test_keras_01(self):

        cnn_pmml = KerasToPmml(self.model_final,model_name="MobileNet",description="Demo",\
            copyright="Internal User",dataSet='image',predictedClasses=['cats','dogs'])
        cnn_pmml.export(open('2classMBNet.pmml', "w"), 0)
        reconPmmlObj=ny.parse('2classMBNet.pmml',True)
        self.assertEqual(os.path.isfile("2classMBNet.pmml"),True)
        self.assertEqual(len(self.model_final.layers), len(reconPmmlObj.DeepNetwork[0].NetworkLayer)) 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:10,代碼來源:test_keras_to_pmml_UnitTest.py

示例7: create_cnn

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def create_cnn():
    net = MobileNet(input_shape=(128,128,3), weights=None, include_top=False)
    # upsampling(32->128)
    input = Input((32,32,3))
    x = UpSampling2D(4)(input)
    x = net(x)
    x = GlobalAveragePooling2D()(x)
    x = Dense(10, activation="softmax")(x)

    model = Model(input, x)
    model.summary()
    return model 
開發者ID:koshian2,項目名稱:Pseudo-Label-Keras,代碼行數:14,代碼來源:mobilenet_pseudo_cifar.py

示例8: create_cnn

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def create_cnn():
    net = MobileNet(input_shape=(128,128,3), include_top=False)
    # conv_pw_6から訓練させる(41)
    for i in range(41):
        net.layers[i].trainable = False
    # upsampling(32->128)
    input = Input((32,32,3))
    x = UpSampling2D(4)(input)
    x = net(x)
    x = GlobalAveragePooling2D()(x)
    x = Dense(10, activation="softmax")(x)

    model = Model(input, x)
    model.summary()
    return model 
開發者ID:koshian2,項目名稱:Pseudo-Label-Keras,代碼行數:17,代碼來源:mobilenet_transfer_pseudo_cifar.py

示例9: test_mobilenet

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def test_mobilenet():
    app = applications.MobileNet
    last_dim = 1024
    _test_application_basic(app)
    _test_application_notop(app, last_dim)
    _test_application_variable_input_channels(app, last_dim)
    _test_app_pooling(app, last_dim) 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:9,代碼來源:applications_test.py

示例10: make_model

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def make_model(model, image_size):
    if model == "inceptionv3":
        base_model = InceptionV3(include_top=False, input_shape=image_size + (3,))
    elif model == "vgg16" or model is None:
        base_model = VGG16(include_top=False, input_shape=image_size + (3,))
    elif model == "mobilenet":
        base_model = MobileNet(include_top=False, input_shape=image_size + (3,))
    return base_model 
開發者ID:seongahjo,項目名稱:Mosaicer,代碼行數:10,代碼來源:file_util.py

示例11: get_imagenet_architecture

# 需要導入模塊: from keras import applications [as 別名]
# 或者: from keras.applications import MobileNet [as 別名]
def get_imagenet_architecture(architecture, variant, size, alpha, output_layer, include_top=False, weights='imagenet'):
    from keras import applications, Model

    if include_top:
        assert output_layer == 'last'

    if size == 'auto':
        size = get_image_size(architecture, variant, size)

    shape = (size, size, 3)

    if architecture == 'densenet':
        if variant == 'auto':
            variant = 'densenet-121'
        if variant == 'densenet-121':
            model = applications.DenseNet121(weights=weights, include_top=include_top, input_shape=shape)
        elif variant == 'densenet-169':
            model = applications.DenseNet169(weights=weights, include_top=include_top, input_shape=shape)
        elif variant == 'densenet-201':
            model = applications.DenseNet201(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'inception-resnet-v2':
        model = applications.InceptionResNetV2(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'mobilenet':
        model = applications.MobileNet(weights=weights, include_top=include_top, input_shape=shape, alpha=alpha)
    elif architecture == 'mobilenet-v2':
        model = applications.MobileNetV2(weights=weights, include_top=include_top, input_shape=shape, alpha=alpha)
    elif architecture == 'nasnet':
        if variant == 'auto':
            variant = 'large'
        if variant == 'large':
            model = applications.NASNetLarge(weights=weights, include_top=include_top, input_shape=shape)
        else:
            model = applications.NASNetMobile(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'resnet-50':
        model = applications.ResNet50(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'vgg-16':
        model = applications.VGG16(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'vgg-19':
        model = applications.VGG19(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'xception':
        model = applications.Xception(weights=weights, include_top=include_top, input_shape=shape)
    elif architecture == 'inception-v3':
        model = applications.InceptionV3(weights=weights, include_top=include_top, input_shape=shape)

    if output_layer != 'last':
        try:
            if isinstance(output_layer, int):
                layer = model.layers[output_layer]
            else:
                layer = model.get_layer(output_layer)
        except Exception:
            raise VergeMLError('layer not found: {}'.format(output_layer))
        model = Model(inputs=model.input, outputs=layer.output)

    return model 
開發者ID:mme,項目名稱:vergeml,代碼行數:57,代碼來源:features.py


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