kritsg commited on
Commit
4365fdc
1 Parent(s): d8edf39

testing french bulldog imagenet

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. app.py +16 -10
  2. data/french_bulldog/n02108915_10204.jpg +0 -0
  3. data/french_bulldog/n02108915_10564.jpg +0 -0
  4. data/french_bulldog/n02108915_110.jpg +0 -0
  5. data/french_bulldog/n02108915_1114.jpg +0 -0
  6. data/french_bulldog/n02108915_1119.jpg +0 -0
  7. data/french_bulldog/n02108915_11207.jpg +0 -0
  8. data/french_bulldog/n02108915_11220.jpg +0 -0
  9. data/french_bulldog/n02108915_11327.jpg +0 -0
  10. data/french_bulldog/n02108915_11335.jpg +0 -0
  11. data/french_bulldog/n02108915_1137.jpg +0 -0
  12. data/french_bulldog/n02108915_11498.jpg +0 -0
  13. data/french_bulldog/n02108915_11550.jpg +0 -0
  14. data/french_bulldog/n02108915_11653.jpg +0 -0
  15. data/french_bulldog/n02108915_1188.jpg +0 -0
  16. data/french_bulldog/n02108915_12139.jpg +0 -0
  17. data/french_bulldog/n02108915_12288.jpg +0 -0
  18. data/french_bulldog/n02108915_12317.jpg +0 -0
  19. data/french_bulldog/n02108915_12319.jpg +0 -0
  20. data/french_bulldog/n02108915_12460.jpg +0 -0
  21. data/french_bulldog/n02108915_12618.jpg +0 -0
  22. data/french_bulldog/n02108915_12904.jpg +0 -0
  23. data/french_bulldog/n02108915_1343.jpg +0 -0
  24. data/french_bulldog/n02108915_142.jpg +0 -0
  25. data/french_bulldog/n02108915_1465.jpg +0 -0
  26. data/french_bulldog/n02108915_1513.jpg +0 -0
  27. data/french_bulldog/n02108915_160.jpg +0 -0
  28. data/french_bulldog/n02108915_1612.jpg +0 -0
  29. data/french_bulldog/n02108915_1752.jpg +0 -0
  30. data/french_bulldog/n02108915_1788.jpg +0 -0
  31. data/french_bulldog/n02108915_1839.jpg +0 -0
  32. data/french_bulldog/n02108915_1866.jpg +0 -0
  33. data/french_bulldog/n02108915_1871.jpg +0 -0
  34. data/french_bulldog/n02108915_1895.jpg +0 -0
  35. data/french_bulldog/n02108915_1911.jpg +0 -0
  36. data/french_bulldog/n02108915_1958.jpg +0 -0
  37. data/french_bulldog/n02108915_198.jpg +0 -0
  38. data/french_bulldog/n02108915_4176.jpg +0 -0
  39. data/french_bulldog/n02108915_4193.jpg +0 -0
  40. data/french_bulldog/n02108915_4214.jpg +0 -0
  41. data/french_bulldog/n02108915_4303.jpg +0 -0
  42. data/french_bulldog/n02108915_4372.jpg +0 -0
  43. data/french_bulldog/n02108915_4474.jpg +0 -0
  44. data/french_bulldog/n02108915_4477.jpg +0 -0
  45. data/french_bulldog/n02108915_4603.jpg +0 -0
  46. data/french_bulldog/n02108915_4731.jpg +0 -0
  47. data/french_bulldog/n02108915_4776.jpg +0 -0
  48. data/french_bulldog/n02108915_481.jpg +0 -0
  49. data/french_bulldog/n02108915_4860.jpg +0 -0
  50. data/french_bulldog/n02108915_4901.jpg +0 -0
app.py CHANGED
@@ -24,12 +24,12 @@ BLENHEIM_SPANIEL_CLASS = 156
24
  def get_image_data(image_name):
