Skip to content

Instantly share code, notes, and snippets.

@ayooshkathuria
Last active January 18, 2020 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayooshkathuria/ef84d955e301fe9f1e4828f9e4c8ecd4 to your computer and use it in GitHub Desktop.
Save ayooshkathuria/ef84d955e301fe9f1e4828f9e4c8ecd4 to your computer and use it in GitHub Desktop.
Partition CamVid Data for GauGAN
import os
from shutil import copy
import random
from tqdm import tqdm
partition_percentage = 90
annotations_dir = 'GauGAN_Annotations'
annotations_files = os.listdir(annotations_dir)
annotations_files = [os.path.join(os.path.realpath("."), annotations_dir, x) for x in annotations_files]
train_labels = random.sample(annotations_files, int(partition_percentage / 100 * len(annotations_files)))
test_labels = [x for x in annotations_files if x not in train_labels]
train_images = [x.replace(annotations_dir, '701_StillsRaw_full').replace("_L", "") for x in train_labels]
test_images = [x.replace(annotations_dir, '701_StillsRaw_full').replace("_L", "") for x in test_labels]
for file in tqdm(train_labels):
src = file
dst = file.replace(annotations_dir, 'train_label').replace("_L", "")
copy(src, dst)
for file in tqdm(test_labels):
src = file
dst = file.replace(annotations_dir, 'test_label').replace("_L", "")
copy(src, dst)
for file in tqdm(train_images):
src = file
dst = file.replace('701_StillsRaw_full', 'train_img')
copy(src, dst)
for file in tqdm(test_images):
src = file
dst = file.replace('701_StillsRaw_full', 'test_img')
copy(src, dst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment