Skip to content

Commit

Permalink
Fixed getting layer dtype for Functional, Sequential layers (#1023)
Browse files Browse the repository at this point in the history
### Changes

Fixed getting layer dtype for Functional, Sequential layers

### Reason for changes

The _get_layer_dtype function for Functional, Sequential layers failes with runtime error.

### Related tickets

N/A

### Tests

N/A
  • Loading branch information
alexsu52 committed Nov 26, 2021
1 parent 39a3c5b commit deffb95
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions nncf/tensorflow/graph/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def _collect_custom_layer_infos(self, model: tf.keras.Model,
retval[layer_name] = custom_layer_info
return retval

def _get_layer_dtype(self, layer_config: Dict) -> str:
if layer_config['class_name'] in ['Functional', 'Sequential']:
return self._get_layer_dtype(layer_config['config']['layers'][0])

dtype = layer_config['config']['dtype']
if layer_config['class_name'] == 'TensorFlowOpLayer':
attrs = layer_config['config']['node_def'].get('attr', {})
dtype = attrs.get('DstT', {}).get('type') or attrs.get('T', {}).get('type') or dtype
return dtype

@staticmethod
def _get_layer_type(layer_config: Dict) -> str:
if layer_config['class_name'] == 'TensorFlowOpLayer':
Expand Down Expand Up @@ -269,14 +279,6 @@ def _get_graphdef_name_to_layer_var_map(concrete_fun) -> Dict[str, str]:

return names_map

@staticmethod
def _get_layer_dtype(layer_config: Dict) -> str:
dtype = layer_config['config']['dtype']
if layer_config['class_name'] == 'TensorFlowOpLayer':
attrs = layer_config['config']['node_def'].get('attr', {})
dtype = attrs.get('DstT', {}).get('type') or attrs.get('T', {}).get('type') or dtype
return dtype

@staticmethod
def _get_graphdef_node_name_for_custom_layer_node_weight(weighted_node: NodeDef,
graphdef_nodes: Dict[str, NodeDef]) -> str:
Expand Down

0 comments on commit deffb95

Please sign in to comment.