我训练了一个模型,并把它上传到Google平台。当我从命令行测试模型时,我希望从上传的模型中得到预测,而不是得到一条错误消息。以下是我遵循的步骤:
gcloud ai-platform local train \
--module-name trainer.final_task \
--package-path trainer/ --saved_model.pb)

MODEL_NAME=ML6Mugs
VERSION=FinalModel6
gcloud ai-platform predict \
--region europe-west1 \
--model $MODEL_NAME \
--version $VERSION \
--json-instances check_deployed_model/test.json我错过了什么?很难在网上找到关于这个问题的东西。我唯一找到的就是这。
我的模型体系结构
def model(input_layer):
"""Returns a compiled model.
This function is expected to return a model to identity the different mugs.
The model's outputs are expected to be probabilities for the classes and
and it should be ready for training.
The input layer specifies the shape of the images. The preprocessing
applied to the images is specified in data.py.
Add your solution below.
Parameters:
input_layer: A tf.keras.layers.InputLayer() specifying the shape of the input.
RGB colored images, shape: (width, height, 3)
Returns:
model: A compiled model
"""
input_shape=(input_layer.shape[1], input_layer.shape[2], input_layer.shape[3])
base_model = tf.keras.applications.MobileNetV2(weights='imagenet', input_shape=input_shape, include_top=False)
for layer in base_model.layers:
layer.trainable = False
model = models.Sequential()
model.add(base_model)
model.add(layers.GlobalAveragePooling2D())
model.add(layers.Dense(4, activation='softmax'))
model.compile(optimizer="rmsprop", loss='sparse_categorical_crossentropy', metrics=["accuracy"])
return model误差
ERROR: (gcloud.ai-platform.predict) HTTP request failed. Response: {
"error": {
"code": 400,
"message": "{\n \"error\": \"Could not find variable block_15_depthwise_BN/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/block_15_depthwise_BN/beta)\\n\\t [[{{function_node __inference__wrapped_model_15632}}{{node model/sequential/mobilenetv2_1.00_224/block_15_depthwise_BN/ReadVariableOp_1}}]]\"\n}",
"status": "INVALID_ARGUMENT"
}
}发布于 2022-10-19 18:01:07
这个问题已经解决了。我的问题是我给我的桶加错了路。
错误
gs://your_bucket_name/saved_model.pb
校正
gs://your_bucket_name/model-dir/
发布于 2022-10-20 20:29:37
我也有过类似的问题。
我做错了什么,:我只上传了saved_model.pb。
解决方案:您还需要上传随附的变量和资产文件夹。
BUCKET_NAME=<bucket-path>
MODEL_DIR=output/exported_model
gsutil cp -r $MODEL_DIR $BUCKET_NAME输出/输出模型
是包含资产、变量文件夹和saved_model.pb的文件夹。
https://stackoverflow.com/questions/74118658
复制相似问题