File size: 5,864 Bytes
d2d323b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# -*- 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')
|