如何在tensorflow.js上加载/重新训练/保存ssd_inception_v2_coco? [英] How can I load/retrain/save ssd_inception_v2_coco on tensorflow.js?

查看:776
本文介绍了如何在tensorflow.js上加载/重新训练/保存ssd_inception_v2_coco?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ML/Tensorflow初学者.

ML / Tensorflow beginner.

这些已经训练过的模型中的任何一个都可以加载到tfjs上并在那里进行重新训练,然后导出到Downloads还是Tensorflow python是唯一的选择吗?

Can any of these already-trained models be loaded on tfjs and re-trained there, then exported to Downloads or is Tensorflow python the only way to go?

我看到此过程在

I see this process is well described and documented in this tutorial for Tensorflow Python but unfortunately I can't find any documentation/tutorial to re-train an object detection model on the browser with tfjs (image classification yes, object detection no).

我了解了如何使用npm加载coco-ssd模型,然后甚至可能触发将其保存为下载内容,但是怎么办:

I see how I could load the coco-ssd model using npm, then probably even trigger saving it to downloads, but what about:

  • 配置文件(需要修改它,因为我只想拥有一个类,而不是90个类)
  • 带注释的图像(.jpg,.xml和.csv)
  • labels.pbtxt
  • .record文件

是否有任何方法可以重新训练ssd模型(例如ssd_inception_v2_coco),而我没有找到正确的Google关键字,或者只是在当前框架状态下无法实现?

Is there any way to go through the process of retraining an ssd model such as ssd_inception_v2_coco and I'm not hitting the right google keywords or is it just not possible in the current state of the framework?

推荐答案

您可以通过将coco-ssd模型用作特征提取器来使用转移学习.可以在此处看到转移学习的示例.

You can use transfer learning by using coco-ssd model as a feature extractor. An example of transfer-learning can be seen here.

这里是一个模型,该模型使用特征提取器作为新的顺序模型的输入来提取特征.

Here is a model which extracts features using a features extractor as an input for a new sequential model.

const loadModel = async () => {
  const loadedModel = await tf.loadModel(MODEL_URL)
  console.log(loadedModel)
  // take whatever layer except last output
  loadedModel.layers.forEach(layer => console.log(layer.name))
  const layer = loadedModel.getLayer(LAYER_NAME)
  return tf.model({ inputs: loadedModel.inputs, outputs: layer.output });
}
loadModel().then(featureExtractor => {
  model = tf.sequential({
    layers: [
      // Flattens the input to a vector so we can use it in a dense layer. While
      // technically a layer, this only performs a reshape (and has no training
      // parameters).
      // slice so as not to take the batch size
      tf.layers.flatten(
        { inputShape: featureExtractor.outputs[0].shape.slice(1) }),
      // add all the layers of the model to train
      tf.layers.dense({
        units: UNITS,
        activation: 'relu',
        kernelInitializer: 'varianceScaling',
        useBias: true
      }),
      // Last Layer. The number of units of the last layer should correspond
      // to the number of classes to predict.
      tf.layers.dense({
        units: NUM_CLASSES,
        kernelInitializer: 'varianceScaling',
        useBias: false,
        activation: 'softmax'
      })
    ]
  });
})

要检测90种coco-ssd中的单个对象,只需在预测coco-ssd时使用条件测试即可.

To detect a single object out of the 90 classes of coco-ssd, one could simply use a conditional test on the prediction of coco-ssd.

const image = document.getElementById(id)

cocoSsd.load()
  .then(model => model.detect(image))
  .then(prediction => {
if (prediction.class === OBJECT_DETECTED) {
  // display it the bbox to the user}
})

如果该类在coco-ssd中不存在,则需要构建一个检测器.

If the class does not exist in coco-ssd, then one needs to builds a detector.

这篇关于如何在tensorflow.js上加载/重新训练/保存ssd_inception_v2_coco?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