简体   繁体   English

如何在tensorflow.js上加载/重新训练/保存ssd_inception_v2_coco?

[英]How can I load/retrain/save ssd_inception_v2_coco on tensorflow.js?

ML / Tensorflow beginner. ML / Tensorflow初学者。

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? 是否可以将这些已经训练过的模型中的任何一个加载到tfjs上并在那里进行再训练,然后导出到Downloads或Tensorflow python是唯一的选择?

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). 我看到此过程在Tensorflow Python的本教程中得到了很好的描述和记录,但是不幸的是,我找不到任何文档/教程来使用tfjs在浏览器上重新训练对象检测模型(图像分类是,对象检测否)。

I see how I could load the coco-ssd model using npm, then probably even trigger saving it to downloads, but what about: 我看到了如何使用npm加载coco-ssd模型,然后甚至可能触发将其保存到下载中,但是呢:

  • config file (need to modify it because I want to have only one class, not 90) 配置文件(需要修改它,因为我只想拥有一个类,而不是90个类)
  • annotated images (both .jpg, .xml and .csv) 带注释的图像(.jpg,.xml和.csv)
  • labels.pbtxt labels.pbtxt
  • .record files .record文件

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? 是否有任何方法可以重新训练诸如ssd_inception_v2_coco之类的ssd模型,而我没有找到正确的Google关键字,或者在当前框架状态下是否不可能?

You can use transfer learning by using coco-ssd model as a feature extractor. 您可以通过将coco-ssd模型用作特征提取器来使用转移学习。 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'
      })
    ]
  });
})

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. 要从90种coco-ssd中检测出单个物体,可以简单地对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}
})

If the class does not exist in coco-ssd, then one needs to builds a detector. 如果该类在coco-ssd中不存在,则需要构建一个检测器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 google colab tensorflow 1.15.2 上训练自定义对象检测模型 ssd_mobilenet_v1_coco 和 ssd_inception_v2_coco? - how to train a custom object detection model ssd_mobilenet_v1_coco and ssd_inception_v2_coco on google colab tensorflow 1.15.2? 使用tensorflow时,在哪里可以找到ssd_mobilenet_v1_coco的标签映射文件(pbtxt)? - Where can I find the label map file(pbtxt) of ssd_mobilenet_v1_coco when using tensorflow? 如何将 ssd_mobilenet_v1_COCO_2017_11_17 加载到本地的 object_detection_webcam? - How can I load the ssd_mobilenet_v1_COCO_2017_11_17 to the object_detection_webcam locally? 保存一个Tensorflow模型并将其加载到Tensorflow.js中 - Save a Tensorflow Model and Load it in Tensorflow.js 如何将 Tensorflow model 转换为 tensorflow.js Z20F35E630DAF44DBFA4C3F68F5399? - How can I convert Tensorflow model to tensorflow.js model? 从Java重新训练Tensorflow Inception v3网络 - Retrain Tensorflow inception v3 network from Java 无法使用 TensorFlow Object 检测 API 以更大的输入分辨率训练 SSD Inception-V2 - Can't Train SSD Inception-V2 with Larger Input Resolution with TensorFlow Object Detection API 如何保存 Tensorflow LinearClassifier 模型并将其转换为兼容 Tensorflow.js - How do I save a Tensorflow LinearClassifier model and convert it to Tensorflow.js compatible 将retrain.py的输出转换为tensorflow.js - Convert output of retrain.py to tensorflow.js 如何使用张量流的retrain.py重新训练多个初始实例 - how to retrain multiple instances of inception using tensorflow's retrain.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM