How to use get_hook_params method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

script_generator_discreteMI.py

Source:script_generator_discreteMI.py Github

copy

Full Screen

...21 model_checkpoint=model_checkpoint)22 self.hook_config = yaml_load(PROJECT_PATH + "/" + opt_hook_path[self.get_hook_name()])23 def get_hook_name(self):24 return "udaiic"25 def get_hook_params(self, feature_names, mi_weights, consistency_weight, two_stage, dense_paddings):26 return {"DiscreteMIConsistencyParams":27 {"feature_names": feature_names, "mi_weights": mi_weights,28 "consistency_weight": consistency_weight,29 "dense_paddings": dense_paddings},30 "Trainer": {"two_stage": two_stage}31 }32 def generate_single_script(self, save_dir, labeled_scan_num, seed, hook_path):33 from semi_seg import ft_lr_zooms34 ft_lr = ft_lr_zooms[self._data_name]35 return f"python main.py Trainer.name=semi Trainer.save_dir={save_dir} " \36 f" Optim.lr={ft_lr:.7f} RandomSeed={str(seed)} Data.labeled_scan_num={int(labeled_scan_num)} " \37 f" {' '.join(self.conditions)} " \38 f" --opt-path {hook_path}"39 def grid_search_on(self, *, seed, **kwargs):40 jobs = []41 labeled_scan_list = ratio_zoo[self._data_name][:-1] if len(ratio_zoo[self._data_name]) > 1 else ratio_zoo[42 self._data_name]43 for param in grid_search(**{**kwargs, **{"seed": seed}}):44 random_seed = param.pop("seed")45 hook_params = self.get_hook_params(**param)46 sub_save_dir = self._get_hyper_param_string(**param)47 merged_config = dictionary_merge_by_hierachy(self.hook_config, hook_params)48 config_path = write_yaml(merged_config, save_dir=TEMP_DIR, save_name=utils.random_string() + ".yaml")49 true_save_dir = os.path.join(self._save_dir, "Seed_" + str(random_seed), sub_save_dir)50 job = " && ".join(51 [self.generate_single_script(save_dir=os.path.join(true_save_dir, "tra", f"labeled_scan_{l:02d}"),52 seed=random_seed, hook_path=config_path, labeled_scan_num=l)53 for l in labeled_scan_list])54 jobs.append(job)55 return jobs56if __name__ == '__main__':57 parser = argparse.ArgumentParser("udaiic method")58 parser.add_argument("--data-name", required=True, type=str, help="dataset_name",59 choices=["acdc", "prostate", "mmwhsct"])...

Full Screen

Full Screen

script_generator_pretrain.py

Source:script_generator_pretrain.py Github

copy

Full Screen

...15 pre_max_epoch=pre_max_epoch, ft_max_epoch=ft_max_epoch)16 self.hook_config = yaml_load(PROJECT_PATH + "/" + opt_hook_path[self.get_hook_name()])17 def get_hook_name(self):18 return "infonce"19 def get_hook_params(self, weight, contrast_on):20 return {"InfonceParams": {"weights": weight,21 "contrast_ons": contrast_on}}22 def grid_search_on(self, *, seed, **kwargs):23 jobs = []24 for param in grid_search(**{**kwargs, **{"seed": seed}}):25 random_seed = param.pop("seed")26 hook_params = self.get_hook_params(**param)27 sub_save_dir = self._get_hyper_param_string(**param)28 merged_config = dictionary_merge_by_hierachy(self.hook_config, hook_params)29 config_path = write_yaml(merged_config, save_dir=TEMP_DIR, save_name=utils.random_string() + ".yaml")30 true_save_dir = os.path.join(self._save_dir, "Seed_" + str(random_seed), sub_save_dir)31 job = self.generate_single_script(save_dir=true_save_dir,32 seed=random_seed, hook_path=config_path)33 jobs.append(job)34 return jobs35class PretrainSPInfoNCEScriptGenerator(PretrainInfoNCEScriptGenerator):36 def get_hook_name(self):37 return "spinfonce"38 def get_hook_params(self, weight, contrast_on, begin_values, end_values, mode, correct_grad):39 return {"SPInfonceParams": {"weights": weight,40 "contrast_ons": contrast_on,41 "begin_values": begin_values,42 "end_values": end_values,43 "mode": mode,44 "correct_grad": correct_grad45 }}46if __name__ == '__main__':47 submittor = JobSubmiter(on_local=True, project_path="../", time=4)48 submittor.prepare_env([49 "module load python/3.8.2 ",50 f"source ~/venv/bin/activate ",51 'if [ $(which python) == "/usr/bin/python" ]',52 "then",...

Full Screen

Full Screen

script_generator_adv.py

Source:script_generator_adv.py Github

copy

Full Screen

...18 model_checkpoint=model_checkpoint)19 self.hook_config = yaml_load(PROJECT_PATH + "/" + opt_hook_path[self.get_hook_name()])20 def get_hook_name(self):21 return "adv"22 def get_hook_params(self, reg_weight, dis_consider_image):23 return {"Trainer": {"reg_weight": reg_weight, "dis_consider_image": dis_consider_image}}24 def generate_single_script(self, save_dir, labeled_scan_num, seed, hook_path):25 from semi_seg import ft_lr_zooms26 ft_lr = ft_lr_zooms[self._data_name]27 return f"python main_adv.py Trainer.save_dir={save_dir} " \28 f" Optim.lr={ft_lr:.7f} RandomSeed={str(seed)} Data.labeled_scan_num={int(labeled_scan_num)} " \29 f" {' '.join(self.conditions)} " \30 f" --opt-path {hook_path}"31 def grid_search_on(self, *, seed, **kwargs):32 jobs = []33 labeled_scan_list = ratio_zoo[self._data_name][:-1] if len(ratio_zoo[self._data_name]) > 1 else ratio_zoo[34 self._data_name]35 for param in grid_search(**{**kwargs, **{"seed": seed}}):36 random_seed = param.pop("seed")37 hook_params = self.get_hook_params(**param)38 sub_save_dir = self._get_hyper_param_string(**param)39 merged_config = dictionary_merge_by_hierachy(self.hook_config, hook_params)40 config_path = write_yaml(merged_config, save_dir=TEMP_DIR, save_name=utils.random_string() + ".yaml")41 true_save_dir = os.path.join(self._save_dir, "Seed_" + str(random_seed), sub_save_dir)42 job = " && ".join(43 [self.generate_single_script(save_dir=os.path.join(true_save_dir, "tra", f"labeled_scan_{l:02d}"),44 seed=random_seed, hook_path=config_path, labeled_scan_num=l)45 for l in labeled_scan_list])46 jobs.append(job)47 return jobs48if __name__ == '__main__':49 parser = argparse.ArgumentParser("adv method")50 parser.add_argument("--data-name", required=True, type=str, help="dataset_name",51 choices=["acdc", "prostate", "mmwhsct"])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful