champ7 commited on
Commit
cbdda75
·
verified ·
1 Parent(s): 883aa4d

Update nellie.py

Browse files
Files changed (1) hide show
  1. nellie.py +14 -7
nellie.py CHANGED
@@ -120,11 +120,13 @@ def prepare_datasets(raw_tif_files, base_dir="generated_datasets"):
120
 
121
  return dirs
122
 
123
- def run_nellie_experiment(dataset_dir, combined_data_path, run_native_filter):
124
- files = sorted(glob.glob(os.path.join(dataset_dir, "*.TIF")))
 
125
  results, saved_masks = [], {}
126
 
127
  for filepath in tqdm(files, desc=f"Evaluating", leave=False):
 
128
  filename = os.path.basename(filepath)
129
  gt_mask_path = os.path.join(combined_data_path, filename.replace(".TIF", "_seg.npy"))
130
  if not os.path.exists(gt_mask_path): continue
@@ -220,20 +222,23 @@ def plot_single_experiment_visual(sample_filename, combined_data_path, data_src_
220
  # Main Execution Flow
221
  # =====================================================================
222
  def main():
223
- n_samples = 10 # Default set to 10
224
 
225
  logger.info("Downloading dataset...")
226
  dataset_dir = snapshot_download(repo_id="champ7/CEllDataW3", repo_type="dataset", allow_patterns="combined_data/*")
227
  combined_data_path = os.path.join(dataset_dir, "combined_data")
228
 
229
- # Randomly sample N files to drastically speed up testing
230
  raw_tif_files = sorted(glob.glob(os.path.join(combined_data_path, "*.TIF")))
231
  if n_samples and n_samples < len(raw_tif_files):
232
  random.seed(42) # Ensure the same random subset is used across runs
233
  raw_tif_files = random.sample(raw_tif_files, n_samples)
234
  logger.info(f"Subsampled dataset to {n_samples} random images.")
235
 
236
- sample_filename = os.path.basename(raw_tif_files[0]) # File to plot for each step
 
 
 
237
  dirs = prepare_datasets(raw_tif_files)
238
 
239
  configs = [
@@ -252,10 +257,12 @@ def main():
252
  for config in configs:
253
  logger.info(f"Running strategy: {config['name']}")
254
 
 
255
  metrics, saved_masks = run_nellie_experiment(
256
  dataset_dir=dirs[config["data_src"]],
257
  combined_data_path=combined_data_path,
258
- run_native_filter=config["run_filter"]
 
259
  )
260
 
261
  ious, precs, recs, f1s = [m[0] for m in metrics], [m[1] for m in metrics], [m[2] for m in metrics], [m[3] for m in metrics]
@@ -289,7 +296,7 @@ def main():
289
 
290
  # Print Final Summary Table
291
  print("\n" + "=" * 115)
292
- print(" " * 35 + f"FINAL 7-WAY EVALUATION REPORT (N={len(raw_tif_files)} images)")
293
  print("=" * 115)
294
  print(tabulate(aggregate_table, headers=headers, tablefmt="fancy_grid"))
295
 
 
120
 
121
  return dirs
122
 
123
+ def run_nellie_experiment(dataset_dir, combined_data_path, run_native_filter, target_filenames):
124
+ # EXPLICITLY use only the filenames we generated/sampled to prevent evaluating old data
125
+ files = [os.path.join(dataset_dir, fname) for fname in target_filenames]
126
  results, saved_masks = [], {}
127
 
128
  for filepath in tqdm(files, desc=f"Evaluating", leave=False):
129
+ if not os.path.exists(filepath): continue
130
  filename = os.path.basename(filepath)
131
  gt_mask_path = os.path.join(combined_data_path, filename.replace(".TIF", "_seg.npy"))
132
  if not os.path.exists(gt_mask_path): continue
 
222
  # Main Execution Flow
223
  # =====================================================================
224
  def main():
225
+ n_samples = 10 # Evaluate only 10 samples
226
 
227
  logger.info("Downloading dataset...")
228
  dataset_dir = snapshot_download(repo_id="champ7/CEllDataW3", repo_type="dataset", allow_patterns="combined_data/*")
229
  combined_data_path = os.path.join(dataset_dir, "combined_data")
230
 
231
+ # Extract complete list and sample N files
232
  raw_tif_files = sorted(glob.glob(os.path.join(combined_data_path, "*.TIF")))
233
  if n_samples and n_samples < len(raw_tif_files):
234
  random.seed(42) # Ensure the same random subset is used across runs
235
  raw_tif_files = random.sample(raw_tif_files, n_samples)
236
  logger.info(f"Subsampled dataset to {n_samples} random images.")
237
 
238
+ # Isolate just the filenames to pass to the evaluation loop
239
+ target_filenames = [os.path.basename(f) for f in raw_tif_files]
240
+
241
+ sample_filename = target_filenames[0] # File to plot for each step
242
  dirs = prepare_datasets(raw_tif_files)
243
 
244
  configs = [
 
257
  for config in configs:
258
  logger.info(f"Running strategy: {config['name']}")
259
 
260
+ # We now pass target_filenames to explicitly govern which files are read
261
  metrics, saved_masks = run_nellie_experiment(
262
  dataset_dir=dirs[config["data_src"]],
263
  combined_data_path=combined_data_path,
264
+ run_native_filter=config["run_filter"],
265
+ target_filenames=target_filenames
266
  )
267
 
268
  ious, precs, recs, f1s = [m[0] for m in metrics], [m[1] for m in metrics], [m[2] for m in metrics], [m[3] for m in metrics]
 
296
 
297
  # Print Final Summary Table
298
  print("\n" + "=" * 115)
299
+ print(" " * 35 + f"FINAL 7-WAY EVALUATION REPORT (N={len(target_filenames)} images)")
300
  print("=" * 115)
301
  print(tabulate(aggregate_table, headers=headers, tablefmt="fancy_grid"))
302