Hali5 commited on
Commit
982ac6c
·
1 Parent(s): ca73993

revert model back

Browse files
.gradio/cached_examples/17/indices.csv ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0
2
+ 1
3
+ 2
4
+ 3
5
+ 4
6
+ 5
7
+ 6
8
+ 7
9
+ 8
10
+ 9
11
+ 10
12
+ 11
13
+ 12
14
+ 13
15
+ 14
16
+ 15
17
+ 16
18
+ 17
19
+ 18
20
+ 19
21
+ 20
22
+ 21
23
+ 22
24
+ 23
25
+ 24
26
+ 25
27
+ 26
28
+ 27
29
+ 28
30
+ 29
31
+ 30
32
+ 31
33
+ 32
34
+ 33
35
+ 34
36
+ 35
37
+ 36
38
+ 37
39
+ 38
40
+ 39
41
+ 40
42
+ 41
43
+ 42
44
+ 43
45
+ 44
46
+ 45
47
+ 46
48
+ 47
49
+ 48
50
+ 49
51
+ 50
52
+ 51
53
+ 52
54
+ 53
55
+ 54
56
+ 55
57
+ 56
58
+ 57
59
+ 58
60
+ 59
61
+ 60
62
+ 61
63
+ 62
64
+ 63
65
+ 64
66
+ 65
67
+ 66
68
+ 67
69
+ 68
70
+ 69
71
+ 70
72
+ 71
73
+ 72
74
+ 73
75
+ 74
76
+ 75
77
+ 76
78
+ 77
79
+ 78
80
+ 79
81
+ 80
82
+ 81
83
+ 82
84
+ 83
85
+ 84
86
+ 85
87
+ 86
88
+ 87
89
+ 88
90
+ 89
91
+ 90
92
+ 91
93
+ 92
94
+ 93
95
+ 94
96
+ 95
97
+ 96
98
+ 97
99
+ 98
100
+ 99
101
+ 100
102
+ 101
103
+ 102
104
+ 103
105
+ 104
106
+ 105
107
+ 106
108
+ 107
109
+ 108
110
+ 109
111
+ 110
112
+ 111
113
+ 112
114
+ 113
115
+ 114
116
+ 115
117
+ 116
118
+ 117
119
+ 118
120
+ 119
121
+ 120
122
+ 121
123
+ 122
124
+ 123
125
+ 124
126
+ 125
127
+ 126
128
+ 127
129
+ 128
130
+ 129
131
+ 130
132
+ 131
133
+ 132
134
+ 133
135
+ 134
136
+ 135
137
+ 136
138
+ 137
139
+ 138
140
+ 139
141
+ 140
142
+ 141
143
+ 142
144
+ 143
145
+ 144
146
+ 145
147
+ 146
148
+ 147
149
+ 148
150
+ 149
151
+ 150
152
+ 151
153
+ 152
154
+ 153
155
+ 154
156
+ 155
157
+ 156
158
+ 157
159
+ 158
160
+ 159
161
+ 160
162
+ 161
163
+ 162
164
+ 163
165
+ 164
166
+ 165
167
+ 166
168
+ 167
169
+ 168
170
+ 169
171
+ 170
172
+ 171
173
+ 172
174
+ 173
175
+ 174
176
+ 175
177
+ 176
178
+ 177
179
+ 178
180
+ 179
181
+ 180
182
+ 181
183
+ 182
184
+ 183
185
+ 184
186
+ 185
187
+ 186
188
+ 187
189
+ 188
190
+ 189
191
+ 190
192
+ 191
193
+ 192
194
+ 193
195
+ 194
196
+ 195
197
+ 196
198
+ 197
199
+ 198
200
+ 199
201
+ 200
202
+ 201
203
+ 202
204
+ 203
205
+ 204
206
+ 205
207
+ 206
208
+ 207
209
+ 208
210
+ 209
211
+ 210
212
+ 211
213
+ 212
214
+ 213
215
+ 214
216
+ 215
217
+ 216
218
+ 217
219
+ 218
220
+ 219
221
+ 220
222
+ 221
223
+ 222
224
+ 223
225
+ 224
226
+ 225
227
+ 226
228
+ 227
229
+ 228
230
+ 229
231
+ 230
232
+ 231
233
+ 232
234
+ 233
235
+ 234
236
+ 235
237
+ 236
238
+ 237
239
+ 238
240
+ 239
241
+ 240
242
+ 241
243
+ 242
244
+ 243
245
+ 244
246
+ 245
247
+ 246
248
+ 247
249
+ 248
250
+ 249
251
+ 250
252
+ 251
253
+ 252
254
+ 253
255
+ 254
256
+ 255
.gradio/cached_examples/17/log.csv ADDED
The diff for this file is too large to render. See raw diff
 
