def load_config(): """ Loading the config and updating the data arguments(e.g., turn off the use_horizontal_flips, use_vertical_flips and rot_90) in the config class. Removing results data in the folder when running this class. Parsing the data from annotation file for testing process. """ curr_config = config.Config() if not os.path.exists(curr_config.results_image_path): os.makedirs(curr_config.results_image_path) if not os.path.exists(curr_config.results_video_path): os.makedirs(curr_config.results_video_path) if not os.path.exists(curr_config.result_graphs_path): os.makedirs(curr_config.result_graphs_path) if not os.path.exists(curr_config.result_graphs_path): os.makedirs(curr_config.result_graphs_path) remove_all_files(curr_config.result_graphs_path) remove_all_files(curr_config.results_image_path) remove_all_files(curr_config.results_video_path) with open(curr_config.train_config_output_filename, 'rb') as f_in: curr_config = pickle.load(f_in) # turn off any data augmentation at test time curr_config.use_horizontal_flips = False curr_config.use_vertical_flips = False curr_config.rot_90 = False if 'bg' not in curr_config.class_mapping: curr_config.class_mapping['bg'] = len(curr_config.class_mapping) class_mapping = {v: k for k, v in curr_config.class_mapping.items()} print('Class Mappings: ') pprint.pprint(class_mapping) class_to_color = {class_mapping[v]: np.random.randint(0, 255, 3) for v in class_mapping} # Save abnormal behaviour classes in class_mapping in config class. curr_config.class_mapping = class_mapping gt_records_count, ground_truth_data = get_data(curr_config.train_path_file, header=True, ground_truth=True) return curr_config, class_to_color, gt_records_count, ground_truth_data
def update_execute_config(): """ Loading the config and updating the config class. Removing results data in the folder when running this class. Setting the path to weights based on Faster R-CNN and VGG16 model. Parsing the data from annotation file for training process. :return classes_count: number of abnormal behaviour labels. :return class_mapping: abnormal behaviour classes(labels). :return all_imgs: all the training dataset. :return curr_config: updated config class. """ curr_config = config.Config() print("Clear the graph data in the folder {}".format( curr_config.result_graphs_path)) remove_file(curr_config.train_process_data_file) # check if weight path was passed via command line # Input path for weights. try to load default weights provided by keras. # set the path to weights based on backend and model curr_config.base_net_weights = nn.get_weight_path() # Path to training data. all_imgs, classes_count, class_mapping = get_data( curr_config.train_path_file, header=True) if 'bg' not in classes_count: classes_count['bg'] = 0 class_mapping['bg'] = len(class_mapping) curr_config.class_mapping = class_mapping print('Training images per class: ') pprint.pprint(classes_count) print('Num classes (including bg) = {}'.format(len(classes_count))) with open(curr_config.train_config_output_filename, 'wb') as config_f: pickle.dump(curr_config, config_f) print( 'Config has been written to {}, and can be loaded when testing to ensure correct results' .format(curr_config.train_config_output_filename)) num_imgs = len(all_imgs) print('Num all images {}'.format(num_imgs)) return classes_count, class_mapping, all_imgs, curr_config
def load_config_train(): """ Loading the config class and calling the remove_all_files and remove_all_file methods. Calling the get_data method from fast_rcnn folder to format the temporal_anomaly_annotation. :return curr_config: modified config class. :return temporal_anomaly_annotation: modified temporal_anomaly_annotation file. """ curr_config = config.Config() # creating a folder named data if not os.path.exists(curr_config.train_images_dataset_path): os.makedirs(curr_config.train_images_dataset_path) remove_all_files(curr_config.train_images_dataset_path) remove_file(curr_config.train_path_file) temporal_anomaly_annotation = get_data( curr_config.train_videos_annotation_file, temporal_anomaly_data=True) return curr_config, temporal_anomaly_annotation
from networks import GoogleNet as nn elif options.net == 'ResNet50': from networks import ResNet_50 as nn if K.image_data_format() == 'tf': base_net_weights = './model/resnet50_weights_th_dim_ordering_th_kernels_notop.h5' else: base_net_weights = './model/resnet50_weights_tf_dim_ordering_tf_kernels.h5' elif options.net == 'ResNet101': from networks import ResNet_101 as nn else: raise ValueError( "Command line option parser must be one of 'ZF' or 'VGG16' or 'GoogleNet' or 'ResNet50' or 'ResNet101'" ) # pass the settings from the command line, and persist them in the config object C = config.Config() all_imgs, classes_count, class_mapping = get_data(options.train_path) if 'bg' not in classes_count: classes_count['bg'] = 0 class_mapping['bg'] = len(class_mapping) C.class_mapping = class_mapping inv_map = {v: k for k, v in class_mapping.items()} print('Training images per class:') pprint.pprint(classes_count) print('Num classes (including bg) = {}'.format(len(classes_count))) config_output_filename = C.config_filename