MingGatsby commited on
Commit
a56d0aa
1 Parent(s): 9c123f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -148,6 +148,8 @@ def load_model(root_dir, model_name, model_file_name):
148
  model = Build_Custom_Model(model_name, NUM_CLASSES, pretrained=False).to(device)
149
  else:
150
  model = SEResNet50(spatial_dims=2, in_channels=1, num_classes=NUM_CLASSES).to(device)
 
 
151
  model.load_state_dict(torch.load(os.path.join(root_dir, model_file_name), map_location=device))
152
  model.eval()
153
  return model
@@ -177,21 +179,8 @@ if uploaded_ct_file is not None:
177
  with tempfile.NamedTemporaryFile(delete=False, suffix=".dcm") as temp_file:
178
  temp_file.write(uploaded_ct_file.getvalue())
179
 
180
- # Debugging section to isolate the RuntimeError issue
181
- try:
182
- # Check if the temporary DICOM file is accessible and properly written
183
- if not os.path.exists(temp_file.name) or os.path.getsize(temp_file.name) == 0:
184
- print("Debugging: Temporary DICOM file is either missing or empty.")
185
-
186
- # Attempt to apply the evaluation transforms to the DICOM image
187
- image_tensor = eval_transforms(temp_file.name).unsqueeze(0).to(device)
188
-
189
- except Exception as e:
190
- print(f"Debugging: Exception caught while applying transform: {e}")
191
- raise
192
-
193
- # # Apply evaluation transforms to the DICOM image for model prediction
194
- # image_tensor = eval_transforms(temp_file.name).unsqueeze(0).to(device)
195
 
196
  # Predict
197
  with torch.no_grad():
 
148
  model = Build_Custom_Model(model_name, NUM_CLASSES, pretrained=False).to(device)
149
  else:
150
  model = SEResNet50(spatial_dims=2, in_channels=1, num_classes=NUM_CLASSES).to(device)
151
+ print(os.path.join(root_dir, model_file_name))
152
+ print("=================================")
153
  model.load_state_dict(torch.load(os.path.join(root_dir, model_file_name), map_location=device))
154
  model.eval()
155
  return model
 
179
  with tempfile.NamedTemporaryFile(delete=False, suffix=".dcm") as temp_file:
180
  temp_file.write(uploaded_ct_file.getvalue())
181
 
182
+ # Apply evaluation transforms to the DICOM image for model prediction
183
+ image_tensor = eval_transforms(temp_file.name).unsqueeze(0).to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  # Predict
186
  with torch.no_grad():