minor updates
Browse files
app.py
CHANGED
@@ -1,26 +1,12 @@
|
|
|
|
1 |
from matplotlib import cm
|
2 |
import matplotlib.pyplot as plt
|
3 |
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
4 |
-
|
5 |
import numpy as np
|
6 |
-
|
7 |
-
# import onnx
|
8 |
import onnxruntime as ort
|
9 |
-
# from onnx import helper
|
10 |
-
# from optimum.onnxruntime import ORTModel
|
11 |
-
|
12 |
-
# import pandas as pd
|
13 |
from PIL import Image
|
14 |
-
|
15 |
from scipy import special
|
16 |
|
17 |
-
# import torch
|
18 |
-
# import torch.utils.data
|
19 |
-
|
20 |
-
import gradio as gr
|
21 |
-
# from transformers import pipeline
|
22 |
-
|
23 |
-
|
24 |
# model_path = 'chlab/planet_detection_models/'
|
25 |
model_path = './models/'
|
26 |
|
@@ -64,7 +50,6 @@ def get_activations(intermediate_model, image: list,
|
|
64 |
|
65 |
input_name = intermediate_model.get_inputs()[0].name
|
66 |
outputs = intermediate_model.run(None, {input_name: image})
|
67 |
-
# outputs = intermediate_model(image)
|
68 |
|
69 |
output_1 = outputs[1]
|
70 |
output_2 = outputs[2]
|
@@ -72,19 +57,9 @@ def get_activations(intermediate_model, image: list,
|
|
72 |
output = outputs[0][0]
|
73 |
output = special.softmax(output)
|
74 |
|
75 |
-
# origin = 'lower'
|
76 |
-
|
77 |
-
# plt.rcParams['xtick.labelsize'] = ticks
|
78 |
-
# plt.rcParams['ytick.labelsize'] = ticks
|
79 |
-
|
80 |
-
# fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(28, 8))
|
81 |
-
|
82 |
-
# ax1, ax2, ax3 = axs[0], axs[1], axs[2]
|
83 |
-
|
84 |
in_image = np.sum(image[0, :, :, :], axis=0)
|
85 |
in_image = normalize_array(in_image)
|
86 |
-
|
87 |
-
# im1 = ax1.imshow(in_image, cmap=cmap, vmin=0, vmax=vmax, origin=origin)
|
88 |
if layer is None:
|
89 |
activation_1 = np.sum(output_1[0, :, :, :], axis=0)
|
90 |
activation_2 = np.sum(output_2[0, :, :, :], axis=0)
|
@@ -99,22 +74,6 @@ def get_activations(intermediate_model, image: list,
|
|
99 |
activation_2 -= np.mean(activation_2)
|
100 |
activation_2 = np.abs(activation_2)
|
101 |
|
102 |
-
|
103 |
-
# im2 = ax2.imshow(activation_1, cmap=cmap, #vmin=0, vmax=1,
|
104 |
-
# origin=origin)
|
105 |
-
# im3 = ax3.imshow(activation_2, cmap=cmap, #vmin=0, vmax=1,
|
106 |
-
# origin=origin)
|
107 |
-
# ims = [im1, im2, im3]
|
108 |
-
|
109 |
-
# for (i, ax) in enumerate(axs):
|
110 |
-
# divider = make_axes_locatable(ax)
|
111 |
-
# cax = divider.append_axes('right', size='5%', pad=0.05)
|
112 |
-
# fig.colorbar(ims[i], cax=cax, orientation='vertical')
|
113 |
-
|
114 |
-
# ax1.set_title('Input', fontsize=titles)
|
115 |
-
|
116 |
-
# plt.show()
|
117 |
-
|
118 |
return output, in_image, activation_1, activation_2
|
119 |
|
120 |
|
@@ -128,22 +87,10 @@ def predict_and_analyze(model_name, num_channels, dim, image):
|
|
128 |
|
129 |
num_channels = int(num_channels)
|
130 |
W = int(dim)
|
131 |
-
|
132 |
-
# image = image.read()
|
133 |
-
|
134 |
-
# with open(image, 'rb') as f:
|
135 |
-
# im = f.readlines()
|
136 |
-
# image = np.frombuffer(image)
|
137 |
-
|
138 |
print("Loading data")
|
139 |
image = np.load(image.name, allow_pickle=True)
|
140 |
|
141 |
-
# image = image.reshape((num_channels, W, W))
|
142 |
-
|
143 |
-
# W = int(np.sqrt(image.shape[1]))
|
144 |
-
|
145 |
-
# image = image.reshape((num_channels, W, W))
|
146 |
-
|
147 |
if len(image.shape) != 4:
|
148 |
image = image[np.newaxis, :, :, :]
|
149 |
|
@@ -182,9 +129,9 @@ def predict_and_analyze(model_name, num_channels, dim, image):
|
|
182 |
|
183 |
ax1, ax2 = axs[0], axs[1]
|
184 |
|
185 |
-
im1 = ax1.imshow(activation_1, cmap=cmap,
|
186 |
origin=origin)
|
187 |
-
im2 = ax2.imshow(activation_2, cmap=cmap,
|
188 |
origin=origin)
|
189 |
|
190 |
ims = [im1, im2]
|
@@ -224,7 +171,6 @@ if __name__ == "__main__":
|
|
224 |
# gr.Image(label="Activation 1", show_label=True),
|
225 |
# gr.Image(label="Actication 2", show_label=True)],
|
226 |
gr.Plot(label="Activations", show_label=True)
|
227 |
-
# gr.Plot(label="Actication 2", show_label=True)],
|
228 |
],
|
229 |
title="Kinematic Planet Detector"
|
230 |
)
|
|
|
1 |
+
import gradio as gr
|
2 |
from matplotlib import cm
|
3 |
import matplotlib.pyplot as plt
|
4 |
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
|
|
5 |
import numpy as np
|
|
|
|
|
6 |
import onnxruntime as ort
|
|
|
|
|
|
|
|
|
7 |
from PIL import Image
|
|
|
8 |
from scipy import special
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# model_path = 'chlab/planet_detection_models/'
|
11 |
model_path = './models/'
|
12 |
|
|
|
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]
|
|
|
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)
|
|
|
74 |
activation_2 -= np.mean(activation_2)
|
75 |
activation_2 = np.abs(activation_2)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
return output, in_image, activation_1, activation_2
|
78 |
|
79 |
|
|
|
87 |
|
88 |
num_channels = int(num_channels)
|
89 |
W = int(dim)
|
90 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
print("Loading data")
|
92 |
image = np.load(image.name, allow_pickle=True)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
if len(image.shape) != 4:
|
95 |
image = image[np.newaxis, :, :, :]
|
96 |
|
|
|
129 |
|
130 |
ax1, ax2 = axs[0], axs[1]
|
131 |
|
132 |
+
im1 = ax1.imshow(activation_1, cmap=cmap,
|
133 |
origin=origin)
|
134 |
+
im2 = ax2.imshow(activation_2, cmap=cmap,
|
135 |
origin=origin)
|
136 |
|
137 |
ims = [im1, im2]
|
|
|
171 |
# gr.Image(label="Activation 1", show_label=True),
|
172 |
# gr.Image(label="Actication 2", show_label=True)],
|
173 |
gr.Plot(label="Activations", show_label=True)
|
|
|
174 |
],
|
175 |
title="Kinematic Planet Detector"
|
176 |
)
|