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.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_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): logits = getcnnlogit(x, outnum=5) return logits
data[i, :, :, :] = im[:, :, :] / 255.0 cc = (int(l) - 1) % ab_size label[i, cc] = 1 return data, label if __name__ == '__main__': ab_size = 3817 bs = 32 imsize = [32, 32, 3] im = tf.placeholder(tf.float32, shape=[ bs, ] + imsize) label = tf.placeholder(tf.float32, shape=[bs, ab_size]) logit = getcnnlogit(im, ab_size) cross_entropy = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits(labels=label, logits=logit)) correct_prediction = tf.equal(tf.argmax(logit, 1), tf.argmax(label, 1)) acc = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) opt = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) trainlst = [] for line in open("datalist/train.lst"): trainlst.append(line) testlst = [] for line in open("datalist/test.lst"): testlst.append(line) saver = tf.train.Saver()