CindyBSydney
commited on
Commit
•
d6c3c84
1
Parent(s):
0af68ff
Update app.py
Browse files
app.py
CHANGED
@@ -35,6 +35,15 @@ model_ft = torch.load(GASTRIC_MODEL_PATH, map_location=device)
|
|
35 |
model_ft.to(device)
|
36 |
model_ft.eval()
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Anomaly detection and classification function
|
39 |
def classify_image(uploaded_image):
|
40 |
image = Image.open(uploaded_image).convert('RGB')
|
|
|
35 |
model_ft.to(device)
|
36 |
model_ft.eval()
|
37 |
|
38 |
+
# Anomaly detection function
|
39 |
+
def is_anomaly(clf, feature_extractor, input_image):
|
40 |
+
feature_extractor.to(device)
|
41 |
+
with torch.no_grad():
|
42 |
+
image_features = feature_extractor(input_image)
|
43 |
+
|
44 |
+
is_outlier = clf.predict(image_features.cpu().numpy().reshape(1, -1))
|
45 |
+
return is_outlier[0] == -1
|
46 |
+
|
47 |
# Anomaly detection and classification function
|
48 |
def classify_image(uploaded_image):
|
49 |
image = Image.open(uploaded_image).convert('RGB')
|