Created
May 10, 2021 15:43
-
-
Save adujardin/b1d7328617830031144c40858d301dc9 to your computer and use it in GitHub Desktop.
Creating label for mmaction2 for a custom dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goal is to convert this dataset into a mmaction2 friendly one (VideoDataset) | |
# https://github.com/open-mmlab/mmaction2/blob/master/docs/tutorials/3_new_dataset.md | |
import os | |
import random | |
output="ucf_crimes_custom" | |
output_ext="_list.txt" | |
ratio_train=0.8 | |
output_list=[] | |
label=0 | |
for class_path in ["Normal", "Violence", "Fire_Explosion"]: | |
class_path = os.path.join("Videos", class_path) | |
for file in os.listdir(class_path): | |
if file.endswith(".mp4"): | |
out=os.path.join(class_path, file) + " " + str(label) + "\n" | |
output_list.append(out) | |
label = label + 1 | |
random.shuffle(output_list) | |
for split in ["train", "val"]: | |
output_ = output + "_" + split + output_ext | |
file1 = open(output_,"w") | |
junction=int(len(output_list)*ratio_train) | |
if split == "train": | |
output_list_ = output_list[0:junction] | |
else: | |
output_list_ = output_list[junction+1:] | |
for out in output_list_: | |
file1.write(out) | |
file1.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment