首页 > 解决方案 > 使用自定义预测例程时没有这样的文件或目录:'/tmp/model/0001' google cloud ai platform

问题描述

gcloud 实例上的 /tmp/model 文件夹似乎是空的。即使标准错误日志另有说明,文件似乎也没有从存储帐户正确复制。

请问我该怎么做,我错过了什么。当我提出预测请求时,我能够成功创建模型版本。

错误信息

这是用于创建模型版本的命令:

gcloud beta ai-platform versions create $VERSION_NAME  --model $MODEL_NAME  --runtime-version 1.15  --python-version 3.7  --origin gs://$BUCKET_NAME/custom_prediction_routine/model/  --package-uris gs://$BUCKET_NAME/custom_prediction_routine/custom_predict_code-0.1.tar.gz  --prediction-class predictor.MyPredictor

这是from_path类方法:

@classmethod
def from_path(cls, model_dir):
    sys.stderr.write(str(model_dir))
    return cls(model_dir)

标签: google-cloud-platformgoogle-ai-platform

解决方案


根据您共享的代码,您似乎没有直接加载模型from_path,而是将路径直接发送到您的 Predictor 实例。

尝试直接在 中加载模型from_path,例如,使用 keras 模型:

@classmethod
def from_path(cls, model_dir):
    model = keras.models.load_model(model_dir) # Load with Keras, or the appropriate format
    return cls(model)

from_path如果问题仍然存在,请尝试从函数内部发出预热预测请求。例如:

@classmethod
def from_path(cls, model_dir):
    model = keras.models.load_model(model_dir)
    predictor = cls(model)
    outputs = predictor.predict([[1,2,3,4,5]]) # Here goes your warm up prediction request 
    return predictor

编辑

该问题已Google 问题跟踪器中报告。响应是,如果要在预测期间使用模型和将要使用的所有工件,则model_dir需要在执行期间加载from_path并存储在预测器类中。


推荐阅读