本文整理汇总了Python中keras.applications.mobilenet.preprocess_input方法的典型用法代码示例。如果您正苦于以下问题:Python mobilenet.preprocess_input方法的具体用法?Python mobilenet.preprocess_input怎么用?Python mobilenet.preprocess_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.applications.mobilenet
的用法示例。
在下文中一共展示了mobilenet.preprocess_input方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_01_image_classifier_with_image_as_input
# 需要导入模块: from keras.applications import mobilenet [as 别名]
# 或者: from keras.applications.mobilenet import preprocess_input [as 别名]
def test_01_image_classifier_with_image_as_input(self):
cnn_pmml = KerasToPmml(self.model_final,model_name="MobileNetImage",description="Demo",\
copyright="Internal User",dataSet='image',predictedClasses=['dogs','cats'])
cnn_pmml.export(open('2classMBNet.pmml', "w"), 0)
img = image.load_img('nyoka/tests/resizedCat.png')
img = img_to_array(img)
img = preprocess_input(img)
imgtf = np.expand_dims(img, axis=0)
model_pred=self.model_final.predict(imgtf)
model_preds = {'dogs':model_pred[0][0],'cats':model_pred[0][1]}
model_name = self.adapa_utility.upload_to_zserver('2classMBNet.pmml')
predictions, probabilities = self.adapa_utility.score_in_zserver(model_name, 'nyoka/tests/resizedCat.png','DN')
self.assertEqual(abs(probabilities['cats'] - model_preds['cats']) < 0.00001, True)
self.assertEqual(abs(probabilities['dogs'] - model_preds['dogs']) < 0.00001, True)
示例2: test_02_image_classifier_with_base64string_as_input
# 需要导入模块: from keras.applications import mobilenet [as 别名]
# 或者: from keras.applications.mobilenet import preprocess_input [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)
示例3: load_data_batch
# 需要导入模块: from keras.applications import mobilenet [as 别名]
# 或者: from keras.applications.mobilenet import preprocess_input [as 别名]
def load_data_batch(num_images_total=None):
"""
load data and preprocess before feeding it to Keras model
:param num_images_total:
:return:
"""
list_x, list_y = [], []
if num_images_total is None:
image_names_select = img_names
else:
image_names_select = np.random.choice(img_names, num_images_total, replace=False)
for img_name in image_names_select:
x, y = get_data_sample(img_name=img_name, yn_interactive_plot=False)
list_x.append(x)
list_y.append(y)
x_batch = np.stack(list_x, axis=0)
y_batch = np.stack(list_y, axis=0)
x_batch_ready = preprocess_input(x_batch.copy())
y_batch_ready = np.array(y_batch, dtype='float32')
return x_batch_ready, y_batch_ready
##