.gradio/cached_examples/28/indices.csv ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0
2
+ 1
3
+ 2
4
+ 3
5
+ 7
6
+ 9
7
+ 8
8
+ 253
9
+ 252
10
+ 250
11
+ 255
12
+ 251
.gradio/cached_examples/28/log.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Model Prediction,timestamp
2
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.3632867634296417}, {""label"": ""Background"", ""confidence"": 0.20581191778182983}, {""label"": ""Smooth Muscle"", ""confidence"": 0.15993033349514008}, {""label"": ""Lymphocytes"", ""confidence"": 0.05527385324239731}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.052241407334804535}]}",2026-08-17 17:20:42.224079
3
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.2888142466545105}, {""label"": ""Smooth Muscle"", ""confidence"": 0.21987244486808777}, {""label"": ""Background"", ""confidence"": 0.19339622557163239}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.07815686613321304}, {""label"": ""Debris"", ""confidence"": 0.05767099931836128}]}",2026-08-17 17:21:10.878495
4
+ "{""label"": ""Smooth Muscle"", ""confidences"": [{""label"": ""Smooth Muscle"", ""confidence"": 0.41677364706993103}, {""label"": ""Adipose"", ""confidence"": 0.26999616622924805}, {""label"": ""Background"", ""confidence"": 0.06960488855838776}, {""label"": ""Mucus"", ""confidence"": 0.06531162559986115}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.046870503574609756}]}",2026-08-17 17:21:12.181611
5
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.4972829222679138}, {""label"": ""Background"", ""confidence"": 0.12184405326843262}, {""label"": ""Smooth Muscle"", ""confidence"": 0.09683744609355927}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.0623493455350399}, {""label"": ""Debris"", ""confidence"": 0.061689186841249466}]}",2026-08-17 17:21:13.582993
6
+ "{""label"": ""Background"", ""confidences"": [{""label"": ""Background"", ""confidence"": 0.9182832837104797}, {""label"": ""Mucus"", ""confidence"": 0.012001528404653072}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.011282394640147686}, {""label"": ""Lymphocytes"", ""confidence"": 0.010236880742013454}, {""label"": ""Normal Colon Mucosa"", ""confidence"": 0.010085840709507465}]}",2026-08-17 17:21:15.957606
7
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.5924761295318604}, {""label"": ""Smooth Muscle"", ""confidence"": 0.11955559253692627}, {""label"": ""Background"", ""confidence"": 0.0762282982468605}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.05226145684719086}, {""label"": ""Lymphocytes"", ""confidence"": 0.04672982543706894}]}",2026-08-17 17:21:20.870717
8
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.5278304219245911}, {""label"": ""Smooth Muscle"", ""confidence"": 0.17604735493659973}, {""label"": ""Background"", ""confidence"": 0.0776616781949997}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.045659247785806656}, {""label"": ""Lymphocytes"", ""confidence"": 0.04397842660546303}]}",2026-08-17 17:21:21.508202
9
+ "{""label"": ""Adipose"", ""confidences"": [{""label"": ""Adipose"", ""confidence"": 0.7484835386276245}, {""label"": ""Smooth Muscle"", ""confidence"": 0.06206844747066498}, {""label"": ""Background"", ""confidence"": 0.054249707609415054}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.024702735245227814}, {""label"": ""Mucus"", ""confidence"": 0.024689581245183945}]}",2026-08-17 17:21:28.091085
10
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.4644416570663452}, {""label"": ""Background"", ""confidence"": 0.13109032809734344}, {""label"": ""Smooth Muscle"", ""confidence"": 0.13060510158538818}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.07063549011945724}, {""label"": ""Lymphocytes"", ""confidence"": 0.058560699224472046}]}",2026-08-17 17:21:28.790322
11
+ "{""label"": ""Adipose"", ""confidences"": [{""label"": ""Adipose"", ""confidence"": 0.5562595129013062}, {""label"": ""Smooth Muscle"", ""confidence"": 0.14078371226787567}, {""label"": ""Background"", ""confidence"": 0.1093922033905983}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.04194163158535957}, {""label"": ""Debris"", ""confidence"": 0.041490957140922546}]}",2026-08-17 17:21:30.486527
12
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.6570587754249573}, {""label"": ""Smooth Muscle"", ""confidence"": 0.07533004134893417}, {""label"": ""Background"", ""confidence"": 0.05949338525533676}, {""label"": ""Colorectal Adenocarcinoma Epithelium"", ""confidence"": 0.051273688673973083}, {""label"": ""Debris"", ""confidence"": 0.04259587824344635}]}",2026-08-17 17:21:33.373855
13
+ "{""label"": ""Mucus"", ""confidences"": [{""label"": ""Mucus"", ""confidence"": 0.28708454966545105}, {""label"": ""Cancer-associated Stroma"", ""confidence"": 0.2425195723772049}, {""label"": ""Lymphocytes"", ""confidence"": 0.09387765824794769}, {""label"": ""Smooth Muscle"", ""confidence"": 0.08705379068851471}, {""label"": ""Debris"", ""confidence"": 0.08193457126617432}]}",2026-08-17 17:24:10.381773
.vscode/settings.json CHANGED
@@ -1,3 +1,3 @@
1
  {
2
- "python-envs.defaultEnvManager": "ms-python.python:pipenv"
3
  }
 
