Fine-tuned MedSAM model for segmenting retinal layers (RNFL, GCL, IPL) in OCT B-scans.
pip install torch transformers Pillow numpy pandas matplotlib tqdm-
Open
run_inference.shand set:INPUT— path to an image, a directory of images, or a.csvfileOUTPUT— where to save results (default:./output)
-
Run:
bash run_inference.sh| Type | Example |
|---|---|
| Single image | INPUT="/data/scan.png" |
| Directory | INPUT="/data/oct_bscans/" |
| CSV file | INPUT="/data/scans.csv" |
Supported image formats: .png, .jpg, .jpeg, .tif, .tiff, .bmp
If using a CSV, it must have a column containing image paths. The default column name is file_path — change --image_col in run_inference.sh if yours differs.
For each image, the following are saved to OUTPUT:
| File | Description |
|---|---|
<stem>_mask.npy |
Binary segmentation mask as float32 array |
<stem>_vis.png |
Overlay visualization |
inference_results.csv |
Per-image paths summary |
inference_summary.json |
Run metadata |
Pass these directly to medsam_inference.py if needed:
| Flag | Default | Description |
|---|---|---|
--device |
0 |
GPU index; use -1 for CPU |
--threshold |
0.5 |
Sigmoid threshold for binary mask |
--image_col |
file_path |
CSV column containing image paths |
--no_vis |
off | Skip saving visualization PNGs |