def inference(x, sequence_len, training, full_sequence_len, rnn_layer_num=3): """Infer a logits of the input signal batch. Args: x: Tensor of shape [batch_size, max_time,channel], a batch of the input signal with a maximum length `max_time`. sequence_len: Tensor of shape [batch_size], given the real lenghs of the segments. training: Placeholder of Boolean, Ture if the inference is during training. full_sequence_len: Scalar float, the maximum length of the sample in the batch. rnn_layer_num:Scalar Int, default is 3, the number of layer of RNN in the network. Returns: logits: Tensor of shape [batch_size, max_time, class_num] ratio: Scalar float, the scale factor between the output logits and the input maximum length. """ cnn_feature = getcnnfeature(x, training=training) feashape = cnn_feature.get_shape().as_list() ratio = full_sequence_len / feashape[1] if rnn_layer_num == 0: logits = getcnnlogit(cnn_feature) else: logits = rnn_layers(cnn_feature, sequence_len, training, layer_num=rnn_layer_num) #logits = cudnn_rnn(cnn_feature,rnn_layer_num) return logits, ratio
def inference(x, sequence_len, training, full_sequence_len, configure, apply_ratio=False): """Infer a logits of the input signal batch. Args: x: Tensor of shape [batch_size, max_time,channel], a batch of the input signal with a maximum length `max_time`. sequence_len: Tensor of shape [batch_size], given the real lenghs of the segments. training: Placeholder of Boolean, Ture if the inference is during training. full_sequence_len: Scalar float, the maximum length of the sample in the batch. configure:Model configuration. apply_ratio: If apply the ration to the sequence_len or not. Returns: logits: Tensor of shape [batch_size, max_time, class_num] ratio: Scalar float, the scale factor between the output logits and the input maximum length. """ cnn_feature = getcnnfeature(x, training=training, cnn_config=configure['cnn']) feashape = cnn_feature.get_shape().as_list() ratio = full_sequence_len / feashape[1] if apply_ratio: sequence_len = tf.cast( tf.ceil(tf.cast(sequence_len, tf.float32) / ratio), tf.int32) if configure['rnn']['layer_num'] == 0: logits = getcnnlogit(cnn_feature) elif configure['rnn']['layer_type'] == 'rna': logits = rnn_layers_rna(cnn_feature, sequence_len, training, layer_num=configure['rnn']['layer_num'], hidden_num=configure['rnn']['hidden_num'], cell=configure['rnn']['cell_type']) else: logits = rnn_layers(cnn_feature, sequence_len, training, layer_num=configure['rnn']['layer_num'], hidden_num=configure['rnn']['hidden_num'], cell=configure['rnn']['cell_type']) #logits = cudnn_rnn(cnn_feature,rnn_layer_num) return logits, ratio