-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass_sort.py
51 lines (45 loc) · 1.45 KB
/
Class_sort.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
This script is used for sorting the data-set class-wise.
"""
import os
import shutil
from imutils import paths
def create_folders(sPath):
"""
Creates the required folders
:param sPath: Base path of the location where folders are to be created.
:return: None
"""
cnt = 1
os.mkdir("Classes")
ClassPath = os.path.join(sPath, "Classes")
os.chdir(ClassPath)
for item in range(105):
ClassName = str(cnt).zfill(4)
ClassFolderPath = os.path.join(ClassPath, ClassName)
print("Creating folder : ", ClassFolderPath)
os.mkdir(ClassFolderPath)
cnt += 1
os.chdir(sPath)
def folders2classes(sFolderPath):
"""
Move the videos from original folders to class folders.
:param sFolderPath: Base folder where the original and class folders are present.
:return: None
"""
sClassPath = os.path.join(sFolderPath, "Classes")
pi_videos = os.listdir(sClassPath)
li_videos = paths.list_files("Dataset\Augmented_FinalDataset")
cnt = 0
for item in li_videos:
cnt += 1
id = item.split(".")[0]
class_id = id[-6:-2]
if class_id in pi_videos:
sVideoName = str(cnt).zfill(5) + ".mp4"
sClassSavePath = os.path.join(sClassPath, os.path.join(class_id, sVideoName))
print("Adding video to : ", sClassSavePath)
shutil.copy(src=item, dst=sClassSavePath)
cwd = os.getcwd()
create_folders(cwd)
folders2classes(cwd)