25
  """Gets the image data and model."""
26
  image, model_and_data = [None, None]
27
- if (image_name == "imagenet_diego.png"):
28
  image = get_dataset_by_name("imagenet_diego", get_label=False)
29
  model_and_data = process_imagenet_get_model(image)
30
- elif (image_name == "mnist_9.png"):
31
- image = get_dataset_by_name(image_name, get_label=False)
32
- model_and_data = process_mnist_get_model(image)
33
 
34
 
35
  return image, model_and_data
@@ -49,7 +49,12 @@ def segmentation_generation(image_name, c_width, n_top, n_gif_imgs):
49
  segs = model_and_data["xtest_segs"]
50
  get_model = model_and_data["model"]
51
  label = model_and_data["label"]
52
- print("LABEL:", label)
 
 
 
 
 
53
 
54
  # Unpack instance and segments
55
  instance = xtest[0]
@@ -62,7 +67,7 @@ def segmentation_generation(image_name, c_width, n_top, n_gif_imgs):
62
  xtrain = get_xtrain(segments)
63
 
64
  prediction = np.argmax(cur_model(xtrain[:1]), axis=1)
65
- assert prediction == BLENHEIM_SPANIEL_CLASS, f"Prediction is {prediction} not {BLENHEIM_SPANIEL_CLASS}"
66
 
67
  # Compute explanation
68
  exp_init = BayesLocalExplanations(training_data=xtrain,
@@ -72,7 +77,7 @@ def segmentation_generation(image_name, c_width, n_top, n_gif_imgs):
72
  verbose=True)
73
  rout = exp_init.explain(classifier_f=cur_model,
74
  data=np.ones_like(xtrain[0]),
75
- label=BLENHEIM_SPANIEL_CLASS,
76
  cred_width=cred_width,
77
  focus_sample=False,
78
  l2=False)
@@ -93,11 +98,12 @@ if __name__ == "__main__":
93
  segmentation_generation,
94
  [
95
  inp,
96
- gr.inputs.Slider(minimum=0.01, maximum=0.8, step=0.001, default=0.1, label="cred_width", optional=False),
97
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=5, label="n_top_segs", optional=False),
98
  gr.inputs.Slider(minimum=10, maximum=50, step=1, default=20, label="n_gif_images", optional=False),
99
  ],
100
  outputs=out,
101
- examples=[["imagenet_diego.png", 0.01, 7, 50]]
 
102
  )
103
- iface.launch(show_error=True, enable_queue=True)
 
24
  def get_image_data(image_name):
25
  """Gets the image data and model."""
26
  image, model_and_data = [None, None]
27
+ if (image_name == "imagenet_diego"):
28
  image = get_dataset_by_name("imagenet_diego", get_label=False)
29
  model_and_data = process_imagenet_get_model(image)
30
+ elif (image_name == "imagenet_french_bulldog"):
31
+ image = get_dataset_by_name("imagenet_french_bulldog", get_label=False)
32
+ model_and_data = process_imagenet_get_model(image)
33
 
34
 
35
  return image, model_and_data
 
49
  segs = model_and_data["xtest_segs"]
50
  get_model = model_and_data["model"]
51
  label = model_and_data["label"]
52
+
53
+
54
+ if (image_name == 'imagenet_diego'):
55
+ label = 156
56
+ elif (image_name == 'imagenet_french_bulldog'):
57
+ label = 245
58
 
59
  # Unpack instance and segments
60
  instance = xtest[0]
 
67
  xtrain = get_xtrain(segments)
68
 
69
  prediction = np.argmax(cur_model(xtrain[:1]), axis=1)
70
+ assert prediction == label, f"Prediction is {prediction} not {label}"
71
 
72
  # Compute explanation
73
  exp_init = BayesLocalExplanations(training_data=xtrain,
 
77
  verbose=True)
