|
|
|
"""
|
|
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
|
|
|
|
break
|
|
else:
|
|
error=1
|
|
return count, error
|
|
|
|
|
|
DEST_PATH='train'
|
|
|
|
|
|
|
|
|
|
pd_card_images = pd.read_csv('train5.csv',sep=";", names=['images','masks_id'], 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']
|
|
|
|
|
|
print('Coping images, please wait...')
|
|
count=0
|
|
|
|
for im in image_path:
|
|
filename = str(im).split("/")
|
|
txt_filename=str(filename[1])
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Coping masks_id, please wait...')
|
|
count=0
|
|
for mask in mask_path:
|
|
filename = str(mask).split("/")
|
|
txt_filename=str(filename[1])
|
|
|
|
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')
|
|
|
|
|