当前位置: 首页>>代码示例>>Python>>正文


Python imagenet_utils.preprocess_input方法代码示例

本文整理汇总了Python中imagenet_utils.preprocess_input方法的典型用法代码示例。如果您正苦于以下问题:Python imagenet_utils.preprocess_input方法的具体用法?Python imagenet_utils.preprocess_input怎么用?Python imagenet_utils.preprocess_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagenet_utils的用法示例。


在下文中一共展示了imagenet_utils.preprocess_input方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: predict

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def predict(filename):
        assert os.path.isfile(filename) and 'cannot find file'
        model = ResNet50(weights='imagenet')

        img = image.load_img(filename, target_size=(224, 224))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)
        x = preprocess_input(x)

        preds = decode_predictions(model.predict(x))
        if len(preds) == 0:
            return None
        return preds[0][0][1]


##################################
# main
################################## 
开发者ID:thoschm,项目名称:START-Summit-2017-Blockchain-Machine-Learning-Workshop,代码行数:20,代码来源:classify.py

示例2: predict

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def predict(filename):
        assert os.path.isfile(filename) and 'cannot find file'
        model = ResNet50(weights='imagenet')

        img = image.load_img(filename, target_size=(224, 224))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)
        x = preprocess_input(x)

        preds = decode_predictions(model.predict(x))
        if len(preds) == 0:
            return None
        return preds[0][0][1]


##################################
# config
################################## 
开发者ID:thoschm,项目名称:START-Summit-2017-Blockchain-Machine-Learning-Workshop,代码行数:20,代码来源:user.py

示例3: compute_VGG19_features

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def compute_VGG19_features(keras_model_path, size, batch_size=32):

    sys.path.append(keras_model_path)
    from vgg19 import VGG19
    from imagenet_utils import preprocess_input
    from keras.models import Model

    # Load data
    hdf5_file = os.path.join(data_dir, "lfw_%s_data.h5" % size)
    with h5py.File(hdf5_file, "a") as hf:

        X = hf["data"][:].astype(np.float32)
        X = preprocess_input(X)

        base_model = VGG19(weights='imagenet', include_top=False)
        list_output = ["block3_conv1", "block4_conv1", "block5_conv1"]
        list_output = [base_model.get_layer(l).output for l in list_output]

        model = Model(input=base_model.input, output=list_output)
        vgg19_feat = model.predict(X, batch_size=batch_size, verbose=True)
        for i in range(len(vgg19_feat)):
            hf.create_dataset("data_VGG_%s" % str(i), data=vgg19_feat[i]) 
开发者ID:tdeboissiere,项目名称:DeepLearningImplementations,代码行数:24,代码来源:make_dataset.py

示例4: predict

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def predict(self, frame):
		image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).astype(np.float32)
		image = image.transpose((2, 0, 1))
		image = image.reshape((1,) + image.shape)

		image = preprocess_input(image)
		preds = self.model.predict(image)
		return decode_predictions(preds)[0] 
开发者ID:ChunML,项目名称:DeepLearning,代码行数:10,代码来源:camera_test.py

