我试图通过宽松地遵循本教程来重新训练用于自定义对象检测的mobilenet_v2模型。我的最终目标是要查询一个web_model,该模型将提供分数,classId和检测次数。最终导出的推理模型可在python环境中使用,但当前在转换为Web时会引发奇怪的错误。
感觉我的管道中缺少某个步骤,无法将推理图转换为Web。这似乎与model_main.py设置有关is_training=True,最终与最终的推理模型混为一谈。我似乎找不到关于如何从受过训练的模型中生成非训练模型的任何支持文档或教程。
我一直在使用tensorflow-gpu 1.13.1并model_main.py重新训练由对象检测zoo提供的当前ssd_mobilenet_v2_coco模型。我也尝试过使用legacy train.py和tensorflow 1.14.0。
当需要将其转换为tfjs时,我同时使用了tensorflowjs 1.2.2.1和0.8.6,当试图在Web上运行最终结果时,都导致了相同的错误。
我还尝试过在冻结模型上执行中间图变换,然后再使用0.8.6对其进行转换。
训练模型:
python model_main.py --model_dir=output --pipeline_config_path=training\ssd_mobilenet_v2_coco.config -num_train_steps=200000
Run Code Online (Sandbox Code Playgroud)
导出推理图:
python export_inference_graph.py --input_type=image_tensor --output_directory=output_inf --pipeline_config_path=training\ssd_mobilenet_v2_coco.config --trained_checkpoint_prefix=neg_32\model.ckpt-XXXX
Run Code Online (Sandbox Code Playgroud)
使用tfjs 1.2.2.1进行转换:
tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --saved_model_tags=serve --signature_name=serving_default output_inf\saved_model output_inf\web_model
Run Code Online (Sandbox Code Playgroud)
在浏览器中测试模型:
import * as tf from '@tensorflow/tfjs';
class Detector {
async init() {
try {
this.model = await tf.loadGraphModel('/web_model/model.json');
} catch (err) {
console.log(err);
}
}
async detect(frame) {
const { model } = this;
const INPUT_TENSOR='image_tensor';
const …Run Code Online (Sandbox Code Playgroud) javascript python tensorflow tensorflow.js tensorflowjs-converter