1
  {
2
+ "python-envs.defaultEnvManager": "ms-python.python:venv"
3
  }
app.py CHANGED
@@ -4,7 +4,7 @@ from torchvision.transforms import v2
4
  import gradio
5
  from PIL import Image
6
  from huggingface_hub import hf_hub_download
7
- from models.cross_predictor_hybrid import Predictor
8
  import numpy
9
  import os
10
 
@@ -26,7 +26,7 @@ model = Predictor(n_labels=len(LABELS))
26
 
27
  model_file = hf_hub_download(
28
  repo_id="Hali5/Mae-Model-MedMNIST-Predictor",
29
- filename="checkpoints/model_cross_reducer_hybrid_epoch_100.pt"
30
  )
31
 
32
  model.load_state_dict(torch.load(model_file,map_location=device))
@@ -39,11 +39,6 @@ tf = v2.Compose([
39
  v2.ToDtype(torch.float32, scale=True),
40
  ])
41
 
42
- sample_tf = v2.Compose([
43
- v2.ToImage(),
44
- v2.ToDtype(torch.float32, scale=True),
45
- ])
46
-
47
  dataset = numpy.load("test_samples.npz")
48
  images = dataset["images"]
49
  labels = dataset["labels"]
@@ -67,13 +62,6 @@ for i in range(number_of_examples):
67
  label_index = int(labels[i].item() if hasattr(labels[i], 'item') else labels[i])
68
  val_label_index = int(val_labels[i].item() if hasattr(val_labels[i], 'item') else val_labels[i])
69
 
70
- if hasattr(img_array, "transpose"):
71
- img_array = img_array.transpose(1, 2, 0)
72
- val_img_arr = val_img_arr.transpose(1, 2, 0)
73
- elif hasattr(img_array, "permute"):
74
- img_array = img_array.permute(1, 2, 0).cpu().numpy()
75
- val_img_arr = val_img_arr.permute(1, 2, 0).cpu().numpy()
76
-
77
  if img_array.max() <= 1.0:
78
  img_array = (img_array * 255).astype(numpy.uint8)
79
  val_img_arr = (val_img_arr * 255).astype(numpy.uint8)
@@ -94,29 +82,16 @@ for i in range(number_of_examples):
94
  example_rows_val.append([val_file_path, val_truth_label_text])
95
 
96
  @spaces.GPU
97
- def predict(image):
98
  if image is None:
99
  return None
100
-
101
  # uplouded image
102
  img_tensor = tf(image).unsqueeze(0).to(device)
103
 
104
  with torch.no_grad():
105
  outputs = model(img_tensor)
106
- probabilities = torch.nn.functional.softmax(outputs.squeeze(0), dim=0)
107
-
108
- return {LABELS[i]: float(probabilities[i]) for i in range(len(LABELS))}
109
-
110
- @spaces.GPU
111
- def sample_predict(image,truth_labels=None):
112
- if image is None:
113
- return None
114
-
115
- # already preprocessed test/val_samples
116
- img_tensor = sample_tf(image).unsqueeze(0).to(device)
117
-
118
- with torch.no_grad():
119
- outputs = model(img_tensor)
120
  probabilities = torch.nn.functional.softmax(outputs.squeeze(0), dim=0)
121
 
122
  return {LABELS[i]: float(probabilities[i]) for i in range(len(LABELS))}
@@ -138,7 +113,7 @@ with gradio.Blocks(css=custom_css) as demo:
138
  with gradio.Row():
139
  input_img = gradio.Image(height=512, width=512)
140
  with gradio.Column():
141
- output_lbl = gradio.Label(num_top_classes=5)
142
  btn = gradio.Button("Predict")
143
  btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
144
 
