Toybrick

rknn例子中ssd_mobilenet_v2修改ssd_mobilenet_v2.quantization.cfg的问题

had_in

注册会员

积分
142
楼主
发表于 2020-5-12 10:20:57    查看: 5024|回复: 4 | [复制链接]    打印 | 只看该作者
运行完step1.py后需要修改配置文件
  1. Please modify ssd_mobilenet_v2.quantization.cfg!
  2. ==================================================================================================
  3. Modify method:
  4. 1. delete @FeatureExtractor/MobilenetV2/expanded_conv/depthwise/depthwise_227:weight and its value
  5. 2. delete @FeatureExtractor/MobilenetV2/expanded_conv/depthwise/depthwise_227:bias and its value
  6. 3. delete @FeatureExtractor/MobilenetV2/Conv/Relu6_228:out0 and its value
  7. ==================================================================================================
  8. Original quantization profile and modified quantization profile diff shows in file quantization_profile.diff
复制代码
我的问题是:为什么要修改这些,这些层作用是啥
我用tensorflow的object detection API训练得到的pb文件,转换完成之后,quantization.cfg文件并没有这些层,我用Netron看了下例子中提供的ssd_mobilenet_v2.pb网络,网络结构与tensorflow API训练得到的模型并不一样,应该是你们做了修改,对于这种情况,需要修改quantization.cfg文件吗,应该如何修改。


我试着不修改quantization.cfg直接运行step3.py,出现如下错误
  1. W [rknn_inputs_set:1271] warning: inputs[0] expected input len is 270000, but actual len is 921600!
  2. ASSERT in NeuralNet.cpp.getNNInst(1471): (m_NnInst.outImageZeroPoint == 0x0) && "only UINT8 support tensor flow quantization\n"
  3. terminate called after throwing an instance of 'bool'
  4. Aborted (core dumped)
复制代码
我将仿照ssd_mobilenet_v2.quantization.cfg将我自己模型生成的quantization.cfg文件倒数第二层删除,step3.py可以跑通,但是结果全错。

回复

使用道具 举报

had_in

注册会员

积分
142
沙发
 楼主| 发表于 2020-5-12 11:39:29 | 只看该作者
求大佬帮助啊,在文档里看到这个,但是不修改会报错。。求大佬教。。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

leok

版主

积分
894
板凳
发表于 2020-5-12 17:50:43 | 只看该作者
had_in 发表于 2020-5-12 11:39
求大佬帮助啊,在文档里看到这个,但是不修改会报错。。求大佬教。。。
...

精度没问题的情况下。你不需要修改文件。
回复

使用道具 举报

had_in

注册会员

积分
142
地板
 楼主| 发表于 2020-5-13 10:59:54 | 只看该作者
