harvitronix / five-video-classification-methods

Code that accompanies my blog post outlining five video classification methods in Keras and TensorFlow
https://medium.com/@harvitronix/five-video-classification-methods-implemented-in-keras-and-tensorflow-99cad29cc0b5
MIT License
1.18k stars 478 forks source link

hope you can help me till the end #93

Open bit-scientist opened 6 years ago

bit-scientist commented 6 years ago

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 below

python 1_move_files.py
Traceback (most recent call last):
  File "1_move_files.py", line 81, in <module>
    main()
  File "1_move_files.py", line 78, in main
    move_files(group_lists)
  File "1_move_files.py", line 49, in move_files
    filename = parts[1]
IndexError: list index out of range

My 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!

jianxing31 commented 6 years ago

I encountered the same problem. and solved it by replacing os.path.sep with "/" parts = video.split("/")

cattei commented 6 years ago

@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.

cattei commented 6 years ago

@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. """

Do each of our groups.

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.")`
cattei commented 6 years ago

THW maybe you need ffmpeg, this is from imageio import imageio imageio.plugins.ffmpeg.download()

Muthu-Mariappan-h commented 6 years ago

I am still getting the error as " FileNotFoundError: [Errno 2] No such file or directory: '' -> 'train/' "

Nitin-Mane commented 4 years ago

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. """

Get our files based on version.

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. """

Do each of our groups.

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. """

Get the videos in groups so we can move them.

group_lists = get_train_test_lists()

# Move the files.
move_files(group_lists)

if name == 'main': main() `