Update app.py
Browse files
app.py
CHANGED
@@ -81,6 +81,22 @@ def cut(data0, wcs0, scale=1):
|
|
81 |
|
82 |
return data, wcs
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
def decompose_cavity(pred, th2=0.7, amin=10):
|
85 |
X, Y = pred.nonzero()
|
86 |
data = np.array([X,Y]).reshape(2, -1)
|
@@ -159,61 +175,53 @@ if uploaded_file is not None:
|
|
159 |
|
160 |
image = np.log10(data+1)
|
161 |
plot_image(image, scale)
|
162 |
-
|
163 |
-
if detect:
|
164 |
|
165 |
-
|
|
|
166 |
st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
|
167 |
threshold = st.slider("", 0.0, 1.0, 0.0, 0.05, label_visibility="hidden")
|
|
|
|
|
|
|
168 |
|
169 |
-
data, wcs = cut(data, wcs, scale=scale)
|
170 |
-
image = np.log10(data+1)
|
171 |
-
|
172 |
-
y_pred = 0
|
173 |
-
for j in [0,1,2,3]:
|
174 |
-
rotated = np.rot90(image, j)
|
175 |
-
pred = model.predict(rotated.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
176 |
-
pred = np.rot90(pred, -j)
|
177 |
-
y_pred += pred / 4
|
178 |
-
|
179 |
# np.save("pred.npy", y_pred)
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
if decompose:
|
191 |
-
# y_pred = np.load("thresh.npy")
|
192 |
-
|
193 |
-
cavs = decompose_cavity(y_pred_th)
|
194 |
-
|
195 |
-
# ccd = CCDData(y_pred, unit="adu", wcs=wcs)
|
196 |
-
# ccd.write(f"predictions/predicted.fits", overwrite=True)
|
197 |
-
image_decomposed = np.zeros((128,128))
|
198 |
-
for i, cav in enumerate(cavs):
|
199 |
-
# ccd = CCDData(cav, unit="adu", wcs=wcs)
|
200 |
-
# ccd.write(f"predictions/predicted_{i+1}.fits", overwrite=True)
|
201 |
-
image_decomposed += (i+1) * np.where(cav > 0, 1, 0)
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
#
|
217 |
-
#
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
return data, wcs
|
83 |
|
84 |
+
|
85 |
+
@st.cache_data
|
86 |
+
def cut_n_predict(data, scale):
|
87 |
+
data, wcs = cut(data, wcs, scale=scale)
|
88 |
+
image = np.log10(data+1)
|
89 |
+
|
90 |
+
y_pred = 0
|
91 |
+
for j in [0,1,2,3]:
|
92 |
+
rotated = np.rot90(image, j)
|
93 |
+
pred = model.predict(rotated.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
94 |
+
pred = np.rot90(pred, -j)
|
95 |
+
y_pred += pred / 4
|
96 |
+
|
97 |
+
return y_pred
|
98 |
+
|
99 |
+
# Define function to decomposed prediction into cavities
|
100 |
def decompose_cavity(pred, th2=0.7, amin=10):
|
101 |
X, Y = pred.nonzero()
|
102 |
data = np.array([X,Y]).reshape(2, -1)
|
|
|
175 |
|
176 |
image = np.log10(data+1)
|
177 |
plot_image(image, scale)
|
|
|
|
|
178 |
|
179 |
+
|
180 |
+
with col4:
|
181 |
st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
|
182 |
threshold = st.slider("", 0.0, 1.0, 0.0, 0.05, label_visibility="hidden")
|
183 |
+
|
184 |
+
if detect:
|
185 |
+
y_pred = predict(data, scale)
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
# np.save("pred.npy", y_pred)
|
188 |
|
189 |
+
# try: y_pred = np.load("pred.npy")
|
190 |
+
# except: y_pred = np.zeros((128,128))
|
191 |
+
try: y_pred
|
192 |
+
except: y_pred = np.zeros((128,128))
|
193 |
+
y_pred_th = np.where(y_pred > threshold, y_pred, 0)
|
194 |
+
# np.save("thresh.npy", y_pred)
|
195 |
|
196 |
+
plot_prediction(y_pred_th)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
if decompose:
|
199 |
+
# y_pred = np.load("thresh.npy")
|
200 |
+
|
201 |
+
cavs = decompose_cavity(y_pred_th)
|
202 |
+
|
203 |
+
# ccd = CCDData(y_pred, unit="adu", wcs=wcs)
|
204 |
+
# ccd.write(f"predictions/predicted.fits", overwrite=True)
|
205 |
+
image_decomposed = np.zeros((128,128))
|
206 |
+
for i, cav in enumerate(cavs):
|
207 |
+
# ccd = CCDData(cav, unit="adu", wcs=wcs)
|
208 |
+
# ccd.write(f"predictions/predicted_{i+1}.fits", overwrite=True)
|
209 |
+
image_decomposed += (i+1) * np.where(cav > 0, 1, 0)
|
210 |
+
|
211 |
+
# shutil.make_archive("predictions.zip", 'zip', "predictions")
|
212 |
+
# np.save("decomposed.npy", image_decomposed)
|
213 |
+
|
214 |
+
# try: image_decomposed = np.load("decomposed.npy")
|
215 |
+
# except: image_decomposed = np.zeros((128,128))
|
216 |
+
try: image_decomposed
|
217 |
+
except: image_decomposed = np.zeros((128,128))
|
218 |
+
plot_decomposed(image_decomposed)
|
219 |
+
|
220 |
+
# shutil.make_archive("predictions", 'zip', "predictions")
|
221 |
+
|
222 |
+
# with col6:
|
223 |
+
# ccd = CCDData(y_pred, unit="adu", wcs=wcs)
|
224 |
+
# # with open('predictions.zip', 'rb') as f:
|
225 |
+
# # res = f.read()
|
226 |
+
# st.markdown("""<style>[data-baseweb="select"] {margin-top: 16px;}</style>""", unsafe_allow_html=True)
|
227 |
+
# download = st.download_button(label="Download", data=ccd, file_name='prediction.fits', mime="application/octet-stream")
|