@@ -147,15 +122,15 @@ with gradio.Blocks(css=custom_css) as demo:
147
 
148
  with gradio.Row():
149
  with gradio.Column():
150
- input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
151
- truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
152
- output_lbl_ex = gradio.Label(num_top_classes=5, label="Model Prediction")
153
 
154
  gradio.Examples(
155
  examples=example_rows_val,
156
- inputs=[input_img_ex, truth_box],
157
- outputs=output_lbl_ex,
158
- fn=sample_predict,
159
  cache_examples=True,
160
  )
161
 
@@ -164,15 +139,15 @@ with gradio.Blocks(css=custom_css) as demo:
164
 
165
  with gradio.Row():
166
  with gradio.Column():
167
- input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
168
- truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
169
- output_lbl_ex = gradio.Label(num_top_classes=5, label="Model Prediction")
170
 
171
  gradio.Examples(
172
  examples=example_rows_test,
173
- inputs=[input_img_ex, truth_box],
174
- outputs=output_lbl_ex,
175
- fn=sample_predict,
176
  cache_examples=True,
177
  )
178
 
 
4
  import gradio
5
  from PIL import Image
6
  from huggingface_hub import hf_hub_download
7
+ from models.linear_predictor import Predictor
8
  import numpy
9
  import os
10
 
 
26
 
27
  model_file = hf_hub_download(
28
  repo_id="Hali5/Mae-Model-MedMNIST-Predictor",
29
+ filename="checkpoints/model_linear_v2_epoch_100.pt"
30
  )
31
 
32
  model.load_state_dict(torch.load(model_file,map_location=device))
 
39
  v2.ToDtype(torch.float32, scale=True),
40
  ])
41
 
 
 
 
 
 
42
  dataset = numpy.load("test_samples.npz")
43
  images = dataset["images"]
44
  labels = dataset["labels"]
 
62
  label_index = int(labels[i].item() if hasattr(labels[i], 'item') else labels[i])
63
  val_label_index = int(val_labels[i].item() if hasattr(val_labels[i], 'item') else val_labels[i])
64
 
 
 
 
 
 
 
 
65
  if img_array.max() <= 1.0:
66
  img_array = (img_array * 255).astype(numpy.uint8)
67
  val_img_arr = (val_img_arr * 255).astype(numpy.uint8)
 
82
  example_rows_val.append([val_file_path, val_truth_label_text])
83
 
84
  @spaces.GPU
85
+ def predict(image,truth_labels=True):
86
  if image is None:
87
  return None
88
+
89
  # uplouded image
90
  img_tensor = tf(image).unsqueeze(0).to(device)
91
 
92
  with torch.no_grad():
93
  outputs = model(img_tensor)
94
+ print(outputs.shape)
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  probabilities = torch.nn.functional.softmax(outputs.squeeze(0), dim=0)
96
 
97
  return {LABELS[i]: float(probabilities[i]) for i in range(len(LABELS))}
 
113
  with gradio.Row():
114
  input_img = gradio.Image(height=512, width=512)
115
  with gradio.Column():
116
+ output_lbl = gradio.Label(num_top_classes=9)
117
  btn = gradio.Button("Predict")
118
  btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
119
 
 
122
 
123
  with gradio.Row():
124
  with gradio.Column():
125
+ input_img_val_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
126
+ truth_box_val = gradio.Textbox(label="Ground Truth Label", interactive=False)
127
+ output_lbl_val_ex = gradio.Label(num_top_classes=9, label="Model Prediction")
128
 
129
  gradio.Examples(
130
  examples=example_rows_val,
131
+ inputs=[input_img_val_ex, truth_box_val],
132
+ outputs=output_lbl_val_ex,
133
+ fn=predict,
134
  cache_examples=True,
135
  )
136
 
 
139
 
140
  with gradio.Row():
141
  with gradio.Column():
142
+ input_img_test_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
143
+ truth_box_test = gradio.Textbox(label="Ground Truth Label", interactive=False)
144
+ output_lbl_test_ex = gradio.Label(num_top_classes=9, label="Model Prediction")
145
 
146
  gradio.Examples(
147
  examples=example_rows_test,
148
+ inputs=[input_img_test_ex, truth_box_test],
149
+ outputs=output_lbl_test_ex,
150
+ fn=predict,
151
  cache_examples=True,
152
  )
153
 
val_samples.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3085e9bbff8d470ed1375d618232b580ebb7fe8dbd0fd02c8a584e115936a5d6
3
- size 2618925
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0b19f9623a259251d6891de276f4c22cd1a24c1ff2c7700f21819262b229879
3
+ size 2646340