本文整理汇总了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
示例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')
示例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)
示例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)
示例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')
示例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))
示例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
示例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
示例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)
示例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
示例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