prepare_chalearn.py
def move_videos(sSourceDir, sTargetDir, fFrac = 0.2):
    """ Move fraction of the videos to another folder eg 20% from train to val """

    # stop if new folder already exists
    assert os.path.exists(sTargetDir) == False

    sCurrentDir = os.getcwd()
    # get list of all directories = classes
    os.chdir(sSourceDir)
    liClasses = glob.glob("*")
    print("Found %d classes in %s. Move %.0f%% videos to %s ..." % \
        (len(liClasses), sSourceDir, fFrac*100, sTargetDir))

    # loop through directories
    for sClass in liClasses:
        os.chdir(sCurrentDir + "/" + sSourceDir + "/" + sClass)
        seVideos = pd.Series(glob.glob("*.avi"))
        seVideosSelected = seVideos.sample(frac = fFrac)

        sTargetPath = sCurrentDir + "/" + sTargetDir + "/" + sClass
        os.makedirs(sTargetPath, exist_ok=True)

        for sVideoName in seVideosSelected:
            os.rename(sVideoName, sTargetPath + "/" + sVideoName)

        print("Class %s | %d videos: Moved %d videos" % (sClass, len(seVideos), len(seVideosSelected)))

    os.chdir(sCurrentDir)
    return
 Move fraction of the videos to another folder eg 20% from train to val 
Move fraction of the videos to another folder eg 20% from train to val
Move fraction of the videos to another folder eg 20% from train to val
def move_videos(sSourceDir, sTargetDir, fFrac = 0.2):
    assert os.path.exists(sTargetDir) == False
    sCurrentDir = os.getcwd()
    os.chdir(sSourceDir)
    liClasses = glob.glob("*")
    print("Found %d classes in %s. Move %.0f%% videos to %s ..." % \
        (len(liClasses), sSourceDir, fFrac*100, sTargetDir))
    for sClass in liClasses:
        os.chdir(sCurrentDir + "/" + sSourceDir + "/" + sClass)
        seVideos = pd.Series(glob.glob("*.avi"))
        seVideosSelected = seVideos.sample(frac = fFrac)
        sTargetPath = sCurrentDir + "/" + sTargetDir + "/" + sClass
        os.makedirs(sTargetPath, exist_ok=True)
        for sVideoName in seVideosSelected:
            os.rename(sVideoName, sTargetPath + "/" + sVideoName)
        print("Class %s | %d videos: Moved %d videos" % (sClass, len(seVideos), len(seVideosSelected)))
    os.chdir(sCurrentDir)
    return
def move_videos ( sSourceDir , sTargetDir , fFrac = 0.2 ) : assert os . path . exists ( sTargetDir ) == False sCurrentDir = os . getcwd ( ) os . chdir ( sSourceDir ) liClasses = glob . glob ( "*" ) print ( "Found %d classes in %s. Move %.0f%% videos to %s ..." % ( len ( liClasses ) , sSourceDir , fFrac * 100 , sTargetDir ) ) for sClass in liClasses : os . chdir ( sCurrentDir + "/" + sSourceDir + "/" + sClass ) seVideos = pd . Series ( glob . glob ( "*.avi" ) ) seVideosSelected = seVideos . sample ( frac = fFrac ) sTargetPath = sCurrentDir + "/" + sTargetDir + "/" + sClass os . makedirs ( sTargetPath , exist_ok = True ) for sVideoName in seVideosSelected : os . rename ( sVideoName , sTargetPath + "/" + sVideoName ) print ( "Class %s | %d videos: Moved %d videos" % ( sClass , len ( seVideos ) , len ( seVideosSelected ) ) ) os . chdir ( sCurrentDir ) return
Move fraction of the videos to another folder eg 20% from train to val
Move fraction of the videos to another folder eg 20% from train to val
""" Move fraction of the videos to another folder eg 20% from train to val """ # stop if new folder already exists # get list of all directories = classes # loop through directories
sSourceDir
sTargetDir
fFrac