question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hope you can help me till the end

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Nitin-Manecommented, Jan 20, 2020

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() `

1reaction
catteicommented, Sep 5, 2018

@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.")`
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disney Music - Lava (Official Lyric Video from "Lava") - YouTube
Download the song “Lava” here: http://smarturl. it /dpls1Google Play: ... try restarting your device. Your browser can 't play this video.
Read more >
Here Are the Lyrics to Gabby Barrett's 'I Hope' - Billboard
Check out the lyrics and music video below. I, I hope she makes you smile. The way it made me smile. On the...
Read more >
James Arthur – Say You Won't Let Go Lyrics - Genius
Say You Won't Let Go Lyrics: I met you in the dark, you lit me up / You made ... and evolve the...
Read more >
I hope you can help me in this matter // is it correct? [closed]
This company can manage accreditation process and provide world leading task management and support for a specific type of job. In the end...
Read more >
How to End an Email & 50 Different Email Sign-Offs - RightInbox
Wish them well. Keep me posted. End with a nice reminder for your recipient to keep you in the loop. I'll circle back....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found