Esempio n. 1
0
train_input_names, train_output_names, val_input_names, val_output_names, test_input_names, test_output_names = prepare_data(
)

class_names_list = helpers.get_class_list(
    os.path.join(args.dataset, "class_list.txt"))
class_names_string = ""
for class_name in class_names_list:
    if not class_name == class_names_list[-1]:
        class_names_string = class_names_string + class_name + ", "
    else:
        class_names_string = class_names_string + class_name

num_classes = len(class_names_list)

if args.balanced_weight:
    b_weight = utils.median_frequency_balancing(
        args.dataset + "/train_labels/", num_classes)

print("Preparing the model ...")
input = tf.placeholder(tf.float32, shape=[None, None, None, 3])
output = tf.placeholder(tf.float32, shape=[None, None, None, num_classes])

with tf.device('/gpu:' + str(args.gpu)):
    input = tf.placeholder(tf.float32, shape=[None, None, None, 3])
    output = tf.placeholder(tf.float32, shape=[None, None, None, num_classes])

    if args.model == "FC-DenseNet56" or args.model == "FC-DenseNet67" or args.model == "FC-DenseNet103" or args.model == "FC-DenseNet158" or args.model == "FC-DenseNet232":
        network = build_fc_densenet(input,
                                    preset_model=args.model,
                                    num_classes=num_classes,
                                    dropout_p=0.5)
    elif args.model == "RefineNet-Res101" or args.model == "RefineNet-Res152":
Esempio n. 2
0
import cv2 as cv
import utils

map_data_dir = 'CamVid/train_labels/'
map_weihgt_dir = 'CamVid/train_labels_weights/'
if os.path.exists(map_weihgt_dir):
    shutil.rmtree(map_weihgt_dir)
os.makedirs(map_weihgt_dir)

# get filenames
map_fns = np.asarray(sorted(glob.glob('%s/*.png*' % map_data_dir)))

n_all_files = len(map_fns)
print 'n_all_files:', n_all_files

balance_weight, cls_freq = utils.median_frequency_balancing(
    'CamVid/train_labels/')

for map_fn in map_fns:
    print map_weihgt_dir + os.path.basename(map_fn).split('.')[0] + '.png'
    map_im = cv.imread(map_fn, cv.IMREAD_GRAYSCALE)
    # _, binary = cv.threshold(11-map_im, 0, 255, cv.THRESH_BINARY)
    # canny = cv.Canny(binary, 60, 0, apertureSize = 3)
    # _,contours,_ = cv.findContours(canny, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
    # blank = np.ones(map_im.shape)
    # cv.drawContours(blank, contours, -1, 5, 1)
    # pixel_weight = blank+2*(binary/255)
    pixel_weight = np.empty(map_im.shape, dtype='float32')
    for c in range(len(cls_freq)):
        if c != 12:
            pixel_weight[map_im == c] = max(2, 1 / cls_freq[c])
        else:
Esempio n. 3
0
    "FC-DenseNet56", "FC-DenseNet67", "FC-DenseNet103", "FC-DenseNet158",
    "Encoder-Decoder", "Encoder-Decoder-Skip", "RefineNet-Res101",
    "RefineNet-Res152", "HF-FCN", "custom"
]
if args.model not in AVAILABLE_MODELS:
    print("Error: given model is not available. Try these:")
    print(AVAILABLE_MODELS)
    print("Now exiting ...")
    sys.exit()

# Load the data
print("Loading the data ...")
train_input_names, train_output_names, val_input_names, val_output_names, test_input_names, test_output_names = prepare_data(
)
if args.balanced_weight:
    balanced_weight = utils.median_frequency_balancing(args.dataset +
                                                       "/train_labels/")

class_names_list = helpers.get_class_list(
    os.path.join(args.dataset, "class_list.txt"))
class_names_string = ""
for class_name in class_names_list:
    if not class_name == class_names_list[-1]:
        class_names_string = class_names_string + class_name + ", "
    else:
        class_names_string = class_names_string + class_name

# num_classes = len(class_names_list)
num_classes = 1

print("Preparing the model ...")
input = tf.placeholder(tf.float32, shape=[None, None, None, 3])
Esempio n. 4
0
print("Loading the data ...")
train_input_names, train_output_names, val_input_names, val_output_names, test_input_names, test_output_names = prepare_data(
)

class_names_list = helpers.get_class_list(
    os.path.join(args.dataset, "class_list.txt"))
class_names_string = ""
for class_name in class_names_list:
    if not class_name == class_names_list[-1]:
        class_names_string = class_names_string + class_name + ", "
    else:
        class_names_string = class_names_string + class_name
num_classes = len(class_names_list)

if args.balanced_weight:
    b_weight = utils.median_frequency_balancing(args.dataset + "/../gts_numpy",
                                                num_classes)
    print('b_weight: ', b_weight)

print("Preparing the model ...")
input = tf.placeholder(tf.float32, shape=[None, None, None, 3])
output = tf.placeholder(tf.float32, shape=[None, None, None, num_classes])

with tf.device('/gpu:' + str(args.gpu)):
    input = tf.placeholder(tf.float32, shape=[None, None, None, 3])
    output = tf.placeholder(tf.float32, shape=[None, None, None, num_classes])

    if args.model == "FC-DenseNet56" or args.model == "FC-DenseNet67" or args.model == "FC-DenseNet103" or args.model == "FC-DenseNet158" or args.model == "FC-DenseNet232":
        network = build_fc_densenet(input,
                                    preset_model=args.model,
                                    num_classes=num_classes)
    elif args.model == "RefineNet-Res101" or args.model == "RefineNet-Res152":