def __init__(self, model_conf: ModelConfig, mode: RunMode, outputs): self.model_conf = model_conf self.utils = NetworkUtils(mode) self.max_label_num = self.model_conf.max_label_num if self.max_label_num == -1: exception( text= "The scene must set the maximum number of label (MaxLabelNum)", code=-998) self.category_num = self.model_conf.category_num flatten = tf.keras.layers.Flatten()(outputs) shape_list = flatten.get_shape().as_list() # print(shape_list[1], self.max_label_num) outputs = tf.keras.layers.Reshape( [self.max_label_num, int(shape_list[1] / self.max_label_num)])(flatten) self.outputs = tf.keras.layers.Dense( input_shape=outputs.shape, units=self.category_num, )(inputs=outputs) print("output to reshape ----------- ", self.outputs.shape) self.outputs = tf.keras.layers.Reshape( [self.max_label_num, self.category_num])(self.outputs)
def __init__(self, model_conf: ModelConfig, mode: RunMode, backbone: CNNNetwork, recurrent: RecurrentNetwork): """ :param model_conf: 模型配置 :param mode: 运行模式 (Trains/Validation/Predict) :param backbone: :param recurrent: """ self.model_conf = model_conf self.decoder = Decoder(self.model_conf) self.mode = mode self.network = backbone self.recurrent = recurrent self.inputs = tf.keras.Input(dtype=tf.float32, shape=self.input_shape, name='input') self.labels = tf.keras.Input(dtype=tf.int32, shape=[None], sparse=True, name='labels') self.utils = NetworkUtils(mode) self.merged_summary = None self.optimizer = None self.dataset_size = None
def __init__(self, model_conf: ModelConfig, mode: RunMode, cnn: CNNNetwork, recurrent: RecurrentNetwork): """ :param model_conf: 模型配置 :param mode: 运行模式 (Trains/Validation/Predict), 其实[Validation]是没有真正被使用的,验证集使用的是[Trains]模式 对于静态图可以定义一个占位符[is_training]通过Feed值来实现这种控制, 但是预测 :param cnn: :param recurrent: """ self.model_conf = model_conf self.decoder = Decoder(self.model_conf) self.mode = mode self.network = cnn self.recurrent = recurrent self.inputs = tf.keras.Input(dtype=tf.float32, shape=self.input_shape, name='input') self.labels = tf.keras.Input(dtype=tf.int32, shape=[None], sparse=True, name='labels') self.utils = NetworkUtils(mode) self.merged_summary = None self.optimizer = None
def __init__(self, mode, cnn: CNNNetwork, recurrent: RecurrentNetwork): self.mode = mode self.utils = NetworkUtils(mode) self.network = cnn self.recurrent = recurrent self.inputs = tf.placeholder(tf.float32, [None, None, RESIZE[1], IMAGE_CHANNEL], name='input') self.labels = tf.sparse_placeholder(tf.int32, name='labels') self.seq_len = None self.merged_summary = None
def __init__(self, model_conf: ModelConfig, mode: RunMode, cnn: CNNNetwork, recurrent: RecurrentNetwork): self.model_conf = model_conf self.mode = mode self.decoder = Decoder(self.model_conf) self.utils = NetworkUtils(mode) self.network = cnn self.recurrent = recurrent self.inputs = tf.keras.Input(dtype=tf.float32, shape=self.input_shape, name='input') self.labels = tf.keras.Input(dtype=tf.int32, shape=[None], sparse=True, name='labels') self.merged_summary = None
def __init__(self, model_conf: ModelConfig, mode: RunMode, outputs): self.model_conf = model_conf self.utils = NetworkUtils(mode) self.dense = tf.keras.layers.Dense( units=self.model_conf.category_num + 2, kernel_initializer=tf.keras.initializers.he_normal(seed=None), bias_initializer='zeros', ) self.outputs = self.dense(outputs) self.predict = tf.keras.backend.permute_dimensions(self.outputs, pattern=(1, 0, 2))
def __init__(self, model_conf: ModelConfig, mode: RunMode, outputs): self.model_conf = model_conf self.utils = NetworkUtils(mode) self.dense = tf.keras.layers.Dense( units=self.model_conf.category_num + 2, kernel_initializer=tf.keras.initializers.he_normal(seed=None), kernel_regularizer=l1_l2(l1=0.01, l2=0.001), bias_initializer='zeros', ) self.time_distributed = lambda: tf.keras.layers.TimeDistributed( layer=self.dense, name='predict', )(inputs=outputs, training=self.utils.training) self.outputs = self.time_distributed() self.predict = tf.keras.backend.permute_dimensions(self.outputs, pattern=(1, 0, 2))