MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _FindLayersToQuantize

Function _FindLayersToQuantize

tensorflow/contrib/quantize/python/quantize.py:344–580  ·  view source on GitHub ↗

Matches layers in graph to quantize. The following patterns get matched. Nodes surrounded by [] will be optionally matched: weight|folded_weight / conv|fc | [batch_to_space_nd] | [post_conv_correction] | [bia

(graph)

Source from the content-addressed store, hash-verified

342
343
344def _FindLayersToQuantize(graph):
345 """Matches layers in graph to quantize.
346
347 The following patterns get matched. Nodes surrounded by [] will be
348 optionally matched:
349
350 weight|folded_weight
351 /
352 conv|fc
353 |
354 [batch_to_space_nd]
355 |
356 [post_conv_correction]
357 |
358 [biasadd|folded_bias]
359 |
360 [bypass]
361 |
362 activation
363 |
364 [post_activation_bypass]
365
366 Match replacements:
367 If weight|folded_weight is found, FakeQuant is added afterwards.
368 If bypass is found, FakeQuant is added before and after.
369 If activation is found, FakeQuant is added afterwards.
370 If post_activation_bypass is found, FakeQuant is added afterwards.
371
372 Args:
373 graph: Graph to perform match on.
374
375 Returns:
376 list of _LayerMatches.
377 """
378 input_pattern = graph_matcher.OpTypePattern('*')
379 weight_var_pattern = graph_matcher.OpTypePattern('Variable|VariableV2')
380 weight_partition_identity_pattern = graph_matcher.OpTypePattern(
381 'Identity', inputs=[weight_var_pattern])
382 weight_partition_concat_pattern = graph_matcher.OpTypePattern(
383 'ConcatV2', inputs=[weight_partition_identity_pattern, '*', '*'])
384 weight_identity_pattern = graph_matcher.OpTypePattern(
385 'Identity',
386 inputs=[
387 graph_matcher.OneofPattern([
388 weight_partition_identity_pattern,
389 weight_partition_concat_pattern,
390 weight_var_pattern,
391 ])
392 ])
393 weight_resource_var_pattern = graph_matcher.OpTypePattern('ReadVariableOp')
394 folded_weight_pattern = graph_matcher.OpTypePattern('Mul')
395
396 # The weights inputs to the layer operation can either be from the Variable or
397 # the folded weight (Mul).
398 layer_pattern = graph_matcher.OpTypePattern(
399 '|'.join(_QUANTIZABLE_TYPES),
400 inputs=[
401 input_pattern,

Callers 1

QuantizeFunction · 0.85

Calls 9

match_graphMethod · 0.95
_LayerMatchClass · 0.85
_IsSkipLayerFunction · 0.85
GraphMatcherMethod · 0.80
get_opMethod · 0.80
joinMethod · 0.45
get_tensorMethod · 0.45
addMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected