A function that reproduces Caffe's StateMeetsRule functionality.
(state, rule)
| 18 | |
| 19 | |
| 20 | def _StateMeetsRule(state, rule): |
| 21 | """A function that reproduces Caffe's StateMeetsRule functionality.""" |
| 22 | if rule.HasField('phase') and rule.phase != state.phase: |
| 23 | return False |
| 24 | if rule.HasField('min_level') and state.level < rule.min_level: |
| 25 | return False |
| 26 | if rule.HasField('max_level') and state.level > rule.max_level: |
| 27 | return False |
| 28 | curr_stages = set(list(state.stage)) |
| 29 | # all stages in rule.stages should be in, otherwise it's not a match. |
| 30 | if len(rule.stage) and any([s not in curr_stages for s in rule.stage]): |
| 31 | return False |
| 32 | # none of the stage in rule.stages should be in, otherwise it's not a match. |
| 33 | if len(rule.not_stage) and any([s in curr_stages for s in rule.not_stage]): |
| 34 | return False |
| 35 | # If none of the nonmatch happens, return True. |
| 36 | return True |
| 37 | |
| 38 | |
| 39 | def _ShouldInclude(net_state, layer): |
no test coverage detected
searching dependent graphs…