Open bit-scientist opened 6 years ago
I encountered the same problem. and solved it by replacing os.path.sep with "/" parts = video.split("/")
@jianxing31 still not work for me, but it's getting better that showing lots of errors.
I thought that maybe the windows path is different in python differ MacOS.
I'm using python3 and windows10.
@git-sohib ok problem sovled my folder structure is data -UCF101- 'all files' data-train data-test as so on. the problem occured when the file is not in the right path.
change "move_files" code :
`def move_files(file_groups): """This assumes all of our files are currently in this directory. So move them to the appropriate spot. Only needs to happen once. """
for group, videos in file_groups.items():
# Do each of our videos.
for video in videos:
# Get the parts.
parts = video.split("/")
classname = parts[0]
filename = parts[1]
# Check if this class exists.
if not os.path.exists(os.path.join(group, classname)):
print("Creating folder for %s/%s" % (group, classname))
os.makedirs(os.path.join(group, classname))
# Check if we have already moved this file, or at least that it
# exists to move.
fullname =os.path.join("UCF101",classname,filename)
if not os.path.exists(fullname):
print("Can't find %s to move. Skipping." % (filename))
continue
# Move it.
dest = os.path.join(group, classname, filename)
print("Moving %s to %s" % (filename, dest))
os.rename(fullname, dest)
print("Done.")`
THW maybe you need ffmpeg, this is from imageio
import imageio imageio.plugins.ffmpeg.download()
I am still getting the error as " FileNotFoundError: [Errno 2] No such file or directory: '' -> 'train/' "
The correct code for moving is this
`""" After extracting the RAR, we run this to move all the files into the appropriate train/test folders.
Should only run this file once! """ import os import os.path
def get_train_test_lists(version='01'): """ Using one of the train/test files (01, 02, or 03), get the filename breakdowns we'll later use to move everything. """
test_file = os.path.join('ucfTrainTestlist', 'testlist' + version + '.txt')
train_file = os.path.join('ucfTrainTestlist', 'trainlist' + version + '.txt')
# Build the test list.
with open(test_file) as fin:
test_list = [row.strip() for row in list(fin)]
# Build the train list. Extra step to remove the class index.
with open(train_file) as fin:
train_list = [row.strip() for row in list(fin)]
train_list = [row.split(' ')[0] for row in train_list]
# Set the groups in a dictionary.
file_groups = {
'train': train_list,
'test': test_list
}
return file_groups
def move_files(file_groups): """This assumes all of our files are currently in this directory. So move them to the appropriate spot. Only needs to happen once. """
for group, videos in file_groups.items():
# Do each of our videos.
for video in videos:
# Get the parts.
#parts = video.split(os.path.sep)
parts = os.path.split(video)
#parts = video.split('/')
classname = parts[0]
filename = parts[1]
# Check if this class exists.
if not os.path.exists(os.path.join(group, classname)):
print("Creating folder for %s/%s" % (group, classname))
os.makedirs(os.path.join(group, classname))
# Check if we have already moved this file, or at least that it
# exists to move.
fullname =os.path.join("UCF-101",classname,filename)
if not os.path.exists(fullname):
print("Can't find %s to move. Skipping." % (filename))
continue
# Move it.
dest = os.path.join(group, classname, filename)
print("Moving %s to %s" % (filename, dest))
os.rename(fullname, dest)
print("Done.")
def main(): """ Go through each of our train/test text files and move the videos to the right place. """
group_lists = get_train_test_lists()
# Move the files.
move_files(group_lists)
if name == 'main': main() `
I started following step by step as suggested in the readme. Now I am here at running
python 1_move_files.py
in the data folder. Please read the traceback belowMy path to data folder is not that long to be out of range I think.
D:\5_methods\five-video-classification-methods\data
I would really appreciate if someone guided me! Many thanks!