예제 #1
0
파일: MENet.py 프로젝트: YoungBim/MENet
 def compute_class_weight(self, annotation_files):
     # =================CLASS WEIGHTS===============================
     # Median frequency balancing class_weights
     if self.opt.weighting == "MFB":
         self.class_weights = median_frequency_balancing(annotation_files["segmentation"])
     # Inverse weighing probability class weights
     elif self.opt.weighting == "ENET":
         self.class_weights = ENet_weigthing(annotation_files["segmentation"])
예제 #2
0
    for file in os.listdir(dataset_dir + "/valannot") if file.endswith('.png')
])

if combine_dataset:
    image_files += image_val_files
    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
예제 #3
0
    for file in os.listdir(dataset_dir + "/valannot") if file.endswith('.png')
])

if combine_dataset:
    image_files += image_val_files
    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(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.

    ------------------
예제 #4
0
gt_val_files = sorted(gt_val_files)
print('Read {} validation images.'.format(len(image_val_files)))
print('Read {} validation groudtruth lables.'.format(len(gt_val_files)))
assert len(image_val_files) == len(gt_val_files)

epochs = 100
# In[ ]:

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,
예제 #5
0
    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

if (FLAGS.decay_steps > 0):
    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