def node_from_component(component): kaldi_check( 'name' in component and 'input' in component and 'type' in component, "'name', 'type' and 'input' are required in component: %s" % component) type = component['type'] name = component['name'] inputs = component['input'] if not isinstance(inputs, list): inputs = [inputs] inputs = [ input if isinstance(input, six.string_types) else str(input) for input in inputs ] attrs = {} if type in ATTRIBUTE_NAMES: attrs_names = ATTRIBUTE_NAMES[type] for key, value in component.items(): if key in attrs_names: attrs[key] = value consts = {} if type in CONSTS_NAMES: param_names = CONSTS_NAMES[type] for p_name in param_names: if p_name in component: p_values = component[p_name] p_tensor_name = name + '_' + p_name consts[p_tensor_name] = p_values inputs.append(p_tensor_name) return make_node(name, type, inputs, attrs, consts)
def convert_input(self, component): kaldi_check('input_dim' in component or 'dim' in component, "input_dim or dim attribute is required in input" " component: %s" % component) if 'input_dim' in component: dim = component['input_dim'] else: dim = component['dim'] self._input_dims[component['name']] = int(dim) self._inputs.append(component['name'])
def convert_components(self): nodes = [] for component in self._components: kaldi_check('type' in component, "'type' is required in component: %s" % component) type = component['type'] if type in KaldiOps: node = self.node_from_component(component) nodes.append(node) elif type == 'Input': self.convert_input(component) elif type == 'Output': self.convert_output(component) else: raise Exception( "Unrecognised component type: {0}.".format(type)) self._nodes = nodes
def node_from_component(self, component): kaldi_check('name' in component and 'input' in component and 'type' in component, "'name', 'type' and 'input'" " are required in component: %s" % component) type = component['type'] name = component['name'] inputs = component['input'] if not isinstance(inputs, list): inputs = [inputs] inputs = [input if isinstance(input, six.string_types) else str(input) for input in inputs] attrs = {} if type in ATTRIBUTE_NAMES: attrs_names = ATTRIBUTE_NAMES[type] for key, value in component.items(): if key in attrs_names: attrs[key] = value if type == KaldiOpType.ReplaceIndex.name: attrs['chunk_size'] = self._chunk_size attrs['left_context'] = self._left_context attrs['right_context'] = self._right_context if type == KaldiOpType.IfDefined.name: attrs['chunk_size'] = self._chunk_size consts = {} if type in CONSTS_NAMES: param_names = CONSTS_NAMES[type] for p_name in param_names: if p_name in component: p_values = component[p_name] p_tensor_name = name + '_' + p_name consts[p_tensor_name] = p_values inputs.append(p_tensor_name) return make_node(name, type, inputs, [name], attrs, consts)