0

我正在通过loadGraphModelof@tensorflow/tfjs-converter包从 TFHub 加载模型。

loadModel = function () {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        return [2, tfconv.loadGraphModel('https://tfhub.dev/tensorflow/tfjs-model/toxicity/1/default/1', { fromTFHub: true })];
      });
    });
  };

这工作正常。然后我在本地下载了模型以进行离线预测:

.
├── group1-shard1of7
├── group1-shard2of7
├── group1-shard3of7
├── group1-shard4of7
├── group1-shard5of7
├── group1-shard6of7
├── group1-shard7of7
├── model.json
└── vocab.json

我现在想在本地加载这个模型。对于其他模型,我使用的tfjs.loadLayersModel(this.path)是支持文件协议的方法file://,但是如果我尝试加载此模型,我会收到以下错误

'className' and 'config' must set.

事实上,model.json这些键是缺失的。我试图以这种方式从集线器加载图表:

var loadGraphModel = function () {
  return new Promise(function (resolve, reject) {
    tfconv.loadGraphModel(
      'https://tfhub.dev/tensorflow/tfjs-model/toxicity/1/default/1',
      { fromTFHub: true })
      .then(res => {
        console.log(res)
        resolve(res);
      })
      .catch(err => reject(err));
  });
}

GraphModel {
  modelUrl: 'https://tfhub.dev/tensorflow/tfjs-model/toxicity/1/default/1/model.json?tfjs-format=file',
  loadOptions: { fromTFHub: true },
  version: 'undefined.undefined',
  handler: HTTPRequest {
    DEFAULT_METHOD: 'POST',
    weightPathPrefix: undefined,
    onProgress: undefined,
    fetch: [Function],
    path: 'https://tfhub.dev/tensorflow/tfjs-model/toxicity/1/default/1/model.json?tfjs-format=file',
    requestInit: {}
  },
  artifacts: {
    modelTopology: { node: [Array], library: {}, versions: {} },
    weightSpecs: [
    ...

那么如何GraphModel像从本地文件系统保存和重新加载一样在本地加载这个 TFHub?

4

0 回答 0