andy-wyx commited on
Commit
1330097
1 Parent(s): 7e7fba0

remove BEiT option

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. closest_sample.py +2 -2
  3. explanations.py +3 -1
app.py CHANGED
@@ -329,7 +329,7 @@ with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
329
 
330
  with gr.Column():
331
  model_name = gr.Dropdown(
332
- ["Mummified 170", "Rock 170","Fossils BEiT","Fossils 142"],
333
  multiselect=False,
334
  value="Fossils 142", # default option
335
  label="Model",
 
329
 
330
  with gr.Column():
331
  model_name = gr.Dropdown(
332
+ ["Mummified 170", "Rock 170","Fossils 142"],#"Fossils BEiT" removed
333
  multiselect=False,
334
  value="Fossils 142", # default option
335
  label="Model",
closest_sample.py CHANGED
@@ -25,7 +25,7 @@ embedding_fossils = np.load('dataset/embedding_fossils_170_finer.npy')
25
 
26
  fossils_pd= pd.read_csv('fossils_paths.csv')
27
 
28
- def pca_distance(pca,sample,embedding,top_k):
29
  """
30
  Args:
31
  pca:fitted PCA model
@@ -38,7 +38,7 @@ def pca_distance(pca,sample,embedding,top_k):
38
  all = pca.transform(embedding[:,-1])
39
  distances = np.linalg.norm(all - s, axis=1)
40
  sorted_indices = np.argsort(distances)
41
- filtered_indices = sorted_indices[sorted_indices<=2852]
42
  top_indices = np.concatenate([filtered_indices[:2], filtered_indices[3:top_k+1]])
43
  return top_indices
44
 
 
25
 
26
  fossils_pd= pd.read_csv('fossils_paths.csv')
27
 
28
+ def pca_distance(pca,sample,embedding,top_k):
29
  """
30
  Args:
31
  pca:fitted PCA model
 
38
  all = pca.transform(embedding[:,-1])
39
  distances = np.linalg.norm(all - s, axis=1)
40
  sorted_indices = np.argsort(distances)
41
+ filtered_indices = sorted_indices[sorted_indices<=2852] # exclude general fossils, keep florissant only.
42
  top_indices = np.concatenate([filtered_indices[:2], filtered_indices[3:top_k+1]])
43
  return top_indices
44
 
explanations.py CHANGED
@@ -128,8 +128,10 @@ def explain(model, input_image,explain_method,nb_samples,size=600, n_classes=171
128
  phi = np.abs(explainer(X, Y))[0]
129
  if len(phi.shape) == 3:
130
  phi = np.mean(phi, -1)
 
 
131
  show(X[0],output_size = size)
132
- show(phi, output_size = size,p=1, alpha=0.2, )
133
  # show(X[0][:,size_repetitions:2*size_repetitions,:])
134
  # show(phi[:,size_repetitions:2*size_repetitions], p=1, alpha=0.4)
135
  plt.savefig(f'phi_{e}{i}.png')
 
128
  phi = np.abs(explainer(X, Y))[0]
129
  if len(phi.shape) == 3:
130
  phi = np.mean(phi, -1)
131
+ #apply Gaussian smoothing
132
+ phi_smoothed = cv2.GaussianBlur(phi, (5, 5), sigmaX=1.0, sigmaY=1.0)
133
  show(X[0],output_size = size)
134
+ show(phi_smoothed, output_size = size,p=1, alpha=0.2)
135
  # show(X[0][:,size_repetitions:2*size_repetitions,:])
136
  # show(phi[:,size_repetitions:2*size_repetitions], p=1, alpha=0.4)
137
  plt.savefig(f'phi_{e}{i}.png')