val_files = pfiles[-validation_num:] else: print("No test data") exit() if not os.access(vision_path, os.F_OK): os.makedirs(vision_path) if os.access(evaluation_path, os.F_OK): shutil.rmtree(evaluation_path) os.makedirs(evaluation_path) x = tf.placeholder(tf.float32, [None, REGION_SIZE, REGION_SIZE, REGION_SIZE]) x_image = tf.reshape(x, [-1, REGION_SIZE, REGION_SIZE, REGION_SIZE, 1]) bn_params = np.load(bn_file) outputs, _, _ = tft.volume_bndo_flbias_l6_40(x_image, dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params) prediction_out = outputs['sm_out'] saver = tf.train.Saver() config = tf.ConfigProto() config.gpu_options.allow_growth = True sess = tf.Session(config=config) saver.restore(sess, net_file) #ktb.set_session(mt.get_session(0.5)) start_time = time.time() #patient_evaluations = open(evaluation_path + "/patient_evaluations.log", "w") results = [] CPMs = [] CPMs2 = [] test_patients = all_patients[:1] bt.filelist_store(all_patients, evaluation_path + "/patientfilelist.log")
] else: bn_params = [None, None, None] outputs0, variables0, _ = tft.volume_bndo_flbias_l5_20( inputs_reshape[0], dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[0]) outputs1, variables1, _ = tft.volume_bndo_flbias_l5_30( inputs_reshape[1], dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[1]) outputs2, variables2, _ = tft.volume_bndo_flbias_l6_40( inputs_reshape[2], dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[2]) if FUSION_MODE == 'vote': predictions = [ outputs0['sm_out'], outputs1['sm_out'], outputs2['sm_out'] ] combined_prediction = tft.vote_fusion(predictions) combined_prediction = tf.reshape(combined_prediction, [-1, 1]) elif FUSION_MODE == 'committe': predictions = [ outputs0['sm_out'], outputs1['sm_out'], outputs2['sm_out'] ] combined_prediction = tft.committe_fusion(predictions) elif FUSION_MODE == 'late': features = [
#negative_importances = 1000*np.ones(shape=[num_negative], dtype=float) #net construct volume_input = tf.placeholder(tf.float32, [None, REGION_SIZE, REGION_SIZE, REGION_SIZE]) volume_reshape = tf.reshape(volume_input, [-1, REGION_SIZE, REGION_SIZE, REGION_SIZE, 1]) real_label = tf.placeholder(tf.float32, [None, 2]) #r_bn1, b_bn1, w_conv1, w_conv2, out_conv1, out_bn1, hidden_conv1, hidden_conv2, hidden_conv3, out_fc1, out_fc2, softmax_out = tft.volume_bnnet2_l6_56(volume_reshape) #bn_params = np.load(net_init_path + "/batch_normalization_statistic.npy") positive_confidence = num_positive_aug / float(num_positive_aug + num_positive * np_proportion) net_outs, _, bn_params = tft.volume_bndo_flbias_l6_40( volume_reshape, True, positive_confidence, dropout_rate=0.0, batch_normalization_statistic=True, bn_params=None) cross_entropy = tf.nn.softmax_cross_entropy_with_logits( logits=net_outs['last_out'], labels=real_label) balancing = real_label[:, 0] + tf.pow(tf.constant(-1, dtype=tf.float32), real_label[:, 0]) * tf.constant( positive_confidence, tf.float32) modulation = tf.pow( real_label[:, 0] + tf.pow(tf.constant(-1, dtype=tf.float32), real_label[:, 0]) * net_outs['sm_out'][:, 0], tf.constant(2, dtype=tf.float32)) focal_loss = modulation * balancing * cross_entropy batch_loss = tf.reduce_mean(focal_loss) correct_prediction = tf.equal(tf.argmax(net_outs['sm_out'], 1),
False, positive_confidence, dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[0]) net_outs1, variables1, _ = tft.volume_bndo_flbias_l5_30( volumes_reshape[1], False, positive_confidence, dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[1]) net_outs2, variables2, _ = tft.volume_bndo_flbias_l6_40( volumes_reshape[2], False, positive_confidence, dropout_rate=0.0, batch_normalization_statistic=False, bn_params=bn_params[2]) features = [ net_outs0['flattened_out'], net_outs1['flattened_out'], net_outs2['fc1_out'] ] net_out, sm_out, fusion_variables = tft.late_fusion(features, True, positive_confidence) loss = tf.nn.softmax_cross_entropy_with_logits(logits=net_out, labels=real_label) if type(LOSS_BALANCING) == float: balancing_factor = LOSS_BALANCING else: balancing_factor = positive_confidence