xd-violence / scripts /gen_train_list.py
jherng's picture
Edit dataset loading script
5fc19f9
raw
history blame
No virus
1.1 kB
# Script to generate train_list.txt file which contains all the training videos
import logging
import os
DATA_DIR = os.path.abspath(os.path.join(__file__, "../../", "data"))
VIDEO_DIR = os.path.join(DATA_DIR, "video")
SUBDIRS = ["1-1004", "1005-2004", "2005-2804", "2805-3319", "3320-3954"]
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
with open(os.path.join(DATA_DIR, "train_list.txt"), "w") as f:
for subdir in SUBDIRS:
subdir_path = os.path.join(VIDEO_DIR, subdir)
logger.info(f"Processing subdir: {subdir_path}")
try:
for video in os.listdir(subdir_path):
f.write(f"{subdir}/{video.split('.mp4')[0]}\n")
except FileNotFoundError as e:
logger.error(
f"Error processing subdir: {subdir_path}: {e.__class__.__name__}"
)
except Exception as e:
logger.error(f"Unknown error processing subdir: {subdir_path}: {e}")
logger.info("Processing finished")