amazinghaha commited on
Commit
d9a1752
·
1 Parent(s): 0563034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -51,22 +51,25 @@ def inference():
51
  model.eval()
52
  all_loss = 0
53
  length = 0
54
- with torch.no_grad():
55
- data = torch.from_numpy(data)
56
- image = torch.unsqueeze(data, 0)
57
- patch_data = torch.unsqueeze(image, 0).to(device).float() # (N, C_{in}, D_{in}, H_{in}, W_{in})
 
58
 
59
- # Pre : Prediction Result
60
- pre_probs = model(patch_data)
61
 
62
- # pre_probs = F.sigmoid(pre_probs)#todo
63
- pre_flat = pre_probs.view(-1)
64
- np.round(pre_flat.numpy()[0], decimals=2)
65
- #(1-pre_flat.numpy()[0]).astype(np.float32)
66
- #pre_flat.numpy()[0].astype(np.float32)
67
- p = float(np.round(pre_flat.numpy()[0], decimals=2))
68
- n = float(np.round(1-p, decimals=2))
69
- return {'急性期': n, '亚急性期': p}
 
 
70
 
71
 
72
 
@@ -131,7 +134,7 @@ def clear_all():
131
  global Current_name
132
  Current_name = None
133
  Image_3D = None
134
- return np.ones((10,10)),np.ones((10,10)),np.ones((10,10)),None,None,None
135
 
136
  class App:
137
  def __init__(self):
 
51
  model.eval()
52
  all_loss = 0
53
  length = 0
54
+ try:
55
+ with torch.no_grad():
56
+ data = torch.from_numpy(data)
57
+ image = torch.unsqueeze(data, 0)
58
+ patch_data = torch.unsqueeze(image, 0).to(device).float() # (N, C_{in}, D_{in}, H_{in}, W_{in})
59
 
60
+ # Pre : Prediction Result
61
+ pre_probs = model(patch_data)
62
 
63
+ # pre_probs = F.sigmoid(pre_probs)#todo
64
+ pre_flat = pre_probs.view(-1)
65
+ np.round(pre_flat.numpy()[0], decimals=2)
66
+ #(1-pre_flat.numpy()[0]).astype(np.float32)
67
+ #pre_flat.numpy()[0].astype(np.float32)
68
+ p = float(np.round(pre_flat.numpy()[0], decimals=2))
69
+ n = float(np.round(1-p, decimals=2))
70
+ return {'急性期': n, '亚急性期': p}
71
+ except:
72
+ return {'': ''}
73
 
74
 
75
 
 
134
  global Current_name
135
  Current_name = None
136
  Image_3D = None
137
+ return np.ones((10,10)),np.ones((10,10)),np.ones((10,10)),'','',{'': ''}
138
 
139
  class App:
140
  def __init__(self):