jpterry commited on
Commit
86d1c7a
·
1 Parent(s): 7826e16

added raw activations

Browse files
Files changed (1) hide show
  1. app.py +40 -27
app.py CHANGED
@@ -82,6 +82,37 @@ def get_activations(intermediate_model, image: list,
82
 
83
  return output, in_image, activation_1, activation_2
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  def predict_and_analyze(model_name, num_channels, dim, image):
87
 
@@ -130,31 +161,12 @@ def predict_and_analyze(model_name, num_channels, dim, image):
130
 
131
  origin = 'lower'
132
 
133
- ##### Make the activation figure ######
134
- plt.rcParams['xtick.labelsize'] = ticks
135
- plt.rcParams['ytick.labelsize'] = ticks
136
 
137
- fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(27, 12))
138
-
139
- ax1, ax2 = axs[0], axs[1]
140
-
141
- # im0 = ax0.imshow(input_image, cmap=cmap,
142
- # origin=origin)
143
- im1 = ax1.imshow(activation_1, cmap=cmap,
144
- origin=origin)
145
- im2 = ax2.imshow(activation_2, cmap=cmap,
146
- origin=origin)
147
-
148
- ims = [im1, im2]
149
-
150
- for (i, ax) in enumerate(axs):
151
- divider = make_axes_locatable(ax)
152
- cax = divider.append_axes('right', size='5%', pad=0.05)
153
- fig.colorbar(ims[i], cax=cax, orientation='vertical')
154
-
155
- # ax0.set_title('Input', fontsize=titles)
156
- ax1.set_title('Activation 1', fontsize=titles)
157
- ax2.set_title('Activation 2', fontsize=titles)
158
 
159
 
160
  ##### make the figure for the input image #####
@@ -168,13 +180,13 @@ def predict_and_analyze(model_name, num_channels, dim, image):
168
 
169
  divider = make_axes_locatable(ax)
170
  cax = divider.append_axes('right', size='5%', pad=0.05)
171
- fig.colorbar(im0, cax=cax, orientation='vertical')
172
 
173
  ax.set_title('Input', fontsize=titles)
174
 
175
  print("Sending to Hugging Face")
176
 
177
- return output, input_fig, fig
178
 
179
 
180
  if __name__ == "__main__":
@@ -199,7 +211,8 @@ if __name__ == "__main__":
199
  gr.Plot(label="Input Image", show_label=True),
200
  # gr.Image(label="Activation 1", show_label=True),
201
  # gr.Image(label="Actication 2", show_label=True)],
202
- gr.Plot(label="Activations", show_label=True)
 
203
  ],
204
  title="Kinematic Planet Detector"
205
  )
 
82
 
83
  return output, in_image, activation_1, activation_2
84
 
85
+ def plot_activations(activation_1, activation_2, origin='lower'):
86
+
87
+
88
+ ##### Make the activation figure ######
89
+ plt.rcParams['xtick.labelsize'] = ticks
90
+ plt.rcParams['ytick.labelsize'] = ticks
91
+
92
+ fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(27, 12))
93
+
94
+ ax1, ax2 = axs[0], axs[1]
95
+
96
+ # im0 = ax0.imshow(input_image, cmap=cmap,
97
+ # origin=origin)
98
+ im1 = ax1.imshow(activation_1, cmap=cmap,
99
+ origin=origin)
100
+ im2 = ax2.imshow(activation_2, cmap=cmap,
101
+ origin=origin)
102
+
103
+ ims = [im1, im2]
104
+
105
+ for (i, ax) in enumerate(axs):
106
+ divider = make_axes_locatable(ax)
107
+ cax = divider.append_axes('right', size='5%', pad=0.05)
108
+ fig.colorbar(ims[i], cax=cax, orientation='vertical')
109
+
110
+ # ax0.set_title('Input', fontsize=titles)
111
+ ax1.set_title('Activation 1', fontsize=titles)
112
+ ax2.set_title('Activation 2', fontsize=titles)
113
+
114
+ return fig
115
+
116
 
117
  def predict_and_analyze(model_name, num_channels, dim, image):
118
 
 
161
 
162
  origin = 'lower'
163
 
164
+ # plot mean subtracted activations
165
+ fig1 = plot_activations(activation_1, activation_2, origin=origin)
 
166
 
167
+ # plot raw activations
168
+ output, input_image, activation_1, activation_2 = get_activations(model, image, sub_mean=False)
169
+ fig2 = plot_activations(activation_1, activation_2, origin=origin)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
 
172
  ##### make the figure for the input image #####
 
180
 
181
  divider = make_axes_locatable(ax)
182
  cax = divider.append_axes('right', size='5%', pad=0.05)
183
+ input_fig.colorbar(im0, cax=cax, orientation='vertical')
184
 
185
  ax.set_title('Input', fontsize=titles)
186
 
187
  print("Sending to Hugging Face")
188
 
189
+ return output, input_fig, fig1, fig2
190
 
191
 
192
  if __name__ == "__main__":
 
211
  gr.Plot(label="Input Image", show_label=True),
212
  # gr.Image(label="Activation 1", show_label=True),
213
  # gr.Image(label="Actication 2", show_label=True)],
214
+ gr.Plot(label="Mean-Subtracted Activations", show_label=True),
215
+ gr.Plot(label="Raw Activations", show_label=True)
216
  ],
217
  title="Kinematic Planet Detector"
218
  )