Keep getting: "Attempted import error: 'loadFrozenModel' is not exported from '@tensorflow/tfjs-converter'"

Keep getting: "Attempted import error: 'loadFrozenModel' is not exported from '@tensorflow/tfjs-converter'"

我正在尝试将 Tensorflow-for-Poets 模型转换为 Tensorflow.js 模型,因此我可以在 front-end 环境(如网站)中使用。我试图按照本教程进行操作: https://gist.github.com/woudsma/d01eeda8998c9ab972d05ec9e9843886

我已按照所有说明进行操作,但当我尝试启动本地主机时,我不断收到标题错误:

src/index.js
Attempted import error: 'loadFrozenModel' is not exported from 
'@tensorflow/tfjs-converter'

我使用以下方法训练了 Tensorflow 模型:

我还看了这些以前问过的问题:

http://www.github.com/tensorflow/tfjs/issues/149

http://www.whosebug.com/questions/49718162/tfjs-converter-html-javascript-trouble-importing-class

但这并没有解决我的问题。

这是我在教程中找到的 example-project。它包含我在我的项目中也使用过的。 https://github.com/woudsma/retrain-mobilenet-for-the-web

我找不到关于这个特定错误的任何信息,有人知道出了什么问题吗?

PS:这也是我向 Stack Overflow post 提出的第一个问题,所以如果此 post.[=17= 中缺少/错误的地方,请告诉我]

编辑:添加了我的 index.js:

import { loadFrozenModel } from '@tensorflow/tfjs-converter'
import labels from './labels.json'

const ASSETS_URL = `${window.location.origin}/assets`
const MODEL_URL = `${ASSETS_URL}/mobilenet-v2/tensorflowjs_model.pb`
const WEIGHTS_URL = `${ASSETS_URL}/mobilenet-v2/weights_manifest.json`
const IMAGE_SIZE = 224 // Model input size

const loadModel = async () => {
  const model = await loadFrozenModel(MODEL_URL, WEIGHTS_URL)
  const input = tf.zeros([1, IMAGE_SIZE, IMAGE_SIZE, 3])
   // Warm up GPU
  // model.predict({ input }) // MobileNet V1
  model.predict({ Placeholder: input }) // MobileNet V2
  return model
}

const predict = async (img, model) => {
  const t0 = performance.now()
  const image = tf.fromPixels(img).toFloat()
  const resized = tf.image.resizeBilinear(image, [IMAGE_SIZE, IMAGE_SIZE])
  const offset = tf.scalar(255 / 2)
  const normalized = resized.sub(offset).div(offset)
  const input = normalized.expandDims(0)
  // const output = await tf.tidy(() => model.predict({ input })).data() 

// MobileNet V2
  const predictions = labels
    .map((label, index) => ({ label, accuracy: output[index] }))
    .sort((a, b) => b.accuracy - a.accuracy)
  const time = `${(performance.now() - t0).toFixed(1)} ms`
  return { predictions, time }
}

const start = async () => {
  const input = document.getElementById('input')
  const output = document.getElementById('output')
  const model = await loadModel()
  const predictions = await predict(input, model)
  output.append(JSON.stringify(predictions, null, 2))
}

start()

编辑:为了确定,我还添加了 HTML-file。

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Image classifier</title>
  </head>
  <body>
    <img id="input" src="assets/images/some-flower.jpg" />
    <pre id="output"></pre>
  </body>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
</html>

import { loadFrozenModel } from '@tensorflow/tfjs-converter'

loadFrozenModel 未从 @tensorflow/tfjs-converter 导出。它位于 @tensorflow/tfjs 的命名空间中。由于您已经导入了 CDN 脚本,因此您只需要使用 tf.loadFrozenModel

加载模型
const model = await loadFrozenModel(MODEL_URL, WEIGHTS_URL)

另外 tf.fromPixels 已更改为 tf.browser.fromPixels