Spaces:
Build error
Build error
Adds script to copy annotation files
Browse files- copy_annotations.py +27 -12
copy_annotations.py
CHANGED
|
@@ -1,22 +1,37 @@
|
|
| 1 |
"""Copies annotations from one file to another."""
|
|
|
|
| 2 |
from os.path import isdir, join, exists
|
| 3 |
from glob import glob
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
if __name__ == "__main__":
|
| 7 |
-
src_dir = "/ssd/pbagad/datasets/
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
]
|
| 13 |
|
| 14 |
# load all source files
|
| 15 |
src_files = glob(join(src_dir, "*_filtered.json"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""Copies annotations from one file to another."""
|
| 2 |
+
import os
|
| 3 |
from os.path import isdir, join, exists
|
| 4 |
from glob import glob
|
| 5 |
+
import shutil
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
|
| 9 |
if __name__ == "__main__":
|
| 10 |
+
src_dir = "/ssd/pbagad/datasets/CondensedMovies/annotations/"
|
| 11 |
+
|
| 12 |
+
num_subdirs = 3
|
| 13 |
+
dst_dirs = [f"./annotations_{i}" for i in range(1, num_subdirs + 1)]
|
| 14 |
+
print("Number of destination dirs:", len(dst_dirs))
|
|
|
|
| 15 |
|
| 16 |
# load all source files
|
| 17 |
src_files = glob(join(src_dir, "*_filtered.json"))
|
| 18 |
+
print("Number of source files:", len(src_files))
|
| 19 |
+
|
| 20 |
+
# split into num_subdirs
|
| 21 |
+
src_file_splits = np.array_split(np.array(src_files), num_subdirs)
|
| 22 |
+
|
| 23 |
+
# src_file_splits = [
|
| 24 |
+
# src_files[:len(src_files)//3],
|
| 25 |
+
# src_files[len(src_files)//3:2*len(src_files)//3],
|
| 26 |
+
# src_files[2*len(src_files)//3:],
|
| 27 |
+
# ]
|
| 28 |
|
| 29 |
+
print("Copying")
|
| 30 |
+
# copy to each dst dir
|
| 31 |
+
for src_files, dst_dir in zip(src_file_splits, dst_dirs):
|
| 32 |
+
if not isdir(dst_dir):
|
| 33 |
+
os.makedirs(dst_dir)
|
| 34 |
+
for src_file in src_files:
|
| 35 |
+
dst_file = join(dst_dir, src_file.split("/")[-1])
|
| 36 |
+
# print(f"Copying {src_file} to {dst_file}")
|
| 37 |
+
shutil.copy(src_file, dst_file)
|