def convert_model(master_spec, sess): # Create flow. flow = Flow() builder = FlowBuilder(sess, flow) # Get components. components = [] connectors = {} for c in master_spec.component: component = Component(c, builder, connectors) components.append(component) # Extract components. for c in components: c.extract() # Sanitize names. for c in components: flow.rename_prefix(c.path() + "/", c.name + "/") flow.rename_suffix("/ExponentialMovingAverage:0", "") flow.rename_suffix(LSTM_H_IN + ":0", "h_in") flow.rename_suffix(LSTM_H_OUT + ":0", "h_out") flow.rename_suffix(LSTM_C_IN + ":0", "c_in") flow.rename_suffix(LSTM_C_OUT + ":0", "c_out") flow.rename_suffix(FF_HIDDEN + ":0", "hidden") flow.rename_suffix(FF_OUTPUT + ":0", "output") # Get external resources. lexicon_file = None commons_file = None actions_file = None for c in master_spec.component: for r in c.resource: if r.name == "word-vocab": lexicon_file = r.part[0].file_pattern elif r.name == "commons": commons_file = r.part[0].file_pattern elif r.name == "action-table": actions_file = r.part[0].file_pattern # Add lexicon to flow. if lexicon_file != None: lexicon = flow.blob("lexicon") lexicon.type = "dict" lexicon.add_attr("delimiter", 10) lexicon.add_attr("oov", 0) lexicon.add_attr("normalize_digits", 1) lexicon.data = read_file(lexicon_file) # Add commons to flow. if commons_file != None: commons = flow.blob("commons") commons.type = "frames" commons.data = read_file(commons_file) # Add action table to flow. if actions_file != None: actions = flow.blob("actions") actions.type = "frames" actions.data = read_file(actions_file) return flow
def convert_model(master_spec, sess): # Create flow. flow = Flow() builder = FlowBuilder(sess, flow) # Get components. components = [] connectors = {} for c in master_spec.component: component = Component(c, builder, connectors) components.append(component) # Extract components. for c in components: c.extract() # Sanitize names. for c in components: flow.rename_prefix(c.path() + "/", c.name + "/") flow.rename_suffix("/ExponentialMovingAverage:0", "") flow.rename_suffix(LSTM_H_IN + ":0", "h_in") flow.rename_suffix(LSTM_H_OUT + ":0", "h_out") flow.rename_suffix(LSTM_C_IN + ":0", "c_in") flow.rename_suffix(LSTM_C_OUT + ":0", "c_out") flow.rename_suffix(FF_HIDDEN + ":0", "hidden") flow.rename_suffix(FF_OUTPUT + ":0", "output") # Get external resources. lexicon_file = None prefix_file = None suffix_file = None commons_file = None actions_file = None for c in master_spec.component: for r in c.resource: if r.name == "word-vocab": lexicon_file = r.part[0].file_pattern elif r.name == "prefix-table": prefix_file = r.part[0].file_pattern elif r.name == "suffix-table": suffix_file = r.part[0].file_pattern elif r.name == "commons": commons_file = r.part[0].file_pattern elif r.name == "action-table": actions_file = r.part[0].file_pattern # Add lexicon to flow. if lexicon_file != None: lexicon = flow.blob("lexicon") lexicon.type = "dict" lexicon.add_attr("delimiter", 10) lexicon.add_attr("oov", 0) lexicon.add_attr("normalize_digits", 1) lexicon.data = read_file(lexicon_file) # Add prefix table to flow. if prefix_file != None: prefixes = flow.blob("prefixes") prefixes.type = "affix" prefixes.data = read_file(prefix_file) # Add suffix table to flow. if suffix_file != None: suffixes = flow.blob("suffixes") suffixes.type = "affix" suffixes.data = read_file(suffix_file) # Add commons to flow. if commons_file != None: commons = flow.blob("commons") commons.type = "frames" commons.data = read_file(commons_file) # Add action table to flow. if actions_file != None: actions = flow.blob("actions") actions.type = "frames" actions.data = read_file(actions_file) return flow