Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ChainerとAnnoyを使った 類似画像検索

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

ChainerとAnnoyを使った 類似画像検索

Avatar for takaaki shimbo

takaaki shimbo

August 29, 2018
Tweet

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ໊લɿɹ৽อɹᠳཅ • 4݄͔Βࣾձਓ (ERPͷձࣾ ) • Twitter: @ta7uw

    • GitHub: @takaaki82 • Qiita: https://qiita.com/ta7uwtaka
  2. ಛ௃ྔΛAnnoyʹ௥Ճ from annoy import AnnoyIndex train, test = chainer.datasets.get_cifar10() dim

    = 1024 #தؒ૚ͷग़ྗͷཁૉ਺ annoy_model = AnnoyIndex(dim) with chainer.using_config('train', False), chainer.using_config('enable_backprop', False): for i in range(len(train)): img, _ = train[i] # numpy -> cupy x = model.xp.asarray(img[None, ...]) # ֶशσʔλͷਪ࿦݁Ռͷ͏ͪը૾෼ྨϞσϧͷ̍̌૚໨ͷग़ྗΛಘΔ x = get_hidden(model ,9 ,x=x).data x = x.reshape(-1) #cupy -> numpy x = chainer.cuda.to_cpu(x) annoy_model.add_item(i, x) # AnnoyϞσϧͷϏϧυ(Ҏޙσʔλͷ௥Ճ͸ߦ͑ͳ͍) annoy_model.build(1000) annoy_model.save("cifar-10-1000tree.ann")
  3. ۙࣅ࠷ۙ๣୳ࡧͷ࣮ߦ x = model.xp.asarray(x[None, …]) x = get_hidden(model ,9 ,x=

    x).data x = x.reshape(-1) x = chainer.cuda.to_cpu(x) # ಛ௃ϕΫτϧxΛΘͨ͢ͱɺྨࣅ౓ܭࢉΛߦ͍ɺྨࣅ౓ͷେ͖͍΋ͷΛฦ͢ɹɹɹɹɹɹɹɹɹɹɹ predict_indexes = annoy_model.get_nns_by_vector(x, 5, search_k=-1)
  4. ࢀߟ • Start Today Technologies TECH BLOG (https://tech.starttoday-tech.com/entry/detection_and_retrieval) • ݪాୡ໵

    (2017) , ը૾ೝࣝɹػցֶशϓϩϑΣογϣφϧ γϦʔζ • Deep metric learning using Triplet network (https://arxiv.org/pdf/1412.6622.pdf)