将 SSD MobileNetV2 自定义模型转换为 edgetpu 模型?

问题描述

我正在尝试将 mobilenetv2(ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8) 模型转换为 EdgeTPU 模型以进行对象检测。我正在使用 TF2。

我尝试了很多解决方案,但是当我将 tflite 模型转换为 edge tpu 时仍然有“cpu 操作”。如何转换整个 mobilenet 模型?

这是我的步骤;

  1. 下载预训练模型 (mobilenetv2),准备数据集(来自 coco 的特定类)并训练您的模型。
  2. 导出检查点 ./exporter_main_v2.py,现在我在 saved_models 文件下有“saved_model.pb、assest、checkpoints”。
  3. 打开 step2,安装 tf-nightly 2.5.0.dev20210218 和“export_tflite_graph_tf2.py”并立即导出模型。
  4. 这一步,尝试为 edgetpu(8bits) 量化模型并转换为 .tflite 文件。像这样的脚本;
  def representative_dataset_gen():
    for data in raw_test_data.take(10):
      image = data['image'].numpy()
      image = tf.image.resize(image,(320,320))
      image = image[np.newaxis,:,:]
      image = image - 127.5
      image = image * 0.007843
      yield [image]
  
  raw_test_data,info = tfds.load(name="coco/2017",with_info=True,split="test",data_dir="/TFDS",download=False)

  converter =  tf.lite.TFLiteConverter.from_saved_model('~/saved_model')
  converter.optimizations = [tf.lite.Optimize.DEFAULT]
  converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8,tf.lite.OpsSet.SELECT_TF_OPS]
  converter.inference_input_type = tf.int8
  converter.inference_output_type = tf.int8
  converter.allow_custom_ops = True
  converter.representative_dataset = representative_dataset_gen
  tflite_model = converter.convert()
  
  with open('{}/model_full_integer_quant.tflite'.format('/saved_model'),'wb') as w:

  w.write(tflite_model)
  1. 量化后从 netron 和这些模型属性可视化;

    enter image description here

  2. 然后我使用“edgetpu_compiler”和我的最终模型将 .tflite 模型转换为 edgetpu 模型;

    have 7 CPU operations

    enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...