jpterry commited on
Commit
d404815
·
1 Parent(s): e8779f0

minor updates

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -43,31 +43,37 @@ def load_model(model: str, activation: bool=True):
43
  return ort_session
44
 
45
  def get_activations(intermediate_model, image: list,
46
- layer=None, vmax=2.5, sub_mean=True):
47
 
48
  '''Gets activations for a given input image'''
49
 
50
-
51
  input_name = intermediate_model.get_inputs()[0].name
52
  outputs = intermediate_model.run(None, {input_name: image})
53
 
 
54
  output_1 = outputs[1]
55
  output_2 = outputs[2]
56
 
 
57
  output = outputs[0][0]
58
  output = special.softmax(output)
59
 
 
60
  in_image = np.sum(image[0, :, :, :], axis=0)
61
  in_image = normalize_array(in_image)
62
 
63
  if layer is None:
 
64
  activation_1 = np.sum(output_1[0, :, :, :], axis=0)
65
  activation_2 = np.sum(output_2[0, :, :, :], axis=0)
66
  else:
 
67
  activation_1 = output_1[0, layer, :, :]
68
  activation_2 = output_2[0, layer, :, :]
69
 
70
  if sub_mean:
 
71
  activation_1 -= np.mean(activation_1)
72
  activation_1 = np.abs(activation_1)
73
 
@@ -123,7 +129,6 @@ def predict_and_analyze(model_name, num_channels, dim, image):
123
 
124
  origin = 'lower'
125
 
126
-
127
  ##### Make the activation figure ######
128
  plt.rcParams['xtick.labelsize'] = ticks
129
  plt.rcParams['ytick.labelsize'] = ticks
@@ -157,7 +162,6 @@ def predict_and_analyze(model_name, num_channels, dim, image):
157
 
158
  input_fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(9, 8))
159
 
160
-
161
  im0 = ax.imshow(input_image, cmap=cmap,
162
  origin=origin)
163
 
 
43
  return ort_session
44
 
45
  def get_activations(intermediate_model, image: list,
46
+ layer=None, vmax=2.5, sub_mean=True):
47
 
48
  '''Gets activations for a given input image'''
49
 
50
+ # run model
51
  input_name = intermediate_model.get_inputs()[0].name
52
  outputs = intermediate_model.run(None, {input_name: image})
53
 
54
+ # get activations
55
  output_1 = outputs[1]
56
  output_2 = outputs[2]
57
 
58
+ # get prediction
59
  output = outputs[0][0]
60
  output = special.softmax(output)
61
 
62
+ # sum over velocity channels
63
  in_image = np.sum(image[0, :, :, :], axis=0)
64
  in_image = normalize_array(in_image)
65
 
66
  if layer is None:
67
+ # sum over all velocity channels
68
  activation_1 = np.sum(output_1[0, :, :, :], axis=0)
69
  activation_2 = np.sum(output_2[0, :, :, :], axis=0)
70
  else:
71
+ # select a single channel
72
  activation_1 = output_1[0, layer, :, :]
73
  activation_2 = output_2[0, layer, :, :]
74
 
75
  if sub_mean:
76
+ # y = |x - <x>|
77
  activation_1 -= np.mean(activation_1)
78
  activation_1 = np.abs(activation_1)
79
 
 
129
 
130
  origin = 'lower'
131
 
 
132
  ##### Make the activation figure ######
133
  plt.rcParams['xtick.labelsize'] = ticks
134
  plt.rcParams['ytick.labelsize'] = ticks
 
162
 
163
  input_fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(9, 8))
164
 
 
165
  im0 = ax.imshow(input_image, cmap=cmap,
166
  origin=origin)
167