我怎样才能 load/retrain/save ssd_inception_v2_coco 在 tensorflow.js 上?
How can I load/retrain/save ssd_inception_v2_coco on tensorflow.js?
ML / Tensorflow 初学者。
是否可以将任何这些已经训练好的模型加载到 tfjs 上并在那里重新训练,然后导出到下载或者 Tensorflow python 是唯一的方法吗?
我看到这个过程在这个 tutorial for Tensorflow Python 中有很好的描述和记录,但不幸的是我找不到任何 documentation/tutorial 来重新训练对象检测模型带有 tfjs 的浏览器(图片 classification yes,object detection no)。
我看到了如何使用 npm 加载 coco-ssd 模型,然后甚至可能触发将其保存到下载,但是怎么样:
- config文件(需要修改,因为我只想有一个class,而不是90个)
- 带注释的图像(.jpg、.xml 和 .csv)
- labels.pbtxt
- .记录文件
有什么方法可以重新训练 ssd 模型,例如 ssd_inception_v2_coco 而我没有找到正确的 google 关键字,或者在当前状态下是不可能的框架的?
您可以通过使用 coco-ssd 模型作为特征提取器来使用迁移学习。可以看到迁移学习的示例 here。
这是一个使用特征提取器提取特征的模型,作为新序列模型的输入。
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'
})
]
});
})
要检测 coco-ssd 的 90 classes 中的单个对象,可以简单地对 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}
})
如果class在coco-ssd中不存在,那么就需要构建一个检测器。
ML / Tensorflow 初学者。
是否可以将任何这些已经训练好的模型加载到 tfjs 上并在那里重新训练,然后导出到下载或者 Tensorflow python 是唯一的方法吗?
我看到这个过程在这个 tutorial for Tensorflow Python 中有很好的描述和记录,但不幸的是我找不到任何 documentation/tutorial 来重新训练对象检测模型带有 tfjs 的浏览器(图片 classification yes,object detection no)。
我看到了如何使用 npm 加载 coco-ssd 模型,然后甚至可能触发将其保存到下载,但是怎么样:
- config文件(需要修改,因为我只想有一个class,而不是90个)
- 带注释的图像(.jpg、.xml 和 .csv)
- labels.pbtxt
- .记录文件
有什么方法可以重新训练 ssd 模型,例如 ssd_inception_v2_coco 而我没有找到正确的 google 关键字,或者在当前状态下是不可能的框架的?
您可以通过使用 coco-ssd 模型作为特征提取器来使用迁移学习。可以看到迁移学习的示例 here。
这是一个使用特征提取器提取特征的模型,作为新序列模型的输入。
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'
})
]
});
})
要检测 coco-ssd 的 90 classes 中的单个对象,可以简单地对 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}
})
如果class在coco-ssd中不存在,那么就需要构建一个检测器。