78
  rout = exp_init.explain(classifier_f=cur_model,
79
  data=np.ones_like(xtrain[0]),
80
+ label=label,
81
  cred_width=cred_width,
82
  focus_sample=False,
83
  l2=False)
 
98
  segmentation_generation,
99
  [
100
  inp,
101
+ gr.inputs.Slider(minimum=0.01, maximum=0.8, step=0.01, default=0.1, label="cred_width", optional=False),
102
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=5, label="n_top_segs", optional=False),
103
  gr.inputs.Slider(minimum=10, maximum=50, step=1, default=20, label="n_gif_images", optional=False),
104
  ],
105
  outputs=out,
106
+ examples=[["imagenet_diego", 0.01, 7, 50],
107
+ ["imagenet_french_bulldog", 0.05, 5, 50]]
108
  )
109
+ iface.launch(enable_queue=True)
data/french_bulldog/n02108915_10204.jpg ADDED
data/french_bulldog/n02108915_10564.jpg ADDED
data/french_bulldog/n02108915_110.jpg ADDED
data/french_bulldog/n02108915_1114.jpg ADDED
data/french_bulldog/n02108915_1119.jpg ADDED
data/french_bulldog/n02108915_11207.jpg ADDED
data/french_bulldog/n02108915_11220.jpg ADDED
data/french_bulldog/n02108915_11327.jpg ADDED
data/french_bulldog/n02108915_11335.jpg ADDED
data/french_bulldog/n02108915_1137.jpg ADDED
data/french_bulldog/n02108915_11498.jpg ADDED
data/french_bulldog/n02108915_11550.jpg ADDED
data/french_bulldog/n02108915_11653.jpg ADDED
data/french_bulldog/n02108915_1188.jpg ADDED
data/french_bulldog/n02108915_12139.jpg ADDED
data/french_bulldog/n02108915_12288.jpg ADDED
data/french_bulldog/n02108915_12317.jpg ADDED
data/french_bulldog/n02108915_12319.jpg ADDED
data/french_bulldog/n02108915_12460.jpg ADDED
data/french_bulldog/n02108915_12618.jpg ADDED
data/french_bulldog/n02108915_12904.jpg ADDED
data/french_bulldog/n02108915_1343.jpg ADDED
data/french_bulldog/n02108915_142.jpg ADDED
data/french_bulldog/n02108915_1465.jpg ADDED
data/french_bulldog/n02108915_1513.jpg ADDED
data/french_bulldog/n02108915_160.jpg ADDED
data/french_bulldog/n02108915_1612.jpg ADDED
data/french_bulldog/n02108915_1752.jpg ADDED
data/french_bulldog/n02108915_1788.jpg ADDED
data/french_bulldog/n02108915_1839.jpg ADDED
data/french_bulldog/n02108915_1866.jpg ADDED
data/french_bulldog/n02108915_1871.jpg ADDED
data/french_bulldog/n02108915_1895.jpg ADDED
data/french_bulldog/n02108915_1911.jpg ADDED
data/french_bulldog/n02108915_1958.jpg ADDED
data/french_bulldog/n02108915_198.jpg ADDED
data/french_bulldog/n02108915_4176.jpg ADDED
data/french_bulldog/n02108915_4193.jpg ADDED
data/french_bulldog/n02108915_4214.jpg ADDED
data/french_bulldog/n02108915_4303.jpg ADDED
data/french_bulldog/n02108915_4372.jpg ADDED
data/french_bulldog/n02108915_4474.jpg ADDED
data/french_bulldog/n02108915_4477.jpg ADDED
data/french_bulldog/n02108915_4603.jpg ADDED
data/french_bulldog/n02108915_4731.jpg ADDED
data/french_bulldog/n02108915_4776.jpg ADDED
data/french_bulldog/n02108915_481.jpg ADDED
data/french_bulldog/n02108915_4860.jpg ADDED
data/french_bulldog/n02108915_4901.jpg ADDED