# -*- coding: utf-8 -*- """ Created on Wed Sep 21 08:17:42 2022 ---------------------------------------------------------------------------------- This script split the rellis 3D dataset into train val and test folders ---------------------------------------------------------------------------------- 1. Create train, val and test folders in data/rellis folder 2. Create a new empty folder named as images and masks_id in train and val folders. 3. Create a new empty foldr named as images inside test folder. 4. Execute this script to copy images and masks_id to train folder. 5. Execute this script to copy images and masks_id to val folder. 6. Execute this script to copy images to test folder. Output: Coping images, please wait... Total number of copied images: 3302 Images stored saved in: ./train//images Coping masks_id, please wait... Total number of copied masks: 3302 Images stored saved in: ./train/masks_id Coping images, please wait... Total number of copied images: 983 Images stored saved in: ./val//images Coping masks_id, please wait... Total number of copied masks: 983 Images stored saved in: ./val/masks_id Coping images, please wait... Total number of copied images: 1672 Images stored saved in: ./test//images _----------------------------------------------------------------------------- Mask_color images to instance segmentation 1. Create train, val and test folders in data/rellis folder 2. Create a new empty folder named as images and masks_color in train and val folders. 3. Create a new empty foldr named as images inside test folder. 4. Execute this script to copy masks_colors to train folder. 5. Execute this script to copy masks_colors to val folder. 6. Execute this script to copy masks_colors to test folder. Output: Coping images, please wait... Total number of copied images: 3302 Images stored saved in: ./train//masks_colors Coping images, please wait... Total number of copied images: 983 Images stored saved in: ./val//masks_colors ''' """ import os import pandas as pd from shutil import copy def search_image(count, imagename, path, DEST_PATH): error=0 for filename in os.listdir(path): if (filename.endswith(".bmp")) and (filename.startswith(imagename)): copy(path +'/'+ filename, DEST_PATH+'/'+filename) count+=1 error=0 #print(count) break else: error=1 return count, error DEST_PATH='train' #DEST_PATH='val' #DEST_PATH='test' # Rellis 5 categories pd_card_images = pd.read_csv('train5.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('val5.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('test5.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) # Rellis 6 categories #pd_card_images = pd.read_csv('train.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('val.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('test.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) # Rellis 20 labels #pd_card_images = pd.read_csv('train20.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('val20.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('test20.csv',sep=";", names=['images','masks_id'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('test_maskcolors.csv',sep=";", names=['maskcolors'], encoding ='latin1', low_memory=False) # Rellis 20 masks_colors for instance segmentation #pd_card_images = pd.read_csv('train_color20.csv',sep=";", names=['images', 'masks_colors'], encoding ='latin1', low_memory=False) #¶pd_card_images = pd.read_csv('val_color20.csv',sep=";", names=['images', 'masks_colors'], encoding ='latin1', low_memory=False) #pd_card_images = pd.read_csv('test_color20.csv',sep=";", names=['images', 'masks_colors'], encoding ='latin1', low_memory=False) pd_card_images = pd_card_images.drop(labels=0, axis=0) rpd_card_images=pd_card_images.reset_index(drop=True) image_path=rpd_card_images['images'] mask_path=rpd_card_images['masks_id'] #maskcolors_path=rpd_card_images['masks_colors'] print('Coping images, please wait...') count=0 for im in image_path: filename = str(im).split("/") txt_filename=str(filename[1]) #print(im) copy('images/'+ im, DEST_PATH +'/images/'+txt_filename) count+=1 print('Total number of copied images: ', count) print('Images stored saved in: ', DEST_PATH+'/images') # for idx, im in enumerate(maskcolors_path): # filename = str(im).split("/") # txt_filename=str(filename[1]) # orig_image = image_path[idx] # copy('./maskscolors/' + orig_image, DEST_PATH +txt_filename) # count+=1 # print('Total number of copied images: ', count) # print('Images stored saved in: ', DEST_PATH+'/masks_colors') ## Only for train and val ************************************** print('Coping masks_id, please wait...') count=0 for mask in mask_path: filename = str(mask).split("/") txt_filename=str(filename[1]) #print(mask) copy('masks_id/'+ mask, DEST_PATH+'/masks_id/'+txt_filename) count+=1 print('Total number of copied masks: ', count) print('Images stored saved in: ', DEST_PATH+'masks_id')