annotation_files += annotation_val_files #Know the number steps to take before decaying the learning rate and batches per epoch num_batches_per_epoch = len(image_files) / batch_size num_steps_per_epoch = num_batches_per_epoch decay_steps = int(num_epochs_before_decay * num_steps_per_epoch) #=================CLASS WEIGHTS=============================== #Median frequency balancing class_weights if weighting == "MFB": class_weights = median_frequency_balancing() print "========= Median Frequency Balancing Class Weights =========\n", class_weights #Inverse weighing probability class weights elif weighting == "ENET": class_weights = ENet_weighing() print "========= ENet Class Weights =========\n", class_weights #============= TRAINING ================= def weighted_cross_entropy(onehot_labels, logits, class_weights): ''' A quick wrapper to compute weighted cross entropy. ------------------ Technical Details ------------------ The class_weights list can be multiplied by onehot_labels directly because the last dimension of onehot_labels is 12 and class_weights (length 12) can broadcast across that dimension, which is what we want. Then we collapse the last dimension for the class_weights to get a shape of (batch_size, height, width, 1) to get a mask with each pixel's value representing the class_weight.
if combine_dataset: image_train_files += image_val_files gt_train_files += gt_val_files # In[ ]: if weighting == 'MFB': class_weights = median_frequency_balancing(gt_train_files, num_classes=num_class) print('Median_frequency_balancing class weights is') print(class_weights) elif weighting == 'ENet': if os.path.isfile('enet_class_weights.npy'): class_weights = np.load('enet_class_weights.npy') else: class_weights = ENet_weighing(gt_train_files, num_classes=num_class) np.save('enet_class_weights.npy', class_weights) print('Save Enet_class_weights') print('ENet class weights is') #class_weights[19] = 0 print('Id Class Weight') for i in range(int(class_weights.shape[0])): print('{:2} {:15} {:>10.6}'.format(i, trainId2label[i].name, class_weights[i])) # In[ ]: def input_pipeline(image_train_files, gt_train_files, image_val_files, gt_val_files, image_size):
#Know the number steps to take before decaying the learning rate and batches per epoch num_batches_per_epoch = len(image_files) / batch_size num_steps_per_epoch = num_batches_per_epoch decay_steps = int(num_epochs_before_decay * num_steps_per_epoch) #=================CLASS WEIGHTS=============================== #Median frequency balancing class_weights if weighting == "MFB": class_weights = median_frequency_balancing(annotation_files, num_classes) print("========= Median Frequency Balancing Class Weights =========\n", class_weights) #Inverse weighing probability class weights elif weighting == "ENET": class_weights = ENet_weighing(annotation_files, num_classes) print("========= ENet Class Weights =========\n", class_weights) #============= TRAINING ================= def weighted_cross_entropy(onehot_labels, logits, class_weights): ''' A quick wrapper to compute weighted cross entropy. ------------------ Technical Details ------------------ The class_weights list can be multiplied by onehot_labels directly because the last dimension of onehot_labels is 12 and class_weights (length 12) can broadcast across that dimension, which is what we want. Then we collapse the last dimension for the class_weights to get a shape of (batch_size, height, width, 1) to get a mask with each pixel's value representing the class_weight.
decay_steps = FLAGS.decay_steps else: decay_steps = int(num_epochs_before_decay * num_steps_per_epoch) #=================CLASS WEIGHTS=============================== #Median frequency balancing class_weights if weighting == "MFB": class_weights = median_frequency_balancing(image_dir=os.path.join( dataset_dir, dataset_name, 'trainannot'), num_classes=num_classes) print "========= Median Frequency Balancing Class Weights =========\n", class_weights #Inverse weighing probability class weights elif weighting == "ENET": class_weights = ENet_weighing(image_dir=os.path.join( dataset_dir, dataset_name, 'trainannot'), num_classes=num_classes) print "========= ENet Class Weights =========\n", class_weights #Inverse weighing probability class weights elif weighting == "CVPR": class_weights = CVPR_weighing() print "========= CVPR Class Weights =========\n", class_weights #============= TRAINING ================= def weighted_cross_entropy(onehot_labels, logits, class_weights): ''' A quick wrapper to compute weighted cross entropy. ------------------