55from datetime import datetime
66
77
8- def write_batch_script (env_name , out_path , inference_setup , checkpoint , model_type , experiment_folder ):
8+ def write_batch_script (env_name , out_path , inference_setup , checkpoint , model_type , experiment_folder , delay = True ):
99 """Writing scripts with different fold-trainings for micro-sam evaluation
1010 """
1111 batch_script = f"""#!/bin/bash
@@ -17,24 +17,40 @@ def write_batch_script(env_name, out_path, inference_setup, checkpoint, model_ty
1717#SBATCH -A nim00007
1818#SBATCH --job-name={ inference_setup }
1919
20- source ~/.bashrc
21- mamba activate { env_name }
22- python { inference_setup } .py """
20+ source ~/.bashrc
21+ mamba activate { env_name } \n """
22+
23+ if delay :
24+ batch_script += "sleep 10m \n "
25+
26+ # python script
27+ python_script = f"python { inference_setup } .py "
2328
2429 _op = out_path [:- 3 ] + f"_{ inference_setup } .sh"
2530
2631 # add the finetuned checkpoint
27- batch_script += f"-c { checkpoint } "
32+ python_script += f"-c { checkpoint } "
2833
2934 # name of the model configuration
30- batch_script += f"-m { model_type } "
35+ python_script += f"-m { model_type } "
3136
3237 # experiment folder
33- batch_script += f"-e { experiment_folder } "
38+ python_script += f"-e { experiment_folder } "
39+
40+ # let's add the python script to the bash script
41+ batch_script += python_script
3442
3543 with open (_op , "w" ) as f :
3644 f .write (batch_script )
3745
46+ # we run the first prompt for iterative once starting with point, and then starting with box (below)
47+ if inference_setup == "iterative_prompting" :
48+ batch_script += "--box "
49+
50+ new_path = out_path [:- 3 ] + f"_{ inference_setup } _box.sh"
51+ with open (new_path , "w" ) as f :
52+ f .write (batch_script )
53+
3854
3955def get_batch_script_names (tmp_folder ):
4056 tmp_folder = os .path .expanduser (tmp_folder )
@@ -56,11 +72,11 @@ def submit_slurm():
5672
5773 # parameters to run the inference scripts
5874 env_name = "sam"
59- checkpoint = "/scratch/usr/nimanwai/micro-sam/checkpoints/vit_h/livecell_sam/best.pt "
60- model_type = "vit_h "
61- experiment_folder = "/scratch/projects/nim00007/sam/experiments/new_models/specialists /livecell/vit_h /"
75+ model_type = "vit_b "
76+ checkpoint = f"/scratch/usr/nimanwai/micro-sam/checkpoints/ { model_type } /lm_generalist_sam/best.pt "
77+ experiment_folder = f "/scratch/projects/nim00007/sam/experiments/new_models/generalists /livecell/{ model_type } /"
6278
63- all_setups = ["evaluate_amg" , "evaluate_instance_segmentation" , "iterative_prompting" ]
79+ all_setups = ["precompute_embeddings" , " evaluate_amg" , "evaluate_instance_segmentation" , "iterative_prompting" ]
6480 for current_setup in all_setups :
6581 write_batch_script (
6682 env_name = env_name ,
@@ -69,6 +85,7 @@ def submit_slurm():
6985 checkpoint = checkpoint ,
7086 model_type = model_type ,
7187 experiment_folder = experiment_folder ,
88+ delay = False if current_setup == "precompute_embeddings" else True
7289 )
7390
7491 for my_script in glob (tmp_folder + "/*" ):
0 commit comments