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