IMG = IMG.astype(int) hist = color.histogram(IMG, type='global', n_bin=4) assert np.equal(np.where(hist > 0)[0], np.array([37, 43, 58, 61])).all(), "global histogram implement failed" hist = color.histogram(IMG, type='region', n_bin=4, n_slice=2) assert np.equal(np.where(hist > 0)[0], np.array([58, 125, 165, 235])).all(), "region histogram implement failed" # examinate distance np.random.seed(1) IMG = sigmoid(np.random.randn(4, 4, 3)) * 255 IMG = IMG.astype(int) hist = color.histogram(IMG, type='region', n_bin=4, n_slice=2) IMG2 = sigmoid(np.random.randn(4, 4, 3)) * 255 IMG2 = IMG2.astype(int) hist2 = color.histogram(IMG2, type='region', n_bin=4, n_slice=2) assert distance(hist, hist2, d_type='d1') == 2, "d1 implement failed" assert distance(hist, hist2, d_type='d2-norm') == 2, "d2 implement failed" # evaluate database APs = evaluate_class(db, f_class=Color, d_type=d_type, depth=depth) cls_MAPs = [] for cls, cls_APs in APs.items(): MAP = np.mean(cls_APs) print("Class {}, MAP {}".format(cls, MAP)) cls_MAPs.append(MAP) print("MMAP", np.mean(cls_MAPs))
def test_subcost(w1, w2): result = evaluate.distance(W, vocab, w1, w2) print(result)
min = -1 name = "" for key, item in distance_dict.items(): if min == -1: min = item name = key if item < min: min = item name = key return name, min if __name__ == "__main__": color = method_select("HOG") data = {} for file in os.listdir(".\\database"): start_time = time.time() data[file] = color.histogram(".\\database\\" + file, type='global') tt = time.time() - start_time print("\t%5s" % (tt), "초") assert data[file].sum() - 1 < 1e-9, "normalize false" query = "05_16_오후DJI_0013.tif" hist2 = color.histogram(query, type='global') distance_dict = {} for key, item in data.items(): distance_dict[key] = distance(item, hist2, d_type='d1') for i in range(0, 5): name, min = simple_min(distance_dict) print(name, min) distance_dict.pop(name)