Caleb Spradlin
commited on
Commit
•
4d01101
1
Parent(s):
a041e91
Initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +170 -0
- images/images/ft_demo_1000_1071_img.png +0 -0
- images/images/ft_demo_1000_1076_img.png +0 -0
- images/images/ft_demo_1000_1541_img.png +0 -0
- images/images/ft_demo_100_1071_img.png +0 -0
- images/images/ft_demo_100_1076_img.png +0 -0
- images/images/ft_demo_100_1541_img.png +0 -0
- images/images/ft_demo_10_1071_img.png +0 -0
- images/images/ft_demo_10_1076_img.png +0 -0
- images/images/ft_demo_10_1541_img.png +0 -0
- images/images/ft_demo_5000_1071_img.png +0 -0
- images/images/ft_demo_5000_1076_img.png +0 -0
- images/images/ft_demo_5000_1541_img.png +0 -0
- images/images/ft_demo_500_1071_img.png +0 -0
- images/images/ft_demo_500_1076_img.png +0 -0
- images/images/ft_demo_500_1541_img.png +0 -0
- images/labels/ft_demo_1000_1071_label.png +0 -0
- images/labels/ft_demo_1000_1076_label.png +0 -0
- images/labels/ft_demo_1000_1541_label.png +0 -0
- images/labels/ft_demo_100_1071_label.png +0 -0
- images/labels/ft_demo_100_1076_label.png +0 -0
- images/labels/ft_demo_100_1541_label.png +0 -0
- images/labels/ft_demo_10_1071_label.png +0 -0
- images/labels/ft_demo_10_1076_label.png +0 -0
- images/labels/ft_demo_10_1541_label.png +0 -0
- images/labels/ft_demo_5000_1071_label.png +0 -0
- images/labels/ft_demo_5000_1076_label.png +0 -0
- images/labels/ft_demo_5000_1541_label.png +0 -0
- images/labels/ft_demo_500_1071_label.png +0 -0
- images/labels/ft_demo_500_1076_label.png +0 -0
- images/labels/ft_demo_500_1541_label.png +0 -0
- images/predictions/10/cnn/ft_cnn_demo_10_1071_pred.png +0 -0
- images/predictions/10/cnn/ft_cnn_demo_10_1076_pred.png +0 -0
- images/predictions/10/cnn/ft_cnn_demo_10_1541_pred.png +0 -0
- images/predictions/10/svb/ft_demo_10_1071_pred.png +0 -0
- images/predictions/10/svb/ft_demo_10_1076_pred.png +0 -0
- images/predictions/10/svb/ft_demo_10_1541_pred.png +0 -0
- images/predictions/100/cnn/ft_cnn_demo_100_1071_pred.png +0 -0
- images/predictions/100/cnn/ft_cnn_demo_100_1076_pred.png +0 -0
- images/predictions/100/cnn/ft_cnn_demo_100_1541_pred.png +0 -0
- images/predictions/100/svb/ft_demo_100_1071_pred.png +0 -0
- images/predictions/100/svb/ft_demo_100_1076_pred.png +0 -0
- images/predictions/100/svb/ft_demo_100_1541_pred.png +0 -0
- images/predictions/1000/cnn/ft_cnn_demo_1000_1071_pred.png +0 -0
- images/predictions/1000/cnn/ft_cnn_demo_1000_1076_pred.png +0 -0
- images/predictions/1000/cnn/ft_cnn_demo_1000_1541_pred.png +0 -0
- images/predictions/1000/svb/ft_demo_1000_1071_pred.png +0 -0
- images/predictions/1000/svb/ft_demo_1000_1076_pred.png +0 -0
- images/predictions/1000/svb/ft_demo_1000_1541_pred.png +0 -0
- images/predictions/500/cnn/ft_cnn_demo_500_1071_pred.png +0 -0
app.py
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
|
5 |
+
# -----------------------------------------------------------------------------
|
6 |
+
# main
|
7 |
+
# -----------------------------------------------------------------------------
|
8 |
+
def main():
|
9 |
+
st.title("SatVision Few-Shot Comparison")
|
10 |
+
|
11 |
+
selected_option = st.select_slider(
|
12 |
+
"## Number of training samples",
|
13 |
+
options=[10, 100, 500, 1000, 5000])
|
14 |
+
|
15 |
+
st.markdown('Move slider to select how many training ' + \
|
16 |
+
'samples the models were trained on')
|
17 |
+
|
18 |
+
images = load_images(selected_option, Path('./images/images'))
|
19 |
+
|
20 |
+
labels = load_labels(selected_option, Path('./images/labels'))
|
21 |
+
|
22 |
+
preds = load_predictions(selected_option, Path('./images/predictions'))
|
23 |
+
|
24 |
+
zipped_st_images = zip(images, preds['svb'], preds['unet'], labels)
|
25 |
+
|
26 |
+
grid = make_grid(4, 4)
|
27 |
+
|
28 |
+
for i, (image_data, svb_data, unet_data, label_data) in \
|
29 |
+
enumerate(zipped_st_images):
|
30 |
+
|
31 |
+
if i == 0:
|
32 |
+
|
33 |
+
grid[0][0].markdown(f'## MOD09GA 3-2-1 Image Chip')
|
34 |
+
grid[0][1].markdown(f'## SatVision-B Prediction')
|
35 |
+
grid[0][2].markdown(f'## UNet (CNN) Prediction')
|
36 |
+
grid[0][3].markdown(f'## MCD12Q1 LandCover Target')
|
37 |
+
|
38 |
+
grid[i][0].image(image_data[0], image_data[1], use_column_width=True)
|
39 |
+
grid[i][1].image(svb_data[0], svb_data[1], use_column_width=True)
|
40 |
+
grid[i][2].image(unet_data[0], unet_data[1], use_column_width=True)
|
41 |
+
grid[i][3].image(label_data[0], label_data[1], use_column_width=True)
|
42 |
+
|
43 |
+
st.text("Additional Information:")
|
44 |
+
st.text("This is a placeholder for additional information about the images.")
|
45 |
+
|
46 |
+
# -----------------------------------------------------------------------------
|
47 |
+
# load_images
|
48 |
+
# -----------------------------------------------------------------------------
|
49 |
+
def load_images(selected_option: str, image_dir: Path):
|
50 |
+
"""
|
51 |
+
Given a selected option and image dir, return streamlit image objects.
|
52 |
+
"""
|
53 |
+
|
54 |
+
image_paths = find_images(selected_option, image_dir)
|
55 |
+
|
56 |
+
images = [(str(path), f"MOD09GA 3-2-1 H18v04 2019 Example {i}") for \
|
57 |
+
i, path in enumerate(image_paths, 1)]
|
58 |
+
|
59 |
+
return images
|
60 |
+
|
61 |
+
# -----------------------------------------------------------------------------
|
62 |
+
# find_images
|
63 |
+
# -----------------------------------------------------------------------------
|
64 |
+
def find_images(selected_option: str, image_dir: Path):
|
65 |
+
|
66 |
+
images_regex = f'ft_demo_{selected_option}_*_img.png'
|
67 |
+
|
68 |
+
images_matching_regex = sorted(image_dir.glob(images_regex))
|
69 |
+
|
70 |
+
assert len(images_matching_regex) == 3, "Should be 3 images matching regex"
|
71 |
+
|
72 |
+
assert '1071' in str(images_matching_regex[0]), 'Should be 1071'
|
73 |
+
|
74 |
+
return images_matching_regex
|
75 |
+
|
76 |
+
|
77 |
+
# -----------------------------------------------------------------------------
|
78 |
+
# load_labels
|
79 |
+
# -----------------------------------------------------------------------------
|
80 |
+
def load_labels(selected_option, label_dir: Path):
|
81 |
+
label_paths = find_labels(selected_option, label_dir)
|
82 |
+
|
83 |
+
labels = [(str(path), f"MCD12Q1 LandCover Target Example {i}") for \
|
84 |
+
i, path in enumerate(label_paths, 1)]
|
85 |
+
|
86 |
+
return labels
|
87 |
+
|
88 |
+
|
89 |
+
# -----------------------------------------------------------------------------
|
90 |
+
# find_labels
|
91 |
+
# -----------------------------------------------------------------------------
|
92 |
+
def find_labels(selected_option: str, label_dir: Path):
|
93 |
+
|
94 |
+
labels_regex = f'ft_demo_{selected_option}_*_label.png'
|
95 |
+
|
96 |
+
labels_matching_regex = sorted(label_dir.glob(labels_regex))
|
97 |
+
|
98 |
+
assert len(labels_matching_regex) == 3, \
|
99 |
+
"Should be 3 label images matching regex"
|
100 |
+
|
101 |
+
assert '1071' in str(labels_matching_regex[0]), 'Should be 1071'
|
102 |
+
|
103 |
+
return labels_matching_regex
|
104 |
+
|
105 |
+
|
106 |
+
# -----------------------------------------------------------------------------
|
107 |
+
# load_predictions
|
108 |
+
# -----------------------------------------------------------------------------
|
109 |
+
def load_predictions(selected_option: str, pred_dir: Path):
|
110 |
+
svb_pred_paths = find_preds(selected_option, pred_dir, 'svb')
|
111 |
+
|
112 |
+
unet_pred_paths = find_preds(selected_option, pred_dir, 'cnn')
|
113 |
+
|
114 |
+
svb_preds = [(str(path), f"SatVision-B Prediction Example {i}") for \
|
115 |
+
i, path in enumerate(svb_pred_paths, 1)]
|
116 |
+
|
117 |
+
unet_preds = [(str(path), f"Unet Prediction Example {i}") for \
|
118 |
+
i, path in enumerate(unet_pred_paths, 1)]
|
119 |
+
|
120 |
+
prediction_dict = {'svb': svb_preds, 'unet': unet_preds}
|
121 |
+
|
122 |
+
return prediction_dict
|
123 |
+
|
124 |
+
|
125 |
+
# -----------------------------------------------------------------------------
|
126 |
+
# find_preds
|
127 |
+
# -----------------------------------------------------------------------------
|
128 |
+
def find_preds(selected_option: int, pred_dir: Path, model: str):
|
129 |
+
|
130 |
+
if model == 'cnn':
|
131 |
+
|
132 |
+
pred_regex = f'ft_cnn_demo_{selected_option}_*_pred.png'
|
133 |
+
|
134 |
+
else:
|
135 |
+
pred_regex = f'ft_demo_{selected_option}_*_pred.png'
|
136 |
+
|
137 |
+
model_specific_dir = pred_dir / str(selected_option) / model
|
138 |
+
|
139 |
+
assert model_specific_dir.exists(), f'{model_specific_dir} does not exist'
|
140 |
+
|
141 |
+
preds_matching_regex = sorted(model_specific_dir.glob(pred_regex))
|
142 |
+
|
143 |
+
assert len(preds_matching_regex) == 3, \
|
144 |
+
"Should be 3 prediction images matching regex"
|
145 |
+
|
146 |
+
assert '1071' in str(preds_matching_regex[0]), 'Should be 1071'
|
147 |
+
|
148 |
+
return preds_matching_regex
|
149 |
+
|
150 |
+
|
151 |
+
# -----------------------------------------------------------------------------
|
152 |
+
# make_grid
|
153 |
+
# -----------------------------------------------------------------------------
|
154 |
+
def make_grid(cols,rows):
|
155 |
+
|
156 |
+
grid = [0]*cols
|
157 |
+
|
158 |
+
for i in range(cols):
|
159 |
+
|
160 |
+
with st.container():
|
161 |
+
|
162 |
+
grid[i] = st.columns(rows, gap='large')
|
163 |
+
|
164 |
+
return grid
|
165 |
+
|
166 |
+
# -----------------------------------------------------------------------------
|
167 |
+
# Main execution
|
168 |
+
# -----------------------------------------------------------------------------
|
169 |
+
if __name__ == "__main__":
|
170 |
+
main()
|
images/images/ft_demo_1000_1071_img.png
ADDED
images/images/ft_demo_1000_1076_img.png
ADDED
images/images/ft_demo_1000_1541_img.png
ADDED
images/images/ft_demo_100_1071_img.png
ADDED
images/images/ft_demo_100_1076_img.png
ADDED
images/images/ft_demo_100_1541_img.png
ADDED
images/images/ft_demo_10_1071_img.png
ADDED
images/images/ft_demo_10_1076_img.png
ADDED
images/images/ft_demo_10_1541_img.png
ADDED
images/images/ft_demo_5000_1071_img.png
ADDED
images/images/ft_demo_5000_1076_img.png
ADDED
images/images/ft_demo_5000_1541_img.png
ADDED
images/images/ft_demo_500_1071_img.png
ADDED
images/images/ft_demo_500_1076_img.png
ADDED
images/images/ft_demo_500_1541_img.png
ADDED
images/labels/ft_demo_1000_1071_label.png
ADDED
images/labels/ft_demo_1000_1076_label.png
ADDED
images/labels/ft_demo_1000_1541_label.png
ADDED
images/labels/ft_demo_100_1071_label.png
ADDED
images/labels/ft_demo_100_1076_label.png
ADDED
images/labels/ft_demo_100_1541_label.png
ADDED
images/labels/ft_demo_10_1071_label.png
ADDED
images/labels/ft_demo_10_1076_label.png
ADDED
images/labels/ft_demo_10_1541_label.png
ADDED
images/labels/ft_demo_5000_1071_label.png
ADDED
images/labels/ft_demo_5000_1076_label.png
ADDED
images/labels/ft_demo_5000_1541_label.png
ADDED
images/labels/ft_demo_500_1071_label.png
ADDED
images/labels/ft_demo_500_1076_label.png
ADDED
images/labels/ft_demo_500_1541_label.png
ADDED
images/predictions/10/cnn/ft_cnn_demo_10_1071_pred.png
ADDED
images/predictions/10/cnn/ft_cnn_demo_10_1076_pred.png
ADDED
images/predictions/10/cnn/ft_cnn_demo_10_1541_pred.png
ADDED
images/predictions/10/svb/ft_demo_10_1071_pred.png
ADDED
images/predictions/10/svb/ft_demo_10_1076_pred.png
ADDED
images/predictions/10/svb/ft_demo_10_1541_pred.png
ADDED
images/predictions/100/cnn/ft_cnn_demo_100_1071_pred.png
ADDED
images/predictions/100/cnn/ft_cnn_demo_100_1076_pred.png
ADDED
images/predictions/100/cnn/ft_cnn_demo_100_1541_pred.png
ADDED
images/predictions/100/svb/ft_demo_100_1071_pred.png
ADDED
images/predictions/100/svb/ft_demo_100_1076_pred.png
ADDED
images/predictions/100/svb/ft_demo_100_1541_pred.png
ADDED
images/predictions/1000/cnn/ft_cnn_demo_1000_1071_pred.png
ADDED
images/predictions/1000/cnn/ft_cnn_demo_1000_1076_pred.png
ADDED
images/predictions/1000/cnn/ft_cnn_demo_1000_1541_pred.png
ADDED
images/predictions/1000/svb/ft_demo_1000_1071_pred.png
ADDED
images/predictions/1000/svb/ft_demo_1000_1076_pred.png
ADDED
images/predictions/1000/svb/ft_demo_1000_1541_pred.png
ADDED
images/predictions/500/cnn/ft_cnn_demo_500_1071_pred.png
ADDED