import os.path as osp import numpy as np import mmcv, os # import cv2 #from PIL import Image ''' -------------------------------------------------------------------------------- This script modifies the original Rellis 3D dataset from 20 labels to 5 labels # Original classes # Labels ID = ["void", "dirt", "grass", "tree", "pole", "water", "sky", "vehicle", # "object", "asphalt", "building", "log", "person", "fence", "bush", # "concrete", "barrier", "puddle", "mud", "rubble"] # Grouped classes # New IDs # 0 -- background: void, sky # 1 -- obstacle: tree, bush, person, rubble, barrier, log, fence, vehicle, object, pole, building # 2 -- withwater: mud, puddle, water # 3 -- unstable: grass, dirt # 4 -- stable: concrete, asphalt -------------------------------------------------------------------------------- Python environment requirements install: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html Download original Rellis 3D: - RGB images: Rellis_3D_pylon_camera_node.zip (11GB) Link: https://drive.google.com/file/d/1F3Leu0H_m6aPVpZITragfreO_SGtL2yV/view - ID Masks : Rellis_3D_pylon_camera_node_label_id.zip (117MB) Link: https://drive.google.com/file/d/16URBUQn_VOGvUqfms-0I8HHKMtjPHsu5/view 1. Create the following folders in data/rellis folder - image - masks_id 2. Copy Rellis_3D_pylon_camera_node.zip in data/rellis/images folder 3. Copy Rellis_3D_pylon_camera_node_label_id.zip in data/rellis/masks_id folder 4. Rellis_3D_pylon_camera_node_label_color.zip (not used in GanAV model) 5. Unzip Rellis_3D_pylon_camera_node.zip in the data/rellis/images folder - data/rellis/images/Rellis-3D\00000 - data/rellis/images/Rellis-3D\00001 ... 6. Move the content of data/rellis/images/Rellis-3D folder to data/rellis/images folder 7. Delete Rellis-3D folder (data/rellis/images/Rellis-3D) 8. Unzip Rellis_3D_pylon_camera_node_label_id.zip in the data/rellis/masks_id folder - data/rellis/masks_id/Rellis-3D\00000 - data/rellis/masks_id/Rellis-3D\00001 ... 9. Move the content of data/rellis/masks_id/Rellis-3D folder to data/rellis/masks_id folder 10. Delete Rellis-3D folder (data/rellis/masks_id/Rellis-3D) 11. Detele zip files 12. Copy the files inside the each pylon_camera_node_label_id folder of masks_id folder to masks_id/0000x folder 13. Delete all empty pylon_camera_node_label_id folders ''' rellis_dir=os.getcwd() #rellis_dir = "./rellis/" annotation_folder = "/Rellis-3D/masks_id/" IDs = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 17, 18, 19, 23, 27, 31, 33, 34] Groups = (0, 3, 3, 1, 1, 2, 0, 1, 1, 4, 1, 1, 1, 1, 1, 4, 1, 2, 2, 1) ID_seq = {} ID_group = {} for n, label in enumerate(IDs): ID_seq[label] = n ID_group[label] = Groups[n] def raw_to_seq(seg): h, w = seg.shape out1 = np.zeros((h, w)) out2 = np.zeros((h, w)) for i in IDs: out1[seg==i] = ID_seq[i] out2[seg==i] = ID_group[i] return out1, out2 with open(osp.join(rellis_dir, 'train.txt'), 'r') as r: i = 0 for l in r: print("train: {}".format(i)) # w.writelines(l[:-5] + "\n") # w.writelines(l.split(".")[0] + "\n") file_client_args=dict(backend='disk') file_client = mmcv.FileClient(**file_client_args) img_bytes = file_client.get(rellis_dir + annotation_folder + l.strip() + '.png') gt_semantic_seg = mmcv.imfrombytes(img_bytes, flag='unchanged', backend='pillow').squeeze().astype(np.uint8) out1, out2 = raw_to_seq(gt_semantic_seg) #mmcv.imwrite(out1, rellis_dir + annotation_folder + l.strip() + "_orig.png") mmcv.imwrite(out2, rellis_dir + annotation_folder + l.strip() + "_5.png") i += 1 with open(osp.join(rellis_dir, 'val.txt'), 'r') as r: i = 0 for l in r: print("val: {}".format(i)) # w.writelines(l[:-5] + "\n") # w.writelines(l.split(".")[0] + "\n") file_client_args=dict(backend='disk') file_client = mmcv.FileClient(**file_client_args) img_bytes = file_client.get(rellis_dir + annotation_folder + l.strip() + '.png') gt_semantic_seg = mmcv.imfrombytes(img_bytes, flag='unchanged', backend='pillow').squeeze().astype(np.uint8) out1, out2 = raw_to_seq(gt_semantic_seg) #mmcv.imwrite(out1, rellis_dir + annotation_folder + l.strip() + "_orig.png") mmcv.imwrite(out2, rellis_dir + annotation_folder + l.strip() + "_5.png") i += 1 with open(osp.join(rellis_dir, 'test.txt'), 'r') as r: i = 0 for l in r: print("test: {}".format(i)) # w.writelines(l[:-5] + "\n") # w.writelines(l.split(".")[0] + "\n") file_client_args=dict(backend='disk') file_client = mmcv.FileClient(**file_client_args) img_bytes = file_client.get(rellis_dir + annotation_folder + l.strip() + '.png') gt_semantic_seg = mmcv.imfrombytes(img_bytes, flag='unchanged', backend='pillow').squeeze().astype(np.uint8) out1, out2 = raw_to_seq(gt_semantic_seg) #mmcv.imwrite(out1, rellis_dir + annotation_folder + l.strip() + "_orig.png") mmcv.imwrite(out2, rellis_dir + annotation_folder + l.strip() + "_5.png") i += 1 print("successful")