导出经过训练的模型后,BatchNorm 层仍然存在。我在某处读过这些应该被删除的推理,原因有两个:
- 网络输出可能有误
- 全网提速
好吧,我怀疑 1。但第二个事实听起来合乎逻辑,所以我的问题是:那么如何过滤掉图层?
环境:来自 Tensorflow GitHub 并在 Tensorflow 1.15.3 上训练的模型。
二手出口:
python deeplab/export_model.py \
--num_classes=2 --model_variant="mobilenet_v3_large_seg" \
--dataset="123" \
--checkpoint_path=training \
--crop_size=384 \
--crop_size=384 \
--export_path=graph.pb
摘录网络图:
(<tf.Tensor 'MobilenetV3/MobilenetV3/input:0' shape=(1, 768, 768, 3) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/weights:0' shape=(3, 3, 3, 16) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/weights/read:0' shape=(3, 3, 3, 16) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/Conv2D:0' shape=(1, 384, 384, 16) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/gamma:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/gamma/read:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/beta:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/beta/read:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/moving_mean:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/moving_mean/read:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/moving_variance:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/moving_variance/read:0' shape=(16,) dtype=float32>,)
(<tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:0' shape=(1, 384, 384, 16) dtype=float32>, <tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:1' shape=(16,) dtype=float32>, <tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:2' shape=(16,) dtype=float32>, <tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:3' shape=(16,) dtype=float32>, <tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:4' shape=(16,) dtype=float32>, <tf.Tensor 'MobilenetV3/Conv/BatchNorm/FusedBatchNormV3:5' shape=<unknown> dtype=float32>)
(<tf.Tensor 'MobilenetV3/Conv/hard_swish/add/y:0' shape=() dtype=float32>,)