Spaces:
Runtime error
Runtime error
rohithk-03
commited on
Commit
·
466ca4d
1
Parent(s):
b98361b
update model code
Browse files
app.py
CHANGED
@@ -299,22 +299,26 @@ def predict():
|
|
299 |
|
300 |
def remove_module_from_checkpoint(checkpoint):
|
301 |
new_state_dict = {}
|
|
|
302 |
for key, value in checkpoint.items():
|
303 |
new_key = key.replace("module.", "")
|
304 |
new_state_dict[new_key] = value
|
305 |
-
checkpoint
|
306 |
return checkpoint
|
307 |
checkpoint = remove_module_from_checkpoint(checkpoint)
|
308 |
model_new.load_state_dict(checkpoint)
|
309 |
image = Image.open(temp_path).convert("RGB")
|
310 |
output = model_new(transform(image).unsqueeze(0))
|
311 |
stage = output.item()
|
312 |
-
if
|
313 |
-
stage
|
314 |
-
|
315 |
-
stage
|
|
|
|
|
|
|
316 |
else:
|
317 |
-
stage = "
|
318 |
return jsonify({"message": a, "confidence": b, "stage": stage, "saved_path": image_save_path})
|
319 |
|
320 |
|
|
|
299 |
|
300 |
def remove_module_from_checkpoint(checkpoint):
|
301 |
new_state_dict = {}
|
302 |
+
print(checkpoint.keys())
|
303 |
for key, value in checkpoint.items():
|
304 |
new_key = key.replace("module.", "")
|
305 |
new_state_dict[new_key] = value
|
306 |
+
checkpoint = new_state_dict
|
307 |
return checkpoint
|
308 |
checkpoint = remove_module_from_checkpoint(checkpoint)
|
309 |
model_new.load_state_dict(checkpoint)
|
310 |
image = Image.open(temp_path).convert("RGB")
|
311 |
output = model_new(transform(image).unsqueeze(0))
|
312 |
stage = output.item()
|
313 |
+
if not a == "No ms detected":
|
314 |
+
if stage <= 2.0:
|
315 |
+
stage = "Mild"
|
316 |
+
elif stage >= 2.0 and stage <= 3.2:
|
317 |
+
stage = "Moderate"
|
318 |
+
else:
|
319 |
+
stage = "Severe"
|
320 |
else:
|
321 |
+
stage = "No ms detected"
|
322 |
return jsonify({"message": a, "confidence": b, "stage": stage, "saved_path": image_save_path})
|
323 |
|
324 |
|