unknownBrain commited on
Commit
263dc8b
·
verified ·
1 Parent(s): 1046d9f

Update Step 2 loader and dataload_utils with cross-platform laptop path resolution

Browse files
CMTLNet_complete_codebase_bundle.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8916609f7aa082ae3d058f388f774776378c619b90216ad451619a481a4d9f74
3
- size 25745064
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e386c80f14bb8e0965e984b5582a81c9271feeb2b5a82cae86ffa13c1215efea
3
+ size 25745375
code/Train_CMTLNet_Step2.py CHANGED
@@ -647,6 +647,10 @@ if __name__ == '__main__':
647
  import wandb
648
  cfe_pattern = f'results/CFE/Fold_{fold}/CFE_F1_*.pkl'
649
  cfe_files = glob.glob(cfe_pattern)
 
 
 
 
650
  if cfe_files:
651
  latest_cfe = max(cfe_files, key=os.path.getmtime)
652
  print(f"✅ Loading CFE model for Fold {fold}: {latest_cfe}")
 
647
  import wandb
648
  cfe_pattern = f'results/CFE/Fold_{fold}/CFE_F1_*.pkl'
649
  cfe_files = glob.glob(cfe_pattern)
650
+ if not cfe_files:
651
+ cfe_files = glob.glob(f'best_models/fixedone/Fold_{fold}/CFE_F1_*.pkl')
652
+ if not cfe_files:
653
+ cfe_files = glob.glob(f'../results/CFE/Fold_{fold}/CFE_F1_*.pkl')
654
  if cfe_files:
655
  latest_cfe = max(cfe_files, key=os.path.getmtime)
656
  print(f"✅ Loading CFE model for Fold {fold}: {latest_cfe}")
code/dataLoder/dataload_utils.py CHANGED
@@ -224,6 +224,26 @@ def random_crop(img_T1C, img_T2W, mask_input_img_T1C, mask_input_img_T2W, mask,
224
  return img_T1C, img_T2W, mask_input_img_T1C, mask_input_img_T2W, mask
225
 
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  def load_mask(path):
228
  """
229
  Load the mask image from the specified path.
@@ -234,6 +254,7 @@ def load_mask(path):
234
  Returns:
235
  - mask (numpy.ndarray): The mask data as a floating-point array.
236
  """
 
237
  mask_img_path = os.path.join(path, 'mask.nii.gz') # Construct the mask file path
238
  if not os.path.exists(mask_img_path):
239
  mask_img_path = os.path.join(path, 'mask.nii')
@@ -256,6 +277,7 @@ def load_img(path, type):
256
  - img_mask (numpy.ndarray): A binary mask indicating non-zero regions in the image.
257
  - affine (numpy.ndarray): The affine transformation matrix of the image.
258
  """
 
259
  # Construct the full file path by combining the directory path and file type
260
  full_path = os.path.join(path, f'{type}.nii.gz')
261
  if not os.path.exists(full_path):
 
224
  return img_T1C, img_T2W, mask_input_img_T1C, mask_input_img_T2W, mask
225
 
226
 
227
+ def resolve_patient_path(path):
228
+ """Dynamically resolve patient directory across environments (Server / Laptop / Windows / Linux)."""
229
+ if os.path.exists(path):
230
+ return path
231
+ pat_id = os.path.basename(path.rstrip('/\\'))
232
+ candidates = [
233
+ os.path.join(os.environ.get('DATA_ROOT', ''), pat_id),
234
+ os.path.join('data', 'ucsf_preprocess', pat_id),
235
+ os.path.join('..', 'data', 'ucsf_preprocess', pat_id),
236
+ os.path.join('..', '..', 'data', 'ucsf_preprocess', pat_id),
237
+ os.path.join('UCSF-PDGM-v5-preprocessed', pat_id),
238
+ os.path.join('D:\\jainam\\UCSF-PDGM-v5-preprocessed', pat_id),
239
+ os.path.join(r'D:\jainam\UCSF-PDGM-v5-preprocessed', pat_id) if os.name == 'nt' else '',
240
+ ]
241
+ for c in candidates:
242
+ if c and os.path.exists(c):
243
+ return c
244
+ return path
245
+
246
+
247
  def load_mask(path):
248
  """
249
  Load the mask image from the specified path.
 
254
  Returns:
255
  - mask (numpy.ndarray): The mask data as a floating-point array.
256
  """
257
+ path = resolve_patient_path(path)
258
  mask_img_path = os.path.join(path, 'mask.nii.gz') # Construct the mask file path
259
  if not os.path.exists(mask_img_path):
260
  mask_img_path = os.path.join(path, 'mask.nii')
 
277
  - img_mask (numpy.ndarray): A binary mask indicating non-zero regions in the image.
278
  - affine (numpy.ndarray): The affine transformation matrix of the image.
279
  """
280
+ path = resolve_patient_path(path)
281
  # Construct the full file path by combining the directory path and file type
282
  full_path = os.path.join(path, f'{type}.nii.gz')
283
  if not os.path.exists(full_path):