예제 #1
0
파일: FeatMat.py 프로젝트: caomw/autocrop
    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]
예제 #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]
예제 #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))
예제 #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))
예제 #5
0
파일: FeatMat.py 프로젝트: caomw/autocrop
    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"]
예제 #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']