代码详解:构建一个简单的Keras+深度学习REST API(12)

如何不在REST API中加载Keras模型

你可能想在predict函数中加载模型 , 如下所示:

...

# ensure an image was properly uploaded to our endpoint

if request.method == "POST":

if request.files.get("image"):

# read the image in PIL format

image = request.files["image"
.read()

image = Image.open(io.BytesIO(image))

# preprocess the image and prepare it for classification

image = prepare_image(image target=(224 224))

# load the model

model = ResNet50(weights="imagenet")

推荐阅读