def subjectset(self, wordnetid): """Iterator for single subject""" assert wordnetid in self.wordnetid_to_name().keys( ), 'Invalid wordnetid "%s"' % wordnetid d = os.path.join(self.datadir, wordnetid) for f in imlist(d): yield ImageDetection(filename=f, category=filebase(d))
def dataset(self): """Return a generator to iterate over dataset""" for d in dirlist(os.path.join(self.datadir, 'images')): for f in imlist(d): im = ImageDetection(filename=f, category=filebase(d)) im = im.boundingbox(xmin=float(im.width() - 256) / 2.0, ymin=float(im.height() - 256.0) / 2.0, xmax=256.0 + ((im.width() - 256.0) / 2.0), ymax=256.0 + ((im.height() - 256.0) / 2.0)) im = im.boundingbox(dilate=0.875) # central 224x224 yield im
def take(self, n, wordnetid=None): """Randomly select n images from the dataset, or n images of a given subjectid""" subjectid = np.random.choice( self.subjects(), n) if wordnetid is None else [wordnetid] * n takelist = [] for s in subjectid: d = os.path.join(self.datadir, s) f = np.random.choice(imlist(d), 1)[0] im = ImageDetection(filename=f).category(filebase(d)) takelist.append(im) return takelist
def take_per_subject(self, n): """Randomly select n images per subject from the dataset""" subjectid = self.subjects() takelist = [] for s in subjectid: d = os.path.join(self.datadir, s) for k in range(0, n): f = np.random.choice(imlist(d), 1)[0] im = ImageDetection(filename=f).category(filebase(d)) takelist.append(im) return takelist
def videos(self, subject): videos = {} for d in dirlist(os.path.join(self.ytfdir, 'frame_images_DB', subject)): k_videoindex = filetail(d) videos[k_videoindex] = [] for f in imlist(d): videos[k_videoindex].append( ImageCategory(filename=f, category=subject)) videos[k_videoindex] = sorted(videos[k_videoindex], key=lambda im: im.filename()) return videos
def take(self, n): S = np.random.choice(self.subjects(), n) takelist = [] for d in dirlist(os.path.join(self.datadir, 'images')): if filebase(d) in S: f = np.random.choice(imlist(d), 1)[0] im = ImageDetection(filename=f, category=filebase(d)) im = im.boundingbox(xmin=float(im.width() - 256) / 2.0, ymin=float(im.height() - 256.0) / 2.0, xmax=256.0 + ((im.width() - 256.0) / 2.0), ymax=256.0 + ((im.height() - 256.0) / 2.0)) im = im.boundingbox(dilate=0.875) # central 224x224 takelist.append(im) return takelist
def _trainset(self): """Save a csv file containing each image on a line for Megaface_Challenge_1M_disjoint_LOOSE.tar.gz""" outfile = os.path.join(self.datadir, 'Megaface_Challenge_1M_disjoint_LOOSE.csv') subdir = os.path.join(self.datadir, 'Megaface_Challenge_1M_disjoint_LOOSE') D = dirlist(subdir) filelist = [] for (k, d) in enumerate(D): print('[MF2.trainset][%d/%d]: creating image list for "%s"' % (k, len(D), d)) for f in imlist(d): filelist.append((f, filebase(d))) return writecsv(filelist, outfile)
def _imagelist(self): """Save a csv file containing each image on a line""" if os.path.exists(os.path.join(self.datadir, 'megaface.csv')): return (os.path.join(self.datadir, 'megaface.csv')) else: outfile = os.path.join(self.datadir, 'megaface.csv') with open(outfile, 'w') as csv: subdir = os.path.join(self.datadir, 'FlickrFinal2') D = dirlist(subdir) for (k, d) in enumerate(D): print( '[megaface.dataset][%d/%d]: creating image list for "%s"' % (k, len(D), d)) for sd in dirlist(d): for f in imlist(sd): csv.write(f + '\n') # full path return outfile
def dataset(self): return [ ImageCategory(category=s, filename=f) for s in self.subjects() for f in imlist(os.path.join(self.lfwdir, s)) ]
def subject_images(self, subject): """List of Images of a subject""" fnames = imlist(os.path.join(self.lfwdir, subject)) return [ImageCategory(category=subject, filename=f) for f in fnames]
def _parse(self): outlist = [] id2name = {k:v for (k,v) in readcsv(os.path.join(self.datadir, 'names.txt'), separator=' ')} for d in dirlist(self.datadir): outlist = outlist + [ImageDetection(filename=imfile, category=id2name[str(filebase(d))], xmin=13, ymin=13, xmax=250 - 13, ymax=250 - 13) for imfile in imlist(d)] return outlist
def by_subject(self, wordnetid): d = os.path.join(self.datadir, 'images', wordnetid) for f in imlist(d): yield ImageDetection(filename=f, category=filebase(d))
def fastset(self): """Return a generator to iterate over dataset""" for d in dirlist(os.path.join(self.datadir, 'images')): for f in imlist(d): im = ImageDetection(filename=f, category=filebase(d)) yield im
def dataset(self): """Return a generator to iterate over dataset""" for d in dirlist(os.path.join(self.datadir)): for f in imlist(d): yield ImageDetection(filename=f).category(filebase(d))