示例5: predict

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def predict(path, model_path, index_file_path, MainUI):
    try:
        result_string = " Detected Object : Probability \n \n"

        # Making check to load Model
        if (MainUI.resnet_model_loaded == False):
            wx.CallAfter(pub.sendMessage, "report101", message="Loading ResNet model for the first time. This may take a few minutes or less than a minute. Please wait. \nLoading.....")
            model = ResNet50(include_top=True, weights="imagenet", model_path=model_path)
            wx.CallAfter(pub.sendMessage, "report101", message="ResNet model loaded.. Picture about to be processed.. \nLoading......")
            MainUI.model_collection_resnet.append(model)  # Loading model if not loaded yet
            MainUI.resnet_model_loaded = True
        else:
            wx.CallAfter(pub.sendMessage, "report101", message="Retrieving loaded model. \nLoading........")
            model = MainUI.model_collection_resnet[0]  # Getting Model from model array if loaded before
            wx.CallAfter(pub.sendMessage, "report101", message="ResNet model loaded.. Picture about to be processed.. \nLoading......")

        # Image prediction processing
        target_image = image.load_img(path, grayscale=False, target_size=(224, 224))
        target_image = image.img_to_array(target_image, data_format="channels_last")
        target_image = np.expand_dims(target_image, axis=0)

        target_image = preprocess_input(target_image, data_format="channels_last")
        wx.CallAfter(pub.sendMessage, "report101", message="Picture is transformed for prediction. \nLoading........")
        prediction = model.predict(x=target_image, steps=1)
        wx.CallAfter(pub.sendMessage, "report101", message="Picture prediction is done. Sending in results. \nLoading......")

        # Retrieving prediction result and sending it back to the thread
        prediction_result = decode_predictions(prediction, top=10, index_file_path=index_file_path)

        for results in prediction_result:
            countdown = 0
            for result in results:
                countdown += 1
                result_string += "(" + str(countdown) + ") " + str(result[1]) + " : " + str(100 * result[2])[
                                                                                        0:4] + "% \n"

        return result_string
    except Exception as e:
        return getattr(e, "message", repr(e)) 
开发者ID:OlafenwaMoses,项目名称:Model-Playgrounds,代码行数:41,代码来源:ResNet.py

示例6: encodings

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def encodings(model, path):
	processed_img = image.load_img(path, target_size=(224,224))
	x = image.img_to_array(processed_img)
	x = np.expand_dims(x, axis=0)
	x = preprocess_input(x)
	image_final = np.asarray(x)
	prediction = model.predict(image_final)
	prediction = np.reshape(prediction, prediction.shape[1])

	return prediction 
开发者ID:Shobhit20,项目名称:Image-Captioning,代码行数:12,代码来源:encode_image.py

示例7: predict

# 需要导入模块: import imagenet_utils [as 别名]
# 或者: from imagenet_utils import preprocess_input [as 别名]
def predict(path, model_path, index_file_path, MainUI):

    try:
        result_string = " Detected Object : Probability \n \n"

        if (MainUI.squeezenet_model_loaded == False):
            wx.CallAfter(pub.sendMessage, "report101",
                         message="Loading SqueezeNet model for the first time. This may take few minutes or less than a minute. Please wait. \nLoading.....")
            model = SqueezeNet(model_path=model_path)
            wx.CallAfter(pub.sendMessage, "report101",
                         message="SqueezeNet model loaded.. Picture about to be processed.. \nLoading......")
            MainUI.model_collection_squeezenet.append(model)
            MainUI.squeezenet_model_loaded = True
        else:
            wx.CallAfter(pub.sendMessage, "report101", message="Retrieving loaded model. \nLoading........")
            model = MainUI.model_collection_squeezenet[0]
            wx.CallAfter(pub.sendMessage, "report101",
                         message="ResNet model loaded.. Picture about to be processed.. \nLoading......")

        img = image.load_img(path, target_size=(227, 227))
        img = image.img_to_array(img, data_format="channels_last")
        img = np.expand_dims(img, axis=0)

        img = preprocess_input(img, data_format="channels_last")
        wx.CallAfter(pub.sendMessage, "report101", message="Picture is transformed for prediction. \nLoading........")


        prediction = model.predict(img, steps=1)
        wx.CallAfter(pub.sendMessage, "report101",
                     message="Picture prediction is done. Sending in results. \nLoading......")

        predictiondata = decode_predictions(prediction, top=10, index_file_path=index_file_path)

        for results in predictiondata:
            countdown = 0
            for result in results:
                countdown += 1
                result_string += "(" + str(countdown) + ") " + str(result[1]) + " : " + str(100 * result[2])[
                                                                                        0:4] + "% \n"

        return result_string
    except Exception as e:
        return getattr(e, "message", repr(e)) 
开发者ID:OlafenwaMoses,项目名称:Model-Playgrounds,代码行数:45,代码来源:SqueezenetPrediction.py


注:本文中的imagenet_utils.preprocess_input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。