我正在使用环回编写API,并且我的一种方法遇到了问题。所有方法均有效,但返回“错误:仅支持http(s)协议”的一种方法
这是有问题的方法
Engine.evaluateone = async function(container, name) {
// Accepts image as a header of an array and converts to a tensor and processes
const path = ('./server/storage/'+container+'/'+name+'.jpg');
const network = await tf.loadModel("file://./cnn/cnnmodel/model.json");
const img = new Canvas.Image();
const canvas = Canvas.createCanvas(28, 28);
const ctx = canvas.getContext("2d");
var response;
img.onload = function () {
ctx.drawImage(img, 0, 0, 28, 28);
var tensor = tf.fromPixels(canvas, 1);
tensor = loadAndProcessImage(tensor);
tensor = tensor.reshape([1, 28, 28, 1]);
var prediction = network.predict(tensor);
const labelPrediction = prediction.as1D().argMax().dataSync()[0];
response = [String.fromCharCode(labels[labelPrediction]), true]
}
img.src = path;
return response;
};
Engine.remoteMethod(
'evaluateone', {
http:
{path: '/evaluateone', verb: 'post'},
accepts: [
{arg: 'container', type: 'string'},
{arg: 'name', type: 'string'}
],
returns: [
{arg: 'prediction', type: 'string'},
{arg: 'success', type: 'boolean'}
]
}
);
我所说的是:
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'container=5c019e748ebd08001351269a&name=img_8' 'http://localhost:3000/api/engine/evaluateone?access_token=vNM60TvRA5OZnhHHmZf3y58xS5MTa3dMyOg81f9bYbm3HCS5aLqev59dDJujzU4o'
权限正确,方法只能由授权用户访问,因此访问令牌
我还发现,当使用GPU加速的tfjs库(tfjs-node-gpu)时,该方法有效,而当使用仅CPU的库(tfjs-node)时,该方法无效。唯一的变化是使用的库
感谢您的帮助