大佬求教,我将tensorflow的ssd_mobilenet_v2_coco_2018_03_29模型转换成功并且也能够正常预测,但是基于这个模型训练的网络,同样的转换方式,发现结果并不正确,我发现输出的类别信息中,全部是背景类别,我的模型配置文件如下所示。
  1. # SSD with Mobilenet v2, configured for egohands dataset.
  2. # This file was extracted modified from 'pipeline.config' in
  3. # http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz

  4. model {
  5.   ssd {
  6.     num_classes: 2
  7.     box_coder {
  8.       faster_rcnn_box_coder {
  9.         y_scale: 10.0
  10.         x_scale: 10.0
  11.         height_scale: 5.0
  12.         width_scale: 5.0
  13.       }
  14.     }
  15.     matcher {
  16.       argmax_matcher {
  17.         matched_threshold: 0.5
  18.         unmatched_threshold: 0.5
  19.         ignore_thresholds: false
  20.         negatives_lower_than_unmatched: true
  21.         force_match_for_each_row: true
  22.       }
  23.     }
  24.     similarity_calculator {
  25.       iou_similarity {
  26.       }
  27.     }
  28.     anchor_generator {
  29.       ssd_anchor_generator {
  30.         num_layers: 6
  31.         min_scale: 0.05
  32.         max_scale: 0.95
  33.         aspect_ratios: 1.0
  34.         aspect_ratios: 2.0
  35.         aspect_ratios: 0.5
  36.         aspect_ratios: 3.0
  37.         aspect_ratios: 0.3333
  38.       }
  39.     }
  40.     image_resizer {
  41.       fixed_shape_resizer {
  42.         height: 300
  43.         width: 300
  44.       }
  45.     }
  46.     box_predictor {
  47.       convolutional_box_predictor {
  48.         min_depth: 0
  49.         max_depth: 0
  50.         num_layers_before_predictor: 0
  51.         use_dropout: false
  52.         dropout_keep_probability: 0.8
  53.         kernel_size: 3
  54.         box_code_size: 4
  55.         apply_sigmoid_to_scores: false
  56.         conv_hyperparams {
  57.           activation: RELU_6
  58.           regularizer {
  59.             l2_regularizer {
  60.               weight: 0.00004
  61.             }
  62.           }
  63.           initializer {
  64.             truncated_normal_initializer {
  65.               stddev: 0.03
  66.               mean: 0.0
  67.             }
  68.           }
  69.           batch_norm {
  70.             train: true
  71.             scale: true
  72.             center: true
  73.             decay: 0.9997
  74.             epsilon: 0.001
  75.           }
  76.         }
  77.       }
  78.     }
  79.     feature_extractor {
  80.       type: "ssd_mobilenet_v2"
  81.       min_depth: 16
  82.       depth_multiplier: 1.0
  83.       conv_hyperparams {
  84.         activation: RELU_6
  85.         regularizer {
  86.           l2_regularizer {
  87.             weight: 4e-05
  88.           }
  89.         }
  90.         initializer {
  91.           truncated_normal_initializer {
  92.             stddev: 0.03
  93.             mean: 0.0
  94.           }
  95.         }
  96.         batch_norm {
  97.           train: true
  98.           scale: true
  99.           center: true
  100.           decay: 0.9997
  101.           epsilon: 0.001
  102.         }
  103.       }
  104.       #batch_norm_trainable: true
  105.       use_depthwise: true
  106.     }
  107.     loss {
  108.       classification_loss {
  109.         weighted_sigmoid {
  110.         }
  111.       }
  112.       localization_loss {
  113.         weighted_smooth_l1 {
  114.         }
  115.       }
  116.       hard_example_miner {
  117.         num_hard_examples: 3000
  118.         iou_threshold: 0.99
  119.         loss_type: CLASSIFICATION
  120.         max_negatives_per_positive: 3
  121.         min_negatives_per_image: 3
  122.       }
  123.       classification_weight: 1.0
  124.       localization_weight: 1.0
  125.     }
  126.     normalize_loss_by_num_matches: true
  127.     post_processing {
  128.       batch_non_max_suppression {
  129.         score_threshold: 1e-8
  130.         iou_threshold: 0.6
  131.         max_detections_per_class: 100
  132.         max_total_detections: 100
  133.       }
  134.       score_converter: SIGMOID
  135.     }
  136.   }
  137. }

  138. train_config {
  139.   batch_size: 24
  140.   optimizer {
  141.     rms_prop_optimizer {
  142.       learning_rate {
  143.         exponential_decay_learning_rate {
  144.           initial_learning_rate: 0.004
  145.           decay_steps: 1000
  146.           decay_factor: 0.8
  147.         }
  148.       }
  149.       momentum_optimizer_value: 0.9
  150.       decay: 0.9
  151.       epsilon: 1.0
  152.     }
  153.   }
  154.   fine_tune_checkpoint: "ssd_mobilenet_v2_coco_2018_03_29/model.ckpt"
  155.   fine_tune_checkpoint_type: "detection"
  156.   num_steps: 20000
  157.   data_augmentation_options {
  158.     random_horizontal_flip {
  159.     }
  160.   }
  161.   data_augmentation_options {
  162.     ssd_random_crop {
  163.     }
  164.   }
  165. }

  166. train_input_reader {
  167.   tf_record_input_reader {
  168.     input_path: "data/pill_case.tfrecord"
  169.   }
  170.   label_map_path: "data/pill_case_label_map.txt"
  171. }

  172. eval_config {
  173.   num_examples: 500
  174.   max_evals: 10
  175.   use_moving_averages: false
  176. }

  177. eval_input_reader {
  178.   tf_record_input_reader {
  179.     input_path: "data/pill_case.tfrecord"
  180.   }
  181.   label_map_path: "data/pill_case_label_map.txt"
  182.   shuffle: false
  183.   num_readers: 1
  184. }
复制代码
训练得到的模型我测试过,效果是正常的,但是转换完成之后,检测不出目标。在示例代码step1.py中有如下一行代码
  1. rknn.config(channel_mean_value='127.5 127.5 127.5 128', reorder_channel='0 1 2', quantized_dtype='asymmetric_quantized-u8')
复制代码
在测试ssd_mobilenet_v2_coco_2018_03_29模型时,我这个参数不变,转换完成后能够正常预测,但是换成自己训练的模型,转换完成后无法检测目标,我检查了下concat_1节点的输出信息,发现预测的类别信息中都是背景。
实际应用中我输入给模型的图片并不作归一化,所以我将上面的代码改成
  1. rknn.config(channel_mean_value='0 0 0 1', reorder_channel='0 1 2', quantized_dtype='asymmetric_quantized-u8')
复制代码
但是转换完成后,结果依旧不正确。

菜鸟已经不知路在何方,求大神指教该怎么调试。这里附上模型地址,求教。。。
https://pan.baidu.com/s/13k_uSwMMMll4TKCyueT03A
提取码:6ytn

回复

使用道具 举报

leok

版主

积分
894
5#
发表于 2020-5-18 09:59:14 | 只看该作者
had_in 发表于 2020-5-13 10:59
大佬求教,我将tensorflow的ssd_mobilenet_v2_coco_2018_03_29模型转换成功并且也能够正常预测,但是基于这 ...

1、你用tensorboard打开模型,看详细信息,FeatureExtractor/MobilenetV2/Conv/Conv2D这个节点之前做了什么操作,需要做对应的前处理。
2、如果网络有改动,box_priors.txt需要根据的你网络重新生成。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表