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']['model']) 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) else: logits = rnn_layers(cnn_feature, sequence_len, training, layer_num = 3, hidden_num = 100, cell="SRU") #logits = cudnn_rnn(cnn_feature,rnn_layer_num) return logits,ratio
def inference(x,seq_length,training): cnn_feature = getcnnfeature(x,training = training) feashape = cnn_feature.get_shape().as_list() ratio = FLAGS.segment_len/feashape[1] # logits = rnn_layers(cnn_feature,seq_length/ratio,training,class_n = 5 ) logits = rnn_layers_one_direction(cnn_feature,seq_length/ratio,training,class_n = len(FLAGS.alphabet)+1) # logits = getcnnlogit(cnn_feature) return logits,ratio
def inference(x,seq_length,training): cnn_feature = getcnnfeature(x,training = training) feashape = cnn_feature.get_shape().as_list() ratio = FLAGS.sequence_len/feashape[1] # logits = rnn_layers(cnn_feature,seq_length/ratio,training,class_n = 4**FLAGS.k_mer+1 ) # logits = rnn_layers_one_direction(cnn_feature,seq_length/ratio,training,class_n = 4**FLAGS.k_mer+1 ) logits = getcnnlogit(cnn_feature) return logits,ratio
def inference(x,seq_length,training): cnn_feature = getcnnfeature(x,training = training) feashape = cnn_feature.get_shape().as_list() ratio = FLAGS.segment_len/feashape[1] logits = rnn_layers(cnn_feature, tf.cast(tf.truediv(tf.cast(seq_length, tf.float32),ratio), tf.int32),training,class_n = 5 ) # logits = rnn_layers_one_direction(cnn_feature,seq_length/ratio,training,class_n = 4**FLAGS.k_mer+1 ) # logits = getcnnlogit(cnn_feature) return logits,ratio
def inference(im): ab_size = 3851 #bs = 1 #imsize = [32,1024,3] #im = tf.placeholder(tf.float32,shape=[bs,]+imsize) #targetIxs = tf.placeholder(tf.int64) #targetVals = tf.placeholder(tf.int32) #targetShape = [bs,20]#tf.placeholder(tf.int64) #gt_label = tf.SparseTensor(targetIxs, targetVals, targetShape) fea = getcnnfeature(im) shape = tf.shape(fea) n = 1 #shape[0] h = 2 #shape[1] w = 1024 / 16 #w = shape[2] c = 512 #shape[3] fea = tf.transpose(fea, [2, 0, 1, 3]) fea = tf.reshape(fea, [w, n, h * c]) print(w) feas = [tf.squeeze(t, [0]) for t in tf.split(fea, w)] print(len(feas)) feass = [] for i in range(len(feas) - 1): tt = tf.concat([feas[i], feas[i + 1]], axis=1) feass.append(tt) W = tf.get_variable("logit_weights", shape=[h * h * c, ab_size], initializer=tf.contrib.layers.xavier_initializer()) B = tf.get_variable("logit_bias", shape=[ab_size], initializer=tf.contrib.layers.xavier_initializer()) logits = [tf.matmul(t, W) + B for t in feass] #print len(logits) logits3d = tf.stack(logits) print(logits3d.get_shape().as_list()) #logits3d = tf.transpose(logits3d,[1,0,2]) #logits3d = tf.multiply(fea,W) + B seqLengths = [w - 1] #tf.placeholder(tf.int32) predictions = tf.to_int32( tf.nn.ctc_beam_search_decoder(logits3d, seqLengths, merge_repeated=False)[0][0]) return predictions.values
def inference(x, seq_len, training): """Infer a logits of the input signal batch. Args: x: Tensor of shape [batch_size, max_time], a batch of the input signal with a maximum length `max_time`. seq_len: Scalar float, the maximum length of the sample in the batch. training: Placeholder of Boolean, Ture if the inference is during training. 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 = seq_len / feashape[1] logits = getcnnlogit(cnn_feature) return logits, ratio
def inference(x,sequence_len,training): cnn_feature = getcnnfeature(x,training = training) feashape = cnn_feature.get_shape().as_list() ratio = sequence_len/feashape[1] logits = getcnnlogit(cnn_feature) return logits,ratio
def inference(x, seq_length, training): cnn_feature = getcnnfeature(x, training=training) feashape = cnn_feature.get_shape().as_list() ratio = FLAGS.sequence_len/feashape[1] logits = rnn_layers(cnn_feature, seq_length, training) return logits, ratio
for w in open("all_class_random.txt"): word_dict.append(w.strip().decode('utf-8')) if __name__ == '__main__': ab_size = 3817 bs = 1 imsize = [32, 1024, 3] im = tf.placeholder(tf.float32, shape=[ bs, ] + imsize) targetIxs = tf.placeholder(tf.int64) targetVals = tf.placeholder(tf.int32) targetShape = [bs, 20] #tf.placeholder(tf.int64) gt_label = tf.SparseTensor(targetIxs, targetVals, targetShape) fea = getcnnfeature(im) n, h, w, c = fea.get_shape().as_list() fea = tf.transpose(fea, [2, 0, 1, 3]) fea = tf.reshape(fea, [w, n, h * c]) feas = [tf.squeeze(t, [0]) for t in tf.split(fea, [ 1, ] * w)] #feass = [] #for i in range(len(feas)-1): # tt = tf.concat([feas[i],feas[i+1]],axis=1) # feass.append(tt) W = tf.get_variable("logits_weights", shape=[h * c, ab_size], initializer=tf.contrib.layers.xavier_initializer())
def inference(x, seq_length, training): cnn_feature = getcnnfeature(x, training=training) logits = rnn_layers(cnn_feature, seq_length, training) return logits