-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_groups.py
35 lines (27 loc) · 978 Bytes
/
create_groups.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 17 09:04:33 2022
@author: cyrilvallez
"""
# =============================================================================
# Divides the datasets into two subfolders randomly
# =============================================================================
import random
# Set the seed
random.seed(256)
import shutil
import os
source_dir = 'Datasets/ILSVRC2012_img_val'
target_dir1 = 'Datasets/ILSVRC2012_img_val/Experimental'
target_dir2 = 'Datasets/ILSVRC2012_img_val/Control'
file_names = os.listdir(source_dir)
# Remove non image data files
file_names = [a for a in file_names if 'ILSVRC2012' in a]
random.shuffle(file_names)
group1 = file_names[0:len(file_names)//2]
group2 = file_names[len(file_names)//2:]
for file_name in group1:
shutil.move(os.path.join(source_dir, file_name), target_dir1)
for file_name in group2:
shutil.move(os.path.join(source_dir, file_name), target_dir2)