首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在将模型上传到Gcloud AI平台时找不到模型变量?

为什么在将模型上传到Gcloud AI平台时找不到模型变量?
EN

Stack Overflow用户
提问于 2022-10-19 00:18:40
回答 2查看 46关注 0票数 0

我训练了一个模型,并把它上传到Google平台。当我从命令行测试模型时,我希望从上传的模型中得到预测,而不是得到一条错误消息。以下是我遵循的步骤:

  1. 安装Gcloud
  2. 拯救我的模型
代码语言:javascript
复制
gcloud ai-platform local train \
    --module-name trainer.final_task \
    --package-path trainer/ --
  1. 手动创建一个桶
  2. 从步骤2到桶添加创建的文件(saved_model.pb)
  3. 在类似于Gcloud的这里中创建了一个模型,并将其与步骤5中的桶相链接(是的,我在桶中配置了Python和Tensorflow。)

  1. 从命令行测试它(这会产生错误)
代码语言:javascript
复制
MODEL_NAME=ML6Mugs
VERSION=FinalModel6

gcloud ai-platform predict \
    --region europe-west1 \
    --model $MODEL_NAME \
    --version $VERSION \
    --json-instances check_deployed_model/test.json

我错过了什么?很难在网上找到关于这个问题的东西。我唯一找到的就是

我的模型体系结构

代码语言:javascript
复制
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

误差

代码语言:javascript
复制
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"
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-19 18:01:07

这个问题已经解决了。我的问题是我给我的桶加错了路。

错误

gs://your_bucket_name/saved_model.pb

校正

gs://your_bucket_name/model-dir/

票数 1
EN

Stack Overflow用户

发布于 2022-10-20 20:29:37

我也有过类似的问题。

我做错了什么,:我只上传了saved_model.pb。

解决方案:您还需要上传随附的变量和资产文件夹。

代码语言:javascript
复制
BUCKET_NAME=<bucket-path>
MODEL_DIR=output/exported_model

gsutil cp -r $MODEL_DIR $BUCKET_NAME

输出/输出模型

是包含资产、变量文件夹和saved_model.pb的文件夹。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74118658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档