Python keras.applications.mobilenet.preprocess_input() Examples
The following are 3
code examples of keras.applications.mobilenet.preprocess_input().
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.mobilenet
, or try the search function
.
Example #1
Source File: testScoreWithAdapaKeras.py From nyoka with Apache License 2.0 | 6 votes |
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)
Example #2
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 #3
Source File: cnn_face_attr_celeba.py From transparent_latent_gan with MIT License | 5 votes |
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 ##