Skip quantizing conv->identity->Batch norm layers. Args: activation_op: Activation op detected by layer matching pattern Returns: skip_layer: boolean, true when conv->identity->batch norm is detected.
(activation_op)
| 581 | |
| 582 | |
| 583 | def _IsSkipLayer(activation_op): |
| 584 | """Skip quantizing conv->identity->Batch norm layers. |
| 585 | |
| 586 | Args: |
| 587 | activation_op: Activation op detected by layer matching pattern |
| 588 | |
| 589 | Returns: |
| 590 | skip_layer: boolean, true when conv->identity->batch norm is detected. |
| 591 | """ |
| 592 | |
| 593 | # Exclude quantization of conv->identity->BN, |
| 594 | # After folding, this part corresponds to estimation of mean and variance |
| 595 | # and should not be quantized. |
| 596 | skip_layer = False |
| 597 | if activation_op.type == 'Identity' and len(activation_op.outputs) == 1: |
| 598 | if len(activation_op.outputs[0].consumers()) == 1: |
| 599 | consumer = activation_op.outputs[0].consumers()[0] |
| 600 | if consumer.type in ['FusedBatchNorm', 'FusedBatchNormV3']: |
| 601 | skip_layer = True |
| 602 | logging.info( |
| 603 | 'Skipping quantizing %s, because it is the output of a conv/fc ' |
| 604 | 'followed by a identity, feeding a fused batch norm.', |
| 605 | activation_op.name) |
| 606 | return skip_layer |
| 607 | |
| 608 | |
| 609 | class _LayerMatch(object): |
no test coverage detected