def F1Plot(maneuver_type,checkpoints,model_id,model_type,dataset_id): thresh_params = np.arange(.15, 1.0, .05) folds = ['fold_1', 'fold_2', 'fold_3', 'fold_4', 'fold_5'] F1 = np.zeros((thresh_params.shape[0],len(folds))) fid = 0 for fold,checkpoint in zip(folds,checkpoints): path_to_dataset = pathToDataset(maneuver_type,fold,dataset_id) path_to_checkpoint = pathToCheckpoint(maneuver_type,model_id,fold,checkpoint) precision,recall,anticipation_time = evaluateForAllThresholds(path_to_dataset,path_to_checkpoint,thresh_params,model_type) f1_score = 2.0*precision*recall / (precision+recall) F1[:,fid] = f1_score fid += 1 F1 = np.mean(F1,axis=1) st = '' for x in F1: st += str(100.0*x) + ',' st = st[:-1] print "************************" print "F1-score" print F1 print st print "Threshold values" print thresh_params print "************************"
results_mat_time = np.zeros( (thresh_params.shape[0], checkpoints_params.shape[0], len(folds) + 1)) count_th = 0 count_fold = 0 for fold in folds: count_checkpoint = 0 threads = [] for checkpoint in checkpoints_params: path_to_dataset = 'checkpoints/{0}/{1}/test_data_{2}.pik'.format( maneuver_type, fold, index) path_to_checkpoint = '{0}/{1}/{2}/checkpoint.{3}'.format( checkpoint_dir, fold, index, checkpoint) precision, recall, anticipation_time = evaluateForAllThresholds( path_to_dataset, path_to_checkpoint, thresh_params, architectures[model_type]) results_mat_precision[:, count_checkpoint, count_fold] = precision results_mat_recall[:, count_checkpoint, count_fold] = recall results_mat_time[:, count_checkpoint, count_fold] = anticipation_time count_checkpoint += 1 count_fold += 1 for count_th in range(len(thresh_params)): results_mat_recall[count_th, :, -1] = np.mean(results_mat_recall[count_th, :, :-1], axis=1) results_mat_precision[count_th, :, -1] = np.mean( results_mat_precision[count_th, :, :-1], axis=1) results_mat_time[count_th, :,
#checkpoint_dir = 'checkpoints' results_mat_precision = np.zeros((thresh_params.shape[0],checkpoints_params.shape[0],len(folds)+1)) results_mat_recall = np.zeros((thresh_params.shape[0],checkpoints_params.shape[0],len(folds)+1)) results_mat_time = np.zeros((thresh_params.shape[0],checkpoints_params.shape[0],len(folds)+1)) count_th = 0 count_fold = 0 for fold in folds: count_checkpoint = 0 threads=[] for checkpoint in checkpoints_params: path_to_dataset = 'checkpoints/{0}/{1}/test_data_{2}.pik'.format(maneuver_type,fold,index) path_to_checkpoint = '{0}/{1}/{2}/checkpoint.{3}'.format(checkpoint_dir,fold,index,checkpoint) precision,recall,anticipation_time = evaluateForAllThresholds(path_to_dataset,path_to_checkpoint,thresh_params,architectures[model_type]) results_mat_precision[:,count_checkpoint,count_fold] = precision results_mat_recall[:,count_checkpoint,count_fold] = recall results_mat_time[:,count_checkpoint,count_fold] = anticipation_time count_checkpoint += 1 count_fold += 1 for count_th in range(len(thresh_params)): results_mat_recall[count_th,:,-1] = np.mean(results_mat_recall[count_th,:,:-1],axis=1) results_mat_precision[count_th,:,-1] = np.mean(results_mat_precision[count_th,:,:-1],axis=1) results_mat_time[count_th,:,-1] = np.mean(results_mat_time[count_th,:,:-1],axis=1) results = {} results['precision'] = results_mat_precision results['recall'] = results_mat_recall