Exemplo n.º 1
0
 def split(self):
     trainPeople = [
         'person02', 'person03', 'person05', 'person06', 'person07',
         'person08', 'person09', 'person10', 'person22'
     ]
     videos = self.dataset()
     trainset = [
         vid for vid in videos
         if filetail(vid.filename()).split('_')[0] in trainPeople
     ]
     testset = [
         vid for vid in videos
         if filetail(vid.filename()).split('_')[0] not in trainPeople
     ]
     return (trainset, testset)
Exemplo n.º 2
0
def imagetuplelist(list_of_tuples_of_image_files,
                   outdir,
                   title='Image Visualization',
                   imagewidth=64):
    """Imageset but put tuples on same row"""
    k_divid = 0

    # Create summary page to show precomputed images
    outdir = remkdir(outdir)
    filename = os.path.join(remkdir(outdir), 'index.html')
    f = open(filename, 'w')
    f.write('<!DOCTYPE html>\n')
    f.write('<html>\n')
    f.write('<body>\n')
    f.write('<div id="container" style="width:2400px">\n')
    f.write('<div id="header">\n')
    f.write('<h1 style="margin-bottom:0;">Title: %s</h1><br>\n' % title)
    localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
    f.write('Summary HTML generated on %s<br>\n' % localtime)
    f.write('Number of Tuples: %d<br>\n' % len(list_of_tuples_of_image_files))
    f.write('</div>\n')
    f.write('<br>\n')
    f.write('<hr>\n')
    f.write('<div id="%04d" style="float:left;">\n' % k_divid)
    k_divid = k_divid + 1

    # Generate images and html
    for (k, imsrclist) in enumerate(list_of_tuples_of_image_files):
        f.write('<p>\n</p>\n')
        for imsrc in imsrclist:
            shutil.copyfile(imsrc, os.path.join(outdir, filetail(imsrc)))
            imdst = filetail(imsrc)
            f.write('<b>Filename: %s</b><br>\n' % imdst)
        f.write('<p>\n</p>\n')
        f.write('<br>\n')
        for imsrc in imsrclist:
            imdst = filetail(imsrc)
            f.write('<img src="%s" alt="image" width=%d/>' %
                    (imdst, imagewidth))
        f.write('\n<p>\n</p>\n')
        f.write('<hr>\n')
        f.write('<p>\n</p>\n')

    f.write('</div>\n')
    f.write('</body>\n')
    f.write('</html>\n')
    f.close()
    return filename
Exemplo n.º 3
0
 def testset(self):
     """ActivityNet test set does not include any annotations"""
     assert self._isdownloaded(
     ), "Dataset not downloaded.  download() first or manually download '%s' into '%s'" % (
         self._url, self.datadir)
     json = readjson(os.path.join(self.datadir, filetail(URL)))
     return [
         Video(url=v['url'], filename=os.path.join(self.datadir, youtubeid))
         for (youtubeid, v) in json['database'].items()
         if v['subset'] == 'testing'
     ]
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 def _dataset(self, subset):
     assert self._isdownloaded(
     ), "Dataset not downloaded.  download() first or manually download '%s' into '%s'" % (
         self._url, self.datadir)
     jsonfile = os.path.join(self.datadir, filetail(URL))
     json = readjson(jsonfile)
     return [
         VideoCategory(url=v['url'],
                       filename=os.path.join(self.datadir, youtubeid),
                       category=a['label'],
                       startsec=float(a['segment'][0]),
                       endsec=float(a['segment'][1]))
         for (youtubeid, v) in json['database'].items()
         for a in v['annotations'] if v['subset'] == subset
     ]
Exemplo n.º 6
0
    def fetchjson(self):
        """Download JSON if not already downloaded"""

        if self._jsonfile is None:
            self._jsonfile = os.path.join(
                remkdir(os.environ["VIPY_CACHE"] if "VIPY_CACHE" in
                        os.environ else tempdir()),
                filetail(self._jsonurl),
            )
            if not os.path.exists(self._jsonfile):
                print('[pycollector.video]:  Fetching "%s"' % self._jsonurl)
                try:
                    vipy.downloader.s3(
                        self._jsonurl, self._jsonfile
                    )  # TODO - this is a problem to assume vipy user also has access to S3. We should decouple this dependency of using vipy

                except KeyboardInterrupt:
                    raise
                except Exception as e:
                    print(
                        '[pycollector.video]: S3 download error "%s" - SKIPPING'
                        % str(e))
                    jsonfile = None
        return self
Exemplo n.º 7
0
 def download(self):
     vipy.downloader.download(URL, os.path.join(self.datadir,
                                                filetail(URL)))
     self._unpack(os.path.join(self.datadir, filetail(URL)), self.datadir)
Exemplo n.º 8
0
 def subjects(self):
     """List of all subject names"""
     return [filetail(d) for d in dirlist(self.lfwdir)]
Exemplo n.º 9
0
 def download(self):
     vipy.downloader.download(URL, os.path.join(self.datadir,
                                                filetail(URL)))
     return self
Exemplo n.º 10
0
 def download(self):
     zipfile = os.path.join(self.datadir, filetail(URL))
     vipy.downloader.download(URL, zipfile)
     vipy.downloader.unpack(zipfile, self.datadir)
     return self