Satoru commited on
Commit
cca6c8d
1 Parent(s): dd3ffb7

feat: fix metric

Browse files
Files changed (4) hide show
  1. api.py +1 -1
  2. app.py +3 -2
  3. models/index.ann +2 -2
  4. src/build.py +1 -1
api.py CHANGED
@@ -15,7 +15,7 @@ def load_annoy_index(
15
  ) -> Tuple[annoy.AnnoyIndex, dict]:
16
  """Load annoy index and associated mapping file"""
17
 
18
- annoy_index = annoy.AnnoyIndex(f=EMBEDDING_DIMENSION, metric='euclidean')
19
  annoy_index.load(index_file)
20
 
21
  with open(ANNOY_MAPPING_FILE) as f:
 
15
  ) -> Tuple[annoy.AnnoyIndex, dict]:
16
  """Load annoy index and associated mapping file"""
17
 
18
+ annoy_index = annoy.AnnoyIndex(f=EMBEDDING_DIMENSION, metric='angular')
19
  annoy_index.load(index_file)
20
 
21
  with open(ANNOY_MAPPING_FILE) as f:
app.py CHANGED
@@ -36,7 +36,7 @@ def find_matching_images(input_img, n_matches: int = 10):
36
  if url != "":
37
  images.append(url)
38
 
39
- score = round(100 - scores[i], 1)
40
 
41
  HTML += f"""<div class="card mb-3">
42
  <div class="row g-0">
@@ -46,7 +46,7 @@ def find_matching_images(input_img, n_matches: int = 10):
46
  <div class="col-md-8">
47
  <div class="card-body">
48
  <h5 class="card-title">{mapping["name"]}</h5>
49
- <p class="card-text">Similarity: {score} %</p>
50
  <p class="card-text">
51
  <a target="_blank" href="https://kunshujo2022.dl.itc.u-tokyo.ac.jp/item/{mapping["nconst"]}">View at 「電子展示『捃拾帖』(拡張版)」</a>
52
  </p>
@@ -67,6 +67,7 @@ iface = gr.Interface(
67
  article=get_article_text(),
68
  inputs=[
69
  gr.inputs.Image(shape=None, label="Your image"),
 
70
  ],
71
  # outputs=gr.Gallery(label="類似する貼り込み資料").style(height="100px"),
72
  outputs=gr.HTML(label="類似する貼り込み資料"),
 
36
  if url != "":
37
  images.append(url)
38
 
39
+ score = round((1 - scores[i]) * 100, 1)
40
 
41
  HTML += f"""<div class="card mb-3">
42
  <div class="row g-0">
 
46
  <div class="col-md-8">
47
  <div class="card-body">
48
  <h5 class="card-title">{mapping["name"]}</h5>
49
+ <p class="card-text">Rank: {i+1}, Similarity: {score} %</p>
50
  <p class="card-text">
51
  <a target="_blank" href="https://kunshujo2022.dl.itc.u-tokyo.ac.jp/item/{mapping["nconst"]}">View at 「電子展示『捃拾帖』(拡張版)」</a>
52
  </p>
 
67
  article=get_article_text(),
68
  inputs=[
69
  gr.inputs.Image(shape=None, label="Your image"),
70
+ gr.inputs.Slider(minimum=1, maximum=30, step=1, default=10, label="Number of matches"),
71
  ],
72
  # outputs=gr.Gallery(label="類似する貼り込み資料").style(height="100px"),
73
  outputs=gr.HTML(label="類似する貼り込み資料"),
models/index.ann CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:93813702bd173d85d7fdeeb743964360e4624facec2b8719db9ad1abf79b7bae
3
- size 973864800
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3340614656c9ecbd54d6d04340c595f5e911474d92e6fed3147cb5d6870055ef
3
+ size 1009403344
src/build.py CHANGED
@@ -95,7 +95,7 @@ N_TREES = 1000
95
 
96
  from annoy import AnnoyIndex
97
 
98
- annoy_index = AnnoyIndex(features.shape[1], metric='euclidean')
99
 
100
  for i in range(len(features)):
101
 
 
95
 
96
  from annoy import AnnoyIndex
97
 
98
+ annoy_index = AnnoyIndex(features.shape[1], metric='angular')
99
 
100
  for i in range(len(features)):
101