mirror of
https://github.com/qurator-spk/sbb_pixelwise_segmentation.git
synced 2025-06-09 20:00:05 +02:00
rotation augmentation is provided for machine based reading order
This commit is contained in:
parent
872e5b0b3a
commit
22f82c5448
2 changed files with 27 additions and 3 deletions
5
train.py
5
train.py
|
@ -380,6 +380,9 @@ def run(_config, n_classes, n_epochs, input_height,
|
||||||
dir_flow_train_labels = os.path.join(dir_train, 'labels')
|
dir_flow_train_labels = os.path.join(dir_train, 'labels')
|
||||||
|
|
||||||
classes = os.listdir(dir_flow_train_labels)
|
classes = os.listdir(dir_flow_train_labels)
|
||||||
|
if augmentation:
|
||||||
|
num_rows = len(classes)*(len(thetha) + 1)
|
||||||
|
else:
|
||||||
num_rows = len(classes)
|
num_rows = len(classes)
|
||||||
#ls_test = os.listdir(dir_flow_train_labels)
|
#ls_test = os.listdir(dir_flow_train_labels)
|
||||||
|
|
||||||
|
@ -390,7 +393,7 @@ def run(_config, n_classes, n_epochs, input_height,
|
||||||
model.compile(loss="binary_crossentropy",
|
model.compile(loss="binary_crossentropy",
|
||||||
optimizer = opt_adam,metrics=['accuracy'])
|
optimizer = opt_adam,metrics=['accuracy'])
|
||||||
for i in range(n_epochs):
|
for i in range(n_epochs):
|
||||||
history = model.fit(generate_arrays_from_folder_reading_order(dir_flow_train_labels, dir_flow_train_imgs, n_batch, input_height, input_width, n_classes), steps_per_epoch=num_rows / n_batch, verbose=1)
|
history = model.fit(generate_arrays_from_folder_reading_order(dir_flow_train_labels, dir_flow_train_imgs, n_batch, input_height, input_width, n_classes, thetha, augmentation), steps_per_epoch=num_rows / n_batch, verbose=1)
|
||||||
model.save( os.path.join(dir_output,'model_'+str(i+indexer_start) ))
|
model.save( os.path.join(dir_output,'model_'+str(i+indexer_start) ))
|
||||||
|
|
||||||
with open(os.path.join(os.path.join(dir_output,'model_'+str(i)),"config.json"), "w") as fp:
|
with open(os.path.join(os.path.join(dir_output,'model_'+str(i)),"config.json"), "w") as fp:
|
||||||
|
|
23
utils.py
23
utils.py
|
@ -363,6 +363,11 @@ def rotation_not_90_func(img, label, thetha):
|
||||||
return rotate_max_area(img, rotated, rotated_label, thetha)
|
return rotate_max_area(img, rotated, rotated_label, thetha)
|
||||||
|
|
||||||
|
|
||||||
|
def rotation_not_90_func_single_image(img, thetha):
|
||||||
|
rotated = imutils.rotate(img, thetha)
|
||||||
|
return rotate_max_area(img, rotated, thetha)
|
||||||
|
|
||||||
|
|
||||||
def color_images(seg, n_classes):
|
def color_images(seg, n_classes):
|
||||||
ann_u = range(n_classes)
|
ann_u = range(n_classes)
|
||||||
if len(np.shape(seg)) == 3:
|
if len(np.shape(seg)) == 3:
|
||||||
|
@ -410,7 +415,7 @@ def IoU(Yi, y_predi):
|
||||||
#print("Mean IoU: {:4.3f}".format(mIoU))
|
#print("Mean IoU: {:4.3f}".format(mIoU))
|
||||||
return mIoU
|
return mIoU
|
||||||
|
|
||||||
def generate_arrays_from_folder_reading_order(classes_file_dir, modal_dir, batchsize, height, width, n_classes):
|
def generate_arrays_from_folder_reading_order(classes_file_dir, modal_dir, batchsize, height, width, n_classes, thetha, augmentation=False):
|
||||||
all_labels_files = os.listdir(classes_file_dir)
|
all_labels_files = os.listdir(classes_file_dir)
|
||||||
ret_x= np.zeros((batchsize, height, width, 3))#.astype(np.int16)
|
ret_x= np.zeros((batchsize, height, width, 3))#.astype(np.int16)
|
||||||
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||||
|
@ -434,6 +439,22 @@ def generate_arrays_from_folder_reading_order(classes_file_dir, modal_dir, batch
|
||||||
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||||
batchcount = 0
|
batchcount = 0
|
||||||
|
|
||||||
|
if augmentation:
|
||||||
|
for thetha_i in thetha:
|
||||||
|
img_rot = rotation_not_90_func_single_image(img, thetha_i)
|
||||||
|
|
||||||
|
ret_x[batchcount, :,:,0] = img_rot[:,:,0]/3.0
|
||||||
|
ret_x[batchcount, :,:,2] = img_rot[:,:,2]/3.0
|
||||||
|
ret_x[batchcount, :,:,1] = img_rot[:,:,1]/5.0
|
||||||
|
|
||||||
|
ret_y[batchcount, :] = label_class
|
||||||
|
batchcount+=1
|
||||||
|
if batchcount>=batchsize:
|
||||||
|
yield (ret_x, ret_y)
|
||||||
|
ret_x= np.zeros((batchsize, height, width, 3))#.astype(np.int16)
|
||||||
|
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||||
|
batchcount = 0
|
||||||
|
|
||||||
def data_gen(img_folder, mask_folder, batch_size, input_height, input_width, n_classes, task='segmentation'):
|
def data_gen(img_folder, mask_folder, batch_size, input_height, input_width, n_classes, task='segmentation'):
|
||||||
c = 0
|
c = 0
|
||||||
n = [f for f in os.listdir(img_folder) if not f.startswith('.')] # os.listdir(img_folder) #List of training images
|
n = [f for f in os.listdir(img_folder) if not f.startswith('.')] # os.listdir(img_folder) #List of training images
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue