4

我正在尝试使用此代码进行图像分类。当用户提供图像时,将加载 mobilenet 模型以进行预训练的图像。但是,我无法在 nodejs 中加载 mobilenet 模型。我正在使用最新版本的 nodejs。所以,这是我的尝试代码:

const tf = require('@tensorflow/tfjs');
const mobilenet = require('@tensorflow-models/mobilenet');
const tfnode = require('@tensorflow/tfjs-node');

const fs = require('fs');

const readImage = path => {

  const imageBuffer = fs.readFileSync(path);

  const tfimage = tfnode.node.decodeImage(imageBuffer);
  return tfimage;
}

const imageClassification = async path => {
  const image = readImage(path);
  const mobilenetModel = await mobilenet.load();
  const predictions = await mobilenetModel.classify(image);
}

if (process.argv.length !== 3) throw new Error('Incorrect arguments: node classify.js <IMAGE_FILE>');

imageClassification(process.argv[2]);

当我使用节点分类香蕉.jpg运行时,它给了我这个错误。将如何处理?

(node:17038) UnhandledPromiseRejectionWarning: FetchError: request to https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_100_224/classification/1/model.json failed, reason: Client network socket disconnected before secure TLS connection was established
4

0 回答 0