def _get_feat(self, db, f_class): if f_class == 'color': f_c = Color() elif f_class == 'daisy': f_c = Daisy() elif f_class == 'edge': f_c = Edge() return f_c.make_samples(db, verbose=False)
def method_select(name): if name == "color": ret = Color() elif name == "edge": ret = Edge() elif name == "gabor": ret = Gabor() elif name == "daisy": ret = Daisy() elif name == "HOG": ret = HOG() return ret
def _get_feat(self, db, f_class): if f_class == 'color': f_c = Color() elif f_class == 'daisy': f_c = Daisy() elif f_class == 'edge': f_c = Edge() elif f_class == 'gabor': f_c = Gabor() elif f_class == 'hog': f_c = HOG() elif f_class == 'vgg': f_c = VGGNetFeat() elif f_class == 'res': f_c = ResNetFeat() return f_c.make_samples(db, verbose=False)
def __init__(self, db, f_class=None, d_type='L1'): self.NGT_dir = 'NGT_{}_{}'.format(f_class,d_type) self.NGT_path = b'' self.fearure = f_class self.SQLdb = SQLite() if f_class == 'daisy': self.f_c = Daisy() self.NGT_path = b'NGT/NGT_daisy_'+d_type.encode() elif f_class == 'edge': self.f_c = Edge() self.NGT_path = b'NGT/NGT_edge_'+d_type.encode() elif f_class == 'hog': self.f_c = HOG() self.NGT_path = b'NGT/NGT_hog_'+d_type.encode() elif f_class == 'vgg': self.f_c = VGGNetFeat() self.NGT_path = b'NGT/NGT_vgg_'+d_type.encode() elif f_class == 'res': self.f_c = ResNetFeat() self.NGT_path = b'NGT/NGT_res_'+d_type.encode() if not os.path.exists(os.path.join(NGT_dir,self.NGT_dir)): samples = self.f_c.make_samples(db, verbose=False) dim = 0 try: dim = samples[0]['hist'].shape[0] except: pass images= [] objects = [] for i, row in enumerate(samples): vector = row['hist'] link = row['img'] lable = row['cls'] data = {'index':i,'link':link,'lable':lable} images.append(data) objects.append(vector) self.SQLdb.updateMuti(f_class,images) # cPickle.dump(images, open(os.path.join(NGT_dir, sample_cache), "wb", True)) ngtpy.create(path=self.NGT_path, dimension=dim, distance_type=d_type) self.index = ngtpy.Index(self.NGT_path) self.index.batch_insert(objects) self.index.save() self.index = ngtpy.Index(self.NGT_path)
depth = 5 d_type = 'd1' query_idx = 0 if __name__ == '__main__': db = Database() # retrieve by color method = Color() samples = method.make_samples(db) query = samples[query_idx] _, result = infer(query, samples=samples, depth=depth, d_type=d_type) print(result) # retrieve by daisy method = Daisy() samples = method.make_samples(db) query = samples[query_idx] _, result = infer(query, samples=samples, depth=depth, d_type=d_type) print(result) # retrieve by edge method = Edge() samples = method.make_samples(db) query = samples[query_idx] _, result = infer(query, samples=samples, depth=depth, d_type=d_type) print(result) # retrieve by gabor method = Gabor() samples = method.make_samples(db)
A_types = np.array([c.A_w, c.A_b]) h = 0.1 dL = 0.01 Ls = np.arange(0.6, 1.6 + dL, dL) N = len(Ls) pops = np.zeros((N, len(a_types))) Ts = np.zeros_like(Ls) pops[0] = np.zeros_like(a_types) + 0.01 for i, L in enumerate(Ls[:-1]): # Initial guess is last step a_0 = np.where(pops[i] < 0.01, 0.01, pops[i]) # Make new daisy object for this solution d_cur = Daisy(1, 0.3, a_0, A_types, L) # Solve d_cur.rk4Solve(100000, h) pops[i + 1] = d_cur.a_vec[:-1] Ts[i + 1] = d_cur.Teff print(f'L = {L:1.1f}', end=' || ') for i, p in enumerate(pops[i + 1]): print(f'p_{i} = {p:1.2e}', end=' || ') print(f'total = {np.sum(pops[i+1, :]):1.2e}', end='\n') fig, axes = plt.subplots(2, 1) ax = axes.flatten()[0] ax.plot(Ls, pops[:, 0] * 100, 'b-', label='White daisy fraction') ax.plot(Ls, pops[:, 1] * 100, 'k-', label='Black daisy fraction')
depth = 100 d_type = 'd1' query_idx = 3 if __name__ == '__main__': db = Database() # # retrieve by color # method = Color() # samples = method.make_samples(db) # query = samples[query_idx] # _, result = infer(query, samples=samples, depth=depth, d_type=d_type) # print(result) # retrieve by daisy method = Daisy() samples = method.make_samples(db) query = samples[query_idx] _, result = infer(query, samples=samples, depth=depth, d_type=d_type) print(result) # retrieve by edge method = Edge() samples = method.make_samples(db) query = samples[query_idx] _, result = infer(query, samples=samples, depth=depth, d_type=d_type) print(result) # # retrieve by gabor # method = Gabor() # samples = method.make_samples(db)
def _get_feat(self, db, f_class, sample_name=""): if f_class == 'color': f_c = Color() elif f_class == 'daisy': f_c = Daisy() return f_c.make_samples(db, verbose=False, sample_name=sample_name)
""" try: name, weight = s.split(':') weight = int(weight) if name not in features.keys() or weight < 1: raise Exception return name, weight except: raise argparse.ArgumentTypeError( f"\nFeature must be 'name:weight'\n\tname in {features.keys()}\n\tweight >= 1" ) features = { "color": Color(), "daisy": Daisy(), "edge": Edge(), "gabor": Gabor(), "hog": HOG(), "vgg": VGGNetFeat(), "res": ResNetFeat(), } if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-n", "--neighbor", help="neighbor by class", type=int, default=3) parser.add_argument(