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


Python mobilenet.preprocess_input方法代碼示例

本文整理匯總了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) 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:21,代碼來源:testScoreWithAdapaKeras.py

示例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) 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:36,代碼來源:testScoreWithAdapaKeras.py

示例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

## 
開發者ID:SummitKwan,項目名稱:transparent_latent_gan,代碼行數:31,代碼來源:cnn_face_attr_celeba.py


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