Ejemplo n.º 1
0
def export_videolist(outdir=None):
    cache = Cache(cacheroot=outdir, subdir=VISET)    
    vidlist = []
    for (idx_category, category) in enumerate(os.listdir(cache.root())):
        if os.path.isdir(os.path.join(cache.root(), category)):
            for (idx_video, filename) in enumerate(os.listdir(os.path.join(cache.root(), category))):    
                [avibase,ext] = os.path.splitext(filename)
                if ext == '.avi':
                    vidlist.append( (os.path.join(category, filename), category) )
    return vidlist
Ejemplo n.º 2
0
def stream(indir=None, outdir=None):
    cache = Cache(subdir=VISET)
    if outdir is not None:
        cache.setroot(outdir)
    if indir is not None:
        csvfile = os.path.join(indir, '%s.csv' % VISET)                    
    else:
        csvfile = os.path.join(cache.root(), '%s.csv' % VISET)            
    if not os.path.isfile(csvfile):
        csvfile = export()        
    return ImageCategoryStream(csvfile, cache=cache)
Ejemplo n.º 3
0
def export(outdir=None):
    # Update cache
    cache = Cache(subdir=VISET)   # non-global cache!
    if outdir is not None:
        cache.setroot(outdir)

    # Fetch textfile for construction
    txtfile = os.path.join(cache.root(), TXTFILE)
    if not os.path.isfile(txtfile):
        cache.unpack(cache.get(URL), unpackto=None, sha1=SHA1, cleanup=False)                 
    outfile = os.path.join(cache.root(), '%s.csv' % VISET)
            
    # Write images and annotations
    if not os.path.isfile(outfile):
        with open(outfile, 'wb') as csvfile:            
            f = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)        
            for (k, line) in enumerate(open(txtfile,'r')):
                try:
                    (name, url) = line.decode('utf-8').rstrip().split('\t')
                    (wnid, suffix) = name.decode('utf-8').rstrip().split('_')      
                    f.writerow([url.encode('utf-8'), wnid.encode('utf-8')])
                except KeyboardInterrupt:
                    raise
                except ValueError:
                    print '[viset.imagenet]: Warning: Ignoring malformed line "' + line[0:64] + ' ..."'                
                except:
                    raise

                if (k % 10000) == 0:
                    print '[bobo.viset.imagenet][%d/14200000]: exporting "%s"' % (k, url.encode('utf-8'))
    else:
        print '[bobo.viset.imagenet]: returning cached viset file "%s"' % (outfile)        

    # Done!
    return outfile
Ejemplo n.º 4
0
def export(outdir=None, clean=False):
    # Unpack dataset
    cache = Cache(cacheroot=outdir, subdir=VISET)        
    if clean:
        cache.clean()
                        
    rarfile = unpack(cache.get(URL, SHA1), cache.root())

    vidlist = []
    for (idx_category, category) in enumerate(os.listdir(cache.root())):
        if os.path.isdir(os.path.join(cache.root(), category)):
            for (idx_video, filename) in enumerate(os.listdir(os.path.join(cache.root(), category))):    
                [avibase,ext] = os.path.splitext(filename)
                if ext == '.avi':
                    vidlist.append( (os.path.join(category, filename), category) )
    return vidlist
Ejemplo n.º 5
0
def stream(outdir=None):
    cache = Cache(cacheroot=outdir, subdir=VISET)            
    csvfile = os.path.join(cache.root(), '%s.csv' % VISET)            
    if not os.path.isfile(csvfile):
        csvfile = export()        
    return VideoCategoryStream(csvfile, cache=cache)
Ejemplo n.º 6
0
def export(outdir=None, clean=False):
    # Unpack dataset
    cache = Cache(cacheroot=outdir, subdir=VISET)        
    outfile = cache.abspath('%s.csv' % VISET)            

    if clean:
        cache.clean()
    elif os.path.isfile(outfile):
        print '[bobo.viset.kthactions]: exporting "%s"' % outfile
        return outfile
                        
    print '[bobo.viset.kthactions][WARNING]: downloads will not show percent progress since content length is unknown'
    for (url, label, sha1) in zip(URLS, LABELS, SHA1):
        cache.unpack(cache.get(url, sha1), cache.abspath(label), cleanup=False)

    # Check for frame export utility
    #if not isexe('ffmpeg'):
    #    raise IOError('[bobo.viset.kthactions]: ffmpeg not found on path')
                    
    # Video list
    with open(outfile, 'wb') as csvfile:
        f = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)                   
        for (idx_category, category) in enumerate(os.listdir(cache.root())):
            if os.path.isdir(os.path.join(cache.root(), category)):
                for (idx_video, filename) in enumerate(os.listdir(os.path.join(cache.root(), category))):    
                    [avibase,ext] = os.path.splitext(filename)
                    if ext == '.avi':
                        imdir = cache.abspath(os.path.join(category, avibase))                        
                        print '[bobo.viset.kthactions]: exporting "%s" to "%s"' % (filename, imdir)
                        f.writerow([os.path.join(category, avibase, 'im_%08d.png'), category]);                                        
                        cmd = "ffmpeg -i \'%s\' %s/im_%%08d.png &> /dev/null" % (os.path.join(cache.root(), category, filename), imdir)
                        remkdir(imdir)                        
                        if os.system(cmd) != 0:
                            raise IOError('Error running ffmpeg')
    return outfile