How to use find_best_result method in Airtest

Best Python code snippet using Airtest

test_aircv.py

Source:test_aircv.py Github

copy

Full Screen

...26 def tearDownClass(cls):27 pass28 def test_find_template(self):29 """Template matching."""30 result = TemplateMatching(self.template_sch, self.template_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()31 self.assertIsInstance(result, dict)32 def test_find_all_template(self):33 """Template matching."""34 result = TemplateMatching(self.template_sch, self.template_src, threshold=self.THRESHOLD, rgb=self.RGB).find_all_results()35 self.assertIsInstance(result, list)36 def test_find_kaze(self):37 """KAZE matching."""38 # 较慢,稍微稳定一点.39 result = KAZEMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()40 self.assertIsInstance(result, dict)41 def test_find_brisk(self):42 """BRISK matching."""43 # 快,效果一般,不太稳定44 result = BRISKMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()45 self.assertIsInstance(result, dict)46 def test_find_akaze(self):47 """AKAZE matching."""48 # 较快,效果较差,很不稳定49 result = AKAZEMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()50 self.assertIsInstance(result, dict)51 def test_find_orb(self):52 """ORB matching."""53 # 很快,效果垃圾54 result = ORBMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()55 self.assertIsInstance(result, dict)56 def test_contrib_find_sift(self):57 """SIFT matching (----need OpenCV contrib module----)."""58 # 慢,最稳定59 result = SIFTMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()60 self.assertIsInstance(result, dict)61 def test_contrib_find_surf(self):62 """SURF matching (----need OpenCV contrib module----)."""63 # 快,效果不错64 result = SURFMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()65 self.assertIsInstance(result, dict)66 def test_contrib_find_brief(self):67 """BRIEF matching (----need OpenCV contrib module----)."""68 # 识别特征点少,只适合强特征图像的匹配69 result = BRIEFMatching(self.keypoint_sch, self.keypoint_src, threshold=self.THRESHOLD, rgb=self.RGB).find_best_result()70 self.assertIsInstance(result, dict)71 def test_contrib_func_find_sift(self):72 """Test find_sift function in sift.py."""73 result = find_sift(self.keypoint_src, self.keypoint_sch, threshold=self.THRESHOLD, rgb=self.RGB)74 self.assertIsInstance(result, dict)75 def test_func_find_template(self):76 """Test find_template function in template.py."""77 result = find_template(self.template_src, self.template_sch, threshold=0.9, rgb=self.RGB)78 self.assertIsInstance(result, dict)79 def test_func_find_all_template(self):80 """Test find_all_template function in template.py."""81 result = find_all_template(self.template_src, self.template_sch, threshold=0.9, rgb=self.RGB)82 self.assertIsInstance(result, list)83if __name__ == '__main__':...

Full Screen

Full Screen

common_filter_results_methods.py

Source:common_filter_results_methods.py Github

copy

Full Screen

...27 if metric!='nan':return img_dir28 29 print(f'#### no image found : {img_dir}')30 return None31def find_best_result(img_dir, metric_name='SSIM', metric_type= 'score'): #metric_type= loss/ score32 img_list = sorted(glob.glob(f"{img_dir}/*.jpg"),key= sort_name_by_epoch, reverse=True)33 min_loss=100034 final_img_dir= None35 36 metric_list=[]37 for img_dir in img_list:38 metric_dict = get_metric(img_dir)39 metric = metric_dict[metric_name]40 if metric!='nan':metric_list.append(metric)41 42 if len(metric_list)==0:43 print(f'#### no img_dir with exceptable metric is found : {img_dir}')44 return None45 min_metric= min(metric_list)46 max_metric= max(metric_list)47 48 for img_dir in img_list:49 metric_dict = get_metric(img_dir)50 metric = metric_dict[metric_name]51 52 img= plt.imread(img_dir)53 is_results_okay= 1 #img[100, 300].sum()< 76554 55 if is_results_okay and metric!='nan':56 #loss= float(loss)57 if metric_type== 'loss':58 if metric<min_metric+0.005:59 return img_dir60 elif metric_type== 'score':61 if metric>max_metric-0.005:62 return img_dir63 64 65 print(f'#### no image found : {img_dir}')66 return None67def get_img_list(img_dir = 'figs/mnistv6', mode='L1Loss', loss_threshold=0.05):68 exp_list = sorted(glob.glob(f'{img_dir}/*@*'))69 70 img_dirs=[]71 for idx in range(len(exp_list)):72 #if idx>102:break73 exp_dir = exp_list[idx]74 75 if mode=='last_converged_correct':img_dir = find_last_converged_correct_result(exp_dir, loss_threshold)76 elif mode=='last_converged_MSE':img_dir = find_last_converged_result(exp_dir, metric_name='MSE', metric_type= 'loss')77 elif mode=='L1Loss':img_dir = find_best_result(exp_dir, metric_name='L1Loss', metric_type= 'loss')78 elif mode=='MSE':img_dir = find_best_result(exp_dir, metric_name='MSE', metric_type= 'loss')79 elif mode=='SSIM':img_dir = find_best_result(exp_dir, metric_name='SSIM', metric_type= 'score')80 elif mode=='SSIM5':img_dir = find_best_result(exp_dir, metric_name='SSIM5', metric_type= 'score')81 elif mode=='SSIM11':img_dir = find_best_result(exp_dir, metric_name='SSIM11', metric_type= 'score')82 83 if idx%100==0:84 print(f'{idx+1}/{len(exp_list)} : {img_dir}')85 86 # exceptions87 #if idx==343:img_dir = find_last_converged_result(exp_dir, 0.130)88 ##89 90 if img_dir==None:91 continue92 93 94 img_dirs.append(img_dir)95 print(f'len img dirs : {len(img_dirs)}')...

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 Airtest 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