Python keras.applications.MobileNet() Examples
The following are 19
code examples of keras.applications.MobileNet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras.applications
, or try the search function
.
Example #1
Source File: mobile_net.py From age-gender-estimator-keras with MIT License | 6 votes |
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
Example #2
Source File: mobilenet_supervised_cifar.py From Pseudo-Label-Keras with MIT License | 5 votes |
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
Example #3
Source File: file_util.py From Mosaicer with MIT License | 5 votes |
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
Example #4
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #5
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #6
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #7
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #8
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #9
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #10
Source File: applications_test.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #11
Source File: mobilenet_transfer_cifar.py From Pseudo-Label-Keras with MIT License | 5 votes |
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
Example #12
Source File: mobilenet_transfer_pseudo_cifar.py From Pseudo-Label-Keras with MIT License | 5 votes |
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
Example #13
Source File: mobilenet_pseudo_cifar.py From Pseudo-Label-Keras with MIT License | 5 votes |
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
Example #14
Source File: test_keras_to_pmml_UnitTest.py From nyoka with Apache License 2.0 | 5 votes |
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))
Example #15
Source File: test_keras_to_pmml_UnitTest.py From nyoka with Apache License 2.0 | 5 votes |
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')
Example #16
Source File: _validateSchema.py From nyoka with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: testScoreWithAdapaKeras.py From nyoka with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: testScoreWithAdapaKeras.py From nyoka with Apache License 2.0 | 5 votes |
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')
Example #19
Source File: features.py From vergeml with MIT License | 4 votes |
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