예제 #1
0
    def load_region_descriptors(self, db_name, limit_num=None, label_val=None):
        print 'Retrieving database \'{}\'...'.format(db_name)
        db = self.client[db_name]
        print '...[done]'

        # Get the hog info collection (which will contain a single document):
        print 'Loading hog info...'
        hog_coll = db.hog_info

        if hog_coll.count() > 0:
            # Load the hog_info from the database:
            hog_info_entry = hog_coll.find_one()
            hog = utils.create_hog_from_info_dict(hog_info_entry)
        else:
            raise ValueError(
                'hog_info not present in the database \'{}\'.'.format(db_name))
        print '...[done]'

        # Get the region descriptors collection:
        print 'Loading regions descriptors...'
        reg_desc_coll = db.region_descriptors
        cursor = None
        if limit_num and label_val:
            cursor = reg_desc_coll.find({'label': label_val}).limit(limit_num)
        else:
            cursor = reg_desc_coll.find()
        reg_desc_gen = (utils.RegionDescriptor.from_dict(info)
                        for info in cursor)
        print '...[done]'

        # # Close the client (it will automatically reopen if we use it again):
        # self.client.close()

        return hog, reg_desc_gen
예제 #2
0
    def load_region_descriptors(self, db_name, limit_num=None, label_val=None):
        print "Retrieving database '{}'...".format(db_name)
        db = self.client[db_name]
        print "...[done]"

        # Get the hog info collection (which will contain a single document):
        print "Loading hog info..."
        hog_coll = db.hog_info

        if hog_coll.count() > 0:
            # Load the hog_info from the database:
            hog_info_entry = hog_coll.find_one()
            hog = utils.create_hog_from_info_dict(hog_info_entry)
        else:
            raise ValueError("hog_info not present in the database '{}'.".format(db_name))
        print "...[done]"

        # Get the region descriptors collection:
        print "Loading regions descriptors..."
        reg_desc_coll = db.region_descriptors
        cursor = None
        if limit_num and label_val:
            cursor = reg_desc_coll.find({"label": label_val}).limit(limit_num)
        else:
            cursor = reg_desc_coll.find()
        reg_desc_gen = (utils.RegionDescriptor.from_dict(info) for info in cursor)
        print "...[done]"

        # # Close the client (it will automatically reopen if we use it again):
        # self.client.close()

        return hog, reg_desc_gen
예제 #3
0
def load_region_descriptors(trial_file):
    print "Loading descriptors from '{}'...".format(trial_file)
    fname, ext = os.path.splitext(trial_file)

    data = None
    if ext == ".pickle":
        with open(trial_file, "rb") as f:
            import pickle

            data = pickle.load(f)
    elif ext == ".yaml":
        data = fileutils.load_yaml_file(trial_file)
    else:
        raise ValueError("The file '{}' has an unrecognised extension: '{}'.".format(trial_file, ext))

    hog = utils.create_hog_from_info_dict(data["hog_descriptor_info"])
    regions = []
    descriptors = []
    for entry in data["region_descriptor_list"]:
        descriptors.append(np.array(entry["descriptor"], dtype=np.float32))

        rect = gm.PixelRectangle.from_opencv_bbox(entry["region"]["rect"])
        fname = entry["region"]["fname"]
        region = utils.ImageRegion(rect, fname)
        regions.append(region)

    return hog, regions, descriptors
예제 #4
0
def load_region_descriptors(trial_file):
    print 'Loading descriptors from \'{}\'...'.format(trial_file)
    fname, ext = os.path.splitext(trial_file)

    data = None
    if ext == '.pickle':
        with open(trial_file, 'rb') as f:
            import pickle
            data = pickle.load(f)
    elif ext == '.yaml':
        data = fileutils.load_yaml_file(trial_file)
    else:
        raise ValueError(
            'The file \'{}\' has an unrecognised extension: \'{}\'.'.format(
                trial_file, ext))

    hog = utils.create_hog_from_info_dict(data['hog_descriptor_info'])
    regions = []
    descriptors = []
    for entry in data['region_descriptor_list']:
        descriptors.append(np.array(entry['descriptor'], dtype=np.float32))

        rect = gm.PixelRectangle.from_opencv_bbox(entry['region']['rect'])
        fname = entry['region']['fname']
        region = utils.ImageRegion(rect, fname)
        regions.append(region)

    return hog, regions, descriptors