Beispiel #1
0
    def __init__(self, path, random=False):
        self.path = path

        # Get all annotations in folder or
        files = []
        if os.path.isdir(path):
            files = util.filesWithRe(path, r".*\/classifications.*\.json$")
            self.name = re.search(r"\/([^\/]*)\/?$", path).groups()[0] + "/all"
        elif os.path.isfile(path) and path.endswith(".json"):
            files = [path]
            self.name = "/".join(re.search(r"\/([^\/]*)\/classifications_(.*)\.json", path).groups())
        if random:
            self.name = re.search(r"\/([^\/]*)\/?$", path).groups()[0] + "/random"

        self.n = len(files)

        self.data = {}
        for fpath in files:
            with open(fpath, "r") as f:
                classifs = json.load(f)
                print("Loaded %s" % fpath)
            for fname, classif in classifs.iteritems():
                if random:
                    classif = randint(0, 1)
                if fname in self.data:
                    self.data[fname].append(classif)
                else:
                    self.data[fname] = [classif]
Beispiel #2
0
    def __init__(self, path, random=False):
        self.path = path

        # Get all annotations in folder or
        files = []
        if os.path.isdir(path):
            files = util.filesWithRe(path, r'.*\/classifications.*\.json$')
            self.name = re.search(r'\/([^\/]*)\/?$', path).groups()[0] + '/all'
        elif os.path.isfile(path) and path.endswith('.json'):
            files = [path]
            self.name = '/'.join(
                re.search(r'\/([^\/]*)\/classifications_(.*)\.json',
                          path).groups())
        if random:
            self.name = re.search(r'\/([^\/]*)\/?$',
                                  path).groups()[0] + '/random'

        self.n = len(files)

        self.data = {}
        for fpath in files:
            with open(fpath, 'r') as f:
                classifs = json.load(f)
                print('Loaded %s' % fpath)
            for fname, classif in classifs.iteritems():
                if random:
                    classif = randint(0, 1)
                if fname in self.data:
                    self.data[fname].append(classif)
                else:
                    self.data[fname] = [classif]
Beispiel #3
0
def cache_features(extractor, path):
    files = util.filesWithRe(path, r'.*\.(jpg|jpeg|png)$')
    for i, fpath in enumerate(files):
        feats = extractor.get_features(fpath)

        with open('%s.pickle' % fpath, 'w') as f:
            pickle.dump(feats, f)

        print('[%d/%d] Stored features for %s' % (i + 1, len(files), fpath))
Beispiel #4
0
def cache_features(extractor, path):
    files = util.filesWithRe(path, r'.*\.(jpg|jpeg|png)$')
    for i, fpath in enumerate(files):
        feats = extractor.get_features(fpath)

        with open('%s.pickle' % fpath, 'w') as f:
            pickle.dump(feats, f)

        print('[%d/%d] Stored features for %s' % (i+1, len(files), fpath))
Beispiel #5
0
    def __init__(self, path):
        self.path = path
        try:
            self.name = re.search(r"\/([^\/]*)\/?$", path).groups()[0]
        except:
            raise ValueError("Invalid path: %s" % path)

        self.data = {}
        for pikpath in util.filesWithRe(path, r".*\.pickle$"):
            fpath = pikpath[:-7]  # Strip .pickle
            with open(pikpath, "rb") as f:
                self.data[fpath] = pickle.load(f)["classes"]
Beispiel #6
0
    def __init__(self, path):
        self.path = path
        try:
            self.name = re.search(r'\/([^\/]*)\/?$', path).groups()[0]
        except:
            raise ValueError('Invalid path: %s' % path)

        self.data = {}
        for pikpath in util.filesWithRe(path, r'.*\.pickle$'):
            fpath = pikpath[:-7]  # Strip .pickle
            with open(pikpath, 'rb') as f:
                pik = pickle.load(f)
                if 'classes' in pik and 'gist' in pik:
                    self.data[fpath] = pik['classes']
                    self._gist[fpath] = pik['gist']