Update
This commit is contained in:
		
							parent
							
								
									6394fd3e09
								
							
						
					
					
						commit
						8f5e076149
					
				|  | @ -1,12 +1,11 @@ | |||
| bayes: | ||||
|   iterations: 2 | ||||
|   iterations: 10 | ||||
| train: | ||||
|   epochs: | ||||
|     type: discrete | ||||
|     values: [10] | ||||
|     values: [30] | ||||
|   batch-size: | ||||
|     type: discrete | ||||
|     #values: [128] | ||||
|     min: 1 | ||||
|     max: 5 | ||||
|     step: 1 | ||||
|  | @ -18,12 +17,12 @@ train: | |||
|   img-size-start: | ||||
|     type: discrete | ||||
|     min: 512 | ||||
|     max: 576 | ||||
|     max: 1088 | ||||
|     step: 64 | ||||
|   img-size-end: | ||||
|     type: discrete | ||||
|     min: 512 | ||||
|     max: 576 | ||||
|     max: 1088 | ||||
|     step: 64 | ||||
|   rect: | ||||
|     type: discrete | ||||
|  | @ -122,16 +121,16 @@ detect: | |||
|   test-img-size: | ||||
|     type: discrete | ||||
|     min: 512 | ||||
|     max: 576 | ||||
|     max: 1088 | ||||
|     step: 64 | ||||
|   conf-thres: | ||||
|     type: continuous | ||||
|     min: 0.0 | ||||
|     max: 1.0 | ||||
|     min: 0.3 | ||||
|     max: 0.6 | ||||
|   iou-thres: | ||||
|     type: continuous | ||||
|     min: 0.0 | ||||
|     max: 1.0 | ||||
|     min: 0.3 | ||||
|     max: 0.6 | ||||
|   classes: | ||||
|   agnostic-nms: | ||||
|   augment: | ||||
|  |  | |||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -8,7 +8,8 @@ import traceback | |||
| import GPyOpt | ||||
| from config_bayes import Configuration | ||||
| 
 | ||||
| from utils import call_subprocess, get_values_from_conff_matrix | ||||
| from utils import call_subprocess, get_values_from_conff_matrix, load_previous_bayes_experiments | ||||
| 
 | ||||
| 
 | ||||
| dir_path = os.path.dirname(os.path.realpath(__file__)) | ||||
| PROJECT_ROOT = os.path.join(dir_path, '..') | ||||
|  | @ -19,7 +20,6 @@ config = Configuration(bayes_config_yaml) | |||
| date_string = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') | ||||
| bayes_params_file = open(os.path.join(PROJECT_ROOT, config.experiments.dir, f"{date_string}_bayes_params.txt"), 'a+') | ||||
| 
 | ||||
| 
 | ||||
| def call_training_script(gaussian_hyps): | ||||
|     cmd = 'python -u train.py' | ||||
|     cmd += ' --epochs ' + gaussian_hyps['epochs'].__str__() | ||||
|  | @ -149,7 +149,7 @@ def yolov3(x): | |||
|         y_dict = get_values_from_conff_matrix(conf_matrix_path) | ||||
| 
 | ||||
|         # tutaj wzór na wyliczanie funkcji  | ||||
|         y_val = 1 - ((y_dict['match'] * 10 - y_dict['false positives'] * 3) / y_dict['mistakes']) | ||||
|         y_val = 1 - (y_dict['match'] * 10 - y_dict['false positives'] * 3 - y_dict['mistakes']) / y_dict['all labels'] | ||||
| 
 | ||||
|         # zapisywanie do pliku zadeklarowanego globalnie | ||||
|         line = "\t".join([bayes_hyps.__str__(), str(y_val)]) | ||||
|  | @ -168,14 +168,9 @@ def yolov3(x): | |||
| if __name__ == '__main__': | ||||
|     bounds = config.get_bayes_bounds() | ||||
| 
 | ||||
|     # for b in bounds: | ||||
|     #   print(b) | ||||
| 
 | ||||
|     # tutaj będzie wczytywanie z poprzednich eksperymentów plik bayes_params | ||||
|     X = None | ||||
|     Y = None | ||||
| 
 | ||||
|     os.chdir(PROJECT_ROOT)  # change to project root directory | ||||
|     # wczytywanie z poprzednich eksperymentów plik bayes_params | ||||
|     X, Y =  load_previous_bayes_experiments(config.experiments.dir) | ||||
| 
 | ||||
|     bayes_optimizer = GPyOpt.methods.BayesianOptimization(f=yolov3, domain=bounds, X=X, Y=Y, verbosity=True, | ||||
|                                                           initial_design_numdata=2) | ||||
|  |  | |||
|  | @ -1,5 +1,9 @@ | |||
| import ast | ||||
| import io | ||||
| import os | ||||
| import subprocess | ||||
| import numpy as np | ||||
| from glob import glob | ||||
| 
 | ||||
| 
 | ||||
| def call_subprocess(cmd): | ||||
|  | @ -53,3 +57,37 @@ def get_bayes_params_as_dict(x): | |||
|         'conf-thres': float(x[:, 26]), | ||||
|         'iou-thres': float(x[:, 27]) | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| def load_previous_bayes_experiments(experiments_dir): | ||||
|     paths = list(glob(os.path.join(experiments_dir, '*bayes_params.txt'))) | ||||
|     y_values = [] | ||||
|     x_values = [] | ||||
| 
 | ||||
|     for p in paths: | ||||
|         file = open(p, 'r') | ||||
|         lines = file.readlines() | ||||
|         for line in lines: | ||||
|             try: | ||||
|                 dict_str, y_val = line.split('\t') | ||||
|                 bayes_dict = ast.literal_eval(dict_str) | ||||
|                 bayes_values = dict_to_numpy(bayes_dict) | ||||
|                 x_values.append(bayes_values) | ||||
|                 y_values.append(float(y_val)) | ||||
|             except: | ||||
|                 raise Exception(f"Cannot parse line {line} from file {p}") | ||||
|     return np.array(x_values), np.array(y_values).reshape((len(y_values), 1)) | ||||
| 
 | ||||
| 
 | ||||
| def dict_to_numpy(d): | ||||
|     x = [] | ||||
|     for key, value in d.items(): | ||||
|         if type(value) == bool: | ||||
|             x.append(int(value)) | ||||
|         elif key == 'img-size': | ||||
|             start_img_size, end_img_size = value.split(" ") | ||||
|             x.append(int(start_img_size)) | ||||
|             x.append(int(end_img_size)) | ||||
|         else: | ||||
|             x.append(float(value)) | ||||
|     return x | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue