How do I split my folder containing multiple video files into train and test folders based on dataframe variables that tell me the which video should be in the train folder and which video should be in the test folder? (in Python 3.0). In which multiple videos are located in separate category folders
Each of the videos can be found in for instance the following category directories:
C:\Users\Me\Videos\a
C:\Users\Me\Videos\b
Which means that for every category I need a "train" and "test" folder like:
C:\Users\Me\Videos\a\train
C:\Users\Me\Videos\a\test
While I have an (EDIT) csv-file containing the following information. Thus, I dont want my train and split to be random, but based on the binary code in my sheet.
videoname |test|train|category|
-------------------------------
video1.mp4| 1 |0 |a |
video2.mp4| 1 |0 |b |
video3.mp4| 1 |0 |c |
video4.mp4| 0 |1 |c |
Can anyone point me in the direction of how I can use the file to do this for me? Can I somehow put the file in a dataframe which tells Python where to move the files?
EDIT:
import os
import csv
from collections import defaultdict
videoroot = r'H:\Desktop'
transferrable_data = defaultdict(list)
with open(r'H:\Desktop\SVW.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
video_path_source = os.path.join(videoroot, row['Genre'], row['FileName'])
if (row['Train 1?'] == 0):
split_type = 'test'
else:
split_type = 'train'
video_destination_path = os.path.join(videoroot, row['Genre'], split_type, row['FileName'])
transferrable_data[video_path_source].append(video_destination_path)