【发布时间】:2017-11-18 02:33:21
【问题描述】:
我正在提供一个预先训练的初始模型,并且我一直按照官方教程提供它直到现在。我目前收到错误代码 3,如下:
{ Error: contents must be scalar, got shape [305]
[[Node: map/while/DecodeJpeg = DecodeJpeg[_output_shapes=[[?,?,3]], acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](map/while/TensorArrayReadV3)]]
at /server/node_modules/grpc/src/client.js:554:15 code: 3, metadata: Metadata { _internal_repr: {} } }
我正在使用来自 Tensorflow Serving 的 API 的 prediction_service.proto。这是我定义函数的 Nodejs 文件:
const PROTO_PATH = "./pb/prediction_service.proto";
const TensorflowServing = grpc.load(PROTO_PATH).tensorflow.serving;
const testClient = new TensorflowServing.PredictionService(
TF_TEST, grpc.credentials.createInsecure()
);
function getTestModelMsg(val){
return {
model_spec: { name: "inception", signature_name: "predict_images", version: 1},
inputs: {
images: {
dtype: "DT_STRING",
tensor_shape: {
dim: [{size: 220}, {size: 305}],
unknown_rank: false
},
string_val: val
}
}
}
}
function predictTest(array, callback) {
testClient.predict(getTestModelMsg(array), (error, response) => {
if(error)
return callback(error);
callback(null, response.outputs)
})}
我将图像作为二进制图像传递如下:
fs.readFile('./test/Xiang_Xiang_panda.jpg', (err, data) => {
if(err) {
return res.json({message: "Not found"});
}
predictTest( data.toString('binary') , (error, outputs) => {
if (error) {
console.error(error);
return res.status(500).json({ error });
}
res.status(200).json({ outputs });
})
})
我已经被困了一段时间,所以如果有人能在这里帮助我,我将不胜感激!任何帮助都会很棒! 提前致谢! :)
【问题讨论】:
标签: node.js tensorflow tensorflow-serving