gcloud实例上的/ tmp / model文件夹似乎为空。即使stderr日志另有说明,看来文件仍未从存储帐户正确复制过来。
请问我该怎么办以及我缺少什么。当我请求进行预测时,我能够成功创建模型版本。
以下是用于创建模型版本的命令:
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)
答案 0 :(得分:1)
根据您共享的代码,似乎您没有直接在from_path
中加载模型,而是将路径直接发送到Predictor实例。
例如,尝试使用keras模型直接在from_path
中加载模型:
@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问题跟踪器中here报告。响应是,在执行model_dir
时,需要从from_path
中使用模型和所有工件,如果要在@Override
public MagazineReader read(JsonReader in) throws IOException {
final MagazineReader magazineReader = new MagazineReader();
final Map<String, Object> users = new HashMap<>();
in.beginObject();
while (in.hasNext()) {
switch (in.nextName()) {
case "id":
magazineReader.setID(in.nextInt());
break;
case "tag":
magazineReader.setTag(in.nextString());
break;
case "users":
in.beginObject();
while(in.hasNext()) {
String key = in.nextName();
JsonToken type = in.peek();
if (type == JsonToken.NUMBER) {
users.put(key, in.nextInt());
} else if (type == JsonToken.STRING) {
users.put(key, in.nextString());
} else {
System.err.println("Unhandled type: " + type);
}
}
in.endObject();
break;
}
in.endObject();
}
}
中使用它们,则将它们存储在预测变量类中。预测。