soumickmj commited on
Commit
087ab59
·
1 Parent(s): 20c9c43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -12,6 +12,8 @@ from skimage.filters import threshold_otsu
12
  import torchio as tio
13
 
14
  def infer_full_vol(tensor, model):
 
 
15
  tensor = torch.movedim(tensor, -1, -3)
16
  tensor = tensor / tensor.max()
17
 
@@ -44,7 +46,7 @@ def infer_full_vol(tensor, model):
44
  return output.squeeze().detach().cpu().numpy()
45
 
46
  def infer_patch_based(tensor, model, patch_size=64, stride_length=32, stride_width=32, stride_depth=16, batch_size=10, num_worker=2):
47
- test_subject = tio.Subject(img = tio.ScalarImage(tensor=tensor.unsqueeze(0)))
48
  overlap = np.subtract(patch_size, (stride_length, stride_width, stride_depth))
49
 
50
  with torch.no_grad():
@@ -140,9 +142,6 @@ if uploaded_file is not None and process_button:
140
  st.write(f"Input tensor shape: `{tensor.shape}`")
141
  st.write(f"Selected pretrained model: `{selected_model}`")
142
 
143
- # Add batch and channel dimensions
144
- tensor = tensor.unsqueeze(0).unsqueeze(0) # Shape: [1, 1, D, H, W]
145
-
146
  # Construct the model name based on the selected model
147
  model_name = f"soumickmj/{selected_model}"
148
 
 
12
  import torchio as tio
13
 
14
  def infer_full_vol(tensor, model):
15
+ tensor = tensor.unsqueeze(0).unsqueeze(0) # Shape: [1, 1, D, H, W] - adding batch and channel dims
16
+
17
  tensor = torch.movedim(tensor, -1, -3)
18
  tensor = tensor / tensor.max()
19
 
 
46
  return output.squeeze().detach().cpu().numpy()
47
 
48
  def infer_patch_based(tensor, model, patch_size=64, stride_length=32, stride_width=32, stride_depth=16, batch_size=10, num_worker=2):
49
+ test_subject = tio.Subject(img = tio.ScalarImage(tensor=tensor.unsqueeze(0))) # adding channel dim while creating the TorchIO subject
50
  overlap = np.subtract(patch_size, (stride_length, stride_width, stride_depth))
51
 
52
  with torch.no_grad():
 
142
  st.write(f"Input tensor shape: `{tensor.shape}`")
143
  st.write(f"Selected pretrained model: `{selected_model}`")
144
 
 
 
 
145
  # Construct the model name based on the selected model
146
  model_name = f"soumickmj/{selected_model}"
147