Spaces:
Runtime error
Runtime error
Commit ·
fc829e4
1
Parent(s): ecff45a
Upload app.py
Browse files
app.py
CHANGED
|
@@ -34,18 +34,29 @@ model3 = torch.load("model3.pt", map_location=torch.device('cpu'))
|
|
| 34 |
|
| 35 |
def fn(glycan, model):
|
| 36 |
if model == "No data augmentation":
|
| 37 |
-
|
| 38 |
-
|
| 39 |
elif model == "Ensemble":
|
| 40 |
-
|
| 41 |
-
|
| 42 |
else:
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
glycan = [glycan]
|
| 46 |
label = [0]
|
| 47 |
data = next(iter(dataset_to_dataloader(glycan, label, batch_size=1)))
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
pred = np.exp(pred)/sum(np.exp(pred)) # Softmax
|
| 50 |
pred = [float(x) for x in pred]
|
| 51 |
pred = {class_list[i]:pred[i] for i in range(15)}
|
|
|
|
| 34 |
|
| 35 |
def fn(glycan, model):
|
| 36 |
if model == "No data augmentation":
|
| 37 |
+
model_pred = model1
|
| 38 |
+
model_pred.eval()
|
| 39 |
elif model == "Ensemble":
|
| 40 |
+
model_pred = model3
|
| 41 |
+
model_pred.eval()
|
| 42 |
else:
|
| 43 |
+
model_pred = model2
|
| 44 |
+
model_pred.eval()
|
| 45 |
+
|
| 46 |
glycan = [glycan]
|
| 47 |
label = [0]
|
| 48 |
data = next(iter(dataset_to_dataloader(glycan, label, batch_size=1)))
|
| 49 |
+
if model == "Ensemble":
|
| 50 |
+
pred = model_pred(data)
|
| 51 |
+
else:
|
| 52 |
+
device = "cpu"
|
| 53 |
+
x = data.labels
|
| 54 |
+
edge_index = data.edge_index
|
| 55 |
+
batch = data.batch
|
| 56 |
+
x = x.to(device)
|
| 57 |
+
edge_index = edge_index.to(device)
|
| 58 |
+
batch = batch.to(device)
|
| 59 |
+
pred = model_pred(x,edge_index, batch).cpu().detach().numpy()[0]
|
| 60 |
pred = np.exp(pred)/sum(np.exp(pred)) # Softmax
|
| 61 |
pred = [float(x) for x in pred]
|
| 62 |
pred = {class_list[i]:pred[i] for i in range(15)}
|