def convert2model(model_config): if 'name' not in model_config: raise ValueError("config is not a model config!") name = model_config['name'] or '' if name.startswith('model'): model = Model.from_config(model_config) elif name.startswith('sequential'): model = Sequential.from_config(model_config) else: raise ValueError("model config incorrect!") return model
def __add_sequence_layer(self, layer): """序列模型,上一层输入只有一个模型""" model_config = {} if self.model_rdd: model_config = json.loads(self.model_rdd.first().model_config) self.layer_num += len(model_config.get('layers', [])) model = Sequential.from_config(model_config) model.add(layer) self.layer_num += 1 return self.model2df(model)
def build_model(self): if self.task_index is None: raise ValueError("task_index cannot None!!!") with tf.device( tf.train.replica_device_setter( worker_device="/job:worker/task:{}".format( self.task_index), cluster=self.cluster)): model_type = gmt(self.model_config) if model_type == ModelType.SEQUENCE: model = Sequential.from_config(self.model_config) elif model_type == ModelType.NETWORK: model = Model.from_config(self.model_config) else: raise ValueError( "{}, unknown model type!!!".format(model_type)) self.parse_optimizer() model.compile(**self.compile_config) self.model = model
def run(self): params = self.params name = params.get('name') model_rdd = inputRDD(name) if not model_rdd: raise ValueError("In Summary model_rdd cannot be empty!") model_config = json.loads(model_rdd.first().model_config) # model_name = model_config.get('name') if get_mode_type(model_rdd) == ModelType.SEQUENCE: model = Sequential.from_config(model_config) elif get_mode_type(model_rdd) == ModelType.NETWORK: model = Model.from_config(model_config) else: raise ValueError("model type incorrect!!!") model.summary() outputRDD('<#zzjzRddName#>_Summary', model_rdd)
def add(self, start_rdd, repeats=0): if MODEL_CONFIG not in self.model_rdd.first(): raise ValueError('repeat units end node not exists model_config!') model_config = json.loads(getattr(self.model_rdd.first(), MODEL_CONFIG)) start_config = json.loads(getattr(start_rdd.first(), MODEL_CONFIG)) marker_layer = start_config['layers'][-1] for index, layer in enumerate(model_config['layers']): if marker_layer == layer: layers = model_config['layers'][index + 1:] if 'inbound_nodes' in layer: self.model = Model.from_config(model_config) self.repeat_networks(layers, repeats) elif 'name' in layer['config']: self.model = Sequential.from_config(model_config) self.repeat_sequence(layers, repeats) else: raise ValueError( "In RepeatBlock node, model type incorrect!") return self.model2df(self.model)