def copy_kitti_native_code(checkpoint_name): """Copies and compiles kitti native code. It also creates neccessary directories for storing the results of the kitti native evaluation code. """ avod_root_dir = avod.root_dir() kitti_native_code_copy = avod_root_dir + '/data/outputs/' + \ checkpoint_name + '/predictions/kitti_native_eval/' # Only copy if the code has not been already copied over if not os.path.exists(kitti_native_code_copy): os.makedirs(kitti_native_code_copy) original_kitti_native_code = avod.top_dir() + \ '/scripts/offline_eval/kitti_native_eval/' predictions_dir = avod_root_dir + '/data/outputs/' + \ checkpoint_name + '/predictions/' # create dir for it first dir_util.copy_tree(original_kitti_native_code, kitti_native_code_copy) # run the script to compile the c++ code script_folder = predictions_dir + \ '/kitti_native_eval/' make_script = script_folder + 'run_make.sh' subprocess.call([make_script, script_folder]) # Set up the results folders if they don't exist results_dir = avod.top_dir() + '/scripts/offline_eval/results' results_05_dir = avod.top_dir() + '/scripts/offline_eval/results_05_iou' if not os.path.exists(results_dir): os.makedirs(results_dir) if not os.path.exists(results_05_dir): os.makedirs(results_05_dir)
def run_kitti_native_script_with_05_iou(checkpoint_name, score_threshold, global_step, output_dir=None): """Runs the kitti native code script.""" if output_dir is None: output_dir = avod.root_dir() + '/data/outputs/' eval_script_dir = os.path.join(output_dir,checkpoint_name) + \ '/predictions' make_script = eval_script_dir + \ '/kitti_native_eval/run_eval_05_iou.sh' script_folder = eval_script_dir + \ '/kitti_native_eval/' if output_dir is None: results_dir = avod.top_dir() + '/scripts/offline_eval/results_05_iou/' else: results_dir = os.path.join( output_dir, checkpoint_name) + '/offline_eval/results_05_iou/' # Round this because protobuf encodes default values as full decimal score_threshold = round(score_threshold, 3) subprocess.call([ make_script, script_folder, str(score_threshold), str(global_step), str(checkpoint_name), str(results_dir) ])
def run_kitti_native_script(checkpoint_name, score_threshold, global_step): """Runs the kitti native code script.""" eval_script_dir = avod.root_dir() + '/data/outputs/' + \ checkpoint_name + '/predictions' make_script = eval_script_dir + \ '/kitti_native_eval/run_eval.sh' script_folder = eval_script_dir + \ '/kitti_native_eval/' results_dir = avod.top_dir() + '/scripts/offline_eval/results/' # Round this because protobuf encodes default values as full decimal score_threshold = round(score_threshold, 3) subprocess.call([make_script, script_folder, str(score_threshold), str(global_step), str(checkpoint_name), str(results_dir)])
def run_profiler(pipeline_config_path, run_mode, data_split, ckpt_index): avod_top_dir = avod.top_dir() # Timeline results logfile file_name = avod_top_dir + '/scripts/profilers/tf_profiler/' + \ 'tf_timeline_output.json' with tf.Session() as sess: if run_mode == 'train': # In train mode, data_split should not be 'test' as the test # split does not have gt. if data_split == 'test': raise ValueError('Data split can only be train or val' 'in train mode.') model, train_op = set_up_model_train_mode(pipeline_config_path, data_split) init = tf.global_variables_initializer() sess.run(init) elif run_mode == 'test': model, model_config = set_up_model_test_mode( pipeline_config_path, data_split) paths_config = model_config.paths_config checkpoint_dir = paths_config.checkpoint_dir prediction_dict = model.build() # Load the weights saver = tf.train.Saver() trainer_utils.load_checkpoints(checkpoint_dir, saver) if not saver.last_checkpoints: raise ValueError('Need existing checkpoints to run' 'in test_mode') checkpoint_to_restore = saver.last_checkpoints[ckpt_index] saver.restore(sess, checkpoint_to_restore) else: raise ValueError('Invalid run_mode {}'.format(run_mode)) feed_dict = model.create_feed_dict() ############################################ # Parameters and Shapes ############################################ graph = tf.get_default_graph() # Print trainable variable parameter statistics to stdout. ProfileOptionBuilder = tf.profiler.ProfileOptionBuilder # Gives the total number of trainable parameters param_stats = tf.profiler.profile( graph, options=ProfileOptionBuilder.trainable_variables_parameter()) # Gives the FLOPS for the ops tf.profiler.profile( graph, options=tf.profiler.ProfileOptionBuilder.float_operation()) run_metadata = tf.RunMetadata() if run_mode == 'train': sess.run( [train_op], options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE), run_metadata=run_metadata, feed_dict=feed_dict) else: # Run in test mode sess.run( prediction_dict, options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE), run_metadata=run_metadata, feed_dict=feed_dict) # The profiler gives us rounded FLOP counts # So instead query it directly and count the total op_missing_shape = 0 # op_missing_shape_names = [] total_flops = 0 for op in graph.get_operations(): try: stats = ops.get_stats_for_node_def(graph, op.node_def, 'flops') if stats.value: total_flops += stats.value except ValueError: op_missing_shape += 1 # op_missing_shape_names.append(op.name) print('=============================================================') print('Number of ops with missing shape: ', op_missing_shape) print('=============================================================') ############################################ # Log Time and Memory ############################################ # Log the analysis to file # 'code' view organizes profile using Python call stack opts = ProfileOptionBuilder( ProfileOptionBuilder.time_and_memory()).with_timeline_output( file_name).build() tf.profiler.profile(graph, run_meta=run_metadata, cmd='code', options=opts) ############################################ # Show Time and Memory on the console ############################################ tf.profiler.profile( graph, run_meta=run_metadata, cmd='op', options=tf.profiler.ProfileOptionBuilder.time_and_memory()) # print the total number of parameters print('Total params: %d' % param_stats.total_parameters) print('Total FLOPs: ', total_flops) print('=============================================================')
import numpy as np import os from PIL import Image from wavedata.tools.obj_detection import obj_utils from wavedata.tools.obj_detection import evaluation from avod.core import box_3d_encoder, anchor_encoder, anchor_filter, anchor_projector from avod.core import grid_anchor_3d_generator from avod import top_dir PRO_ROOT = top_dir() class MiniBatchPreprocessor(object): def __init__(self, dataset): """Preprocesses anchors and saves info to files for RPN training Args: dataset: Dataset object mini_batch_dir: directory to save the info anchor_strides: anchor strides for generating anchors (per class) density_threshold: minimum number of points required to keep an anchor neg_iou_3d_range: 3D iou range for an anchor to be negative pos_iou_3d_range: 3D iou range for an anchor to be positive """ self._dataset = dataset
def run_kitti_native_script_with_05_iou(checkpoint_name, score_threshold, global_step, output_dir=None, do_eval_sin=False, do_eval_ain=False, sin_type='rand', sin_level=5, sin_repeat=10, sin_input_name=None, idx_repeat=None, data_split=None): """Runs the kitti native code script.""" if output_dir is None: output_dir = avod.root_dir() + '/data/outputs/' eval_script_dir = os.path.join(output_dir,checkpoint_name) + \ '/predictions' if do_eval_sin: eval_script_dir += '_sin_{}_{}_{}/{}'.format(sin_type, sin_level, sin_repeat, sin_input_name) elif do_eval_ain: eval_script_dir += '_ain_{}_{}_{}'.format(sin_type, sin_level, sin_repeat) make_script = eval_script_dir + \ '/kitti_native_eval/run_eval_05_iou.sh' script_folder = eval_script_dir + \ '/kitti_native_eval/' if output_dir is None: if do_eval_sin: results_dir = avod.top_dir() + \ '/scripts/offline_eval/results_05_iou_sin_{}_{}_{}/{}/'.format( sin_type, sin_level, sin_repeat, sin_input_name) elif do_eval_ain: results_dir = avod.top_dir() + \ '/scripts/offline_eval/results_05_iou_ain_{}_{}_{}/'.format( sin_type, sin_level, sin_repeat) else: results_dir = avod.top_dir() + \ '/scripts/offline_eval/results_05_iou/' else: if do_eval_sin: results_dir = os.path.join(output_dir,checkpoint_name) + \ '/offline_eval/results_05_iou_sin_{}_{}_{}/{}/'.format( sin_type, sin_level, sin_repeat, sin_input_name) elif do_eval_ain: results_dir = os.path.join(output_dir,checkpoint_name) + \ '/offline_eval/results_05_iou_ain_{}_{}_{}/'.format( sin_type, sin_level, sin_repeat) else: results_dir = os.path.join(output_dir,checkpoint_name) + \ '/offline_eval/results_05_iou/' # Round this because protobuf encodes default values as full decimal score_threshold = round(score_threshold, 3) if idx_repeat is None: offline_res_name = str(score_threshold) + '_' + data_split else: # result dir is different offline_res_name = str(score_threshold)+ '_' + data_split + \ '_{}_rep'.format(idx_repeat) subprocess.call([ make_script, script_folder, offline_res_name, str(global_step), str(checkpoint_name), str(results_dir) ])
def copy_kitti_native_code(checkpoint_name, output_dir=None, do_eval_sin=False, do_eval_ain=False, sin_type='rand', sin_level=5, sin_repeat=10, sin_input_names=None): """Copies and compiles kitti native code. It also creates neccessary directories for storing the results of the kitti native evaluation code. """ if output_dir is None: output_dir = avod.root_dir() + '/data/outputs/' if do_eval_sin: if sin_input_names is None: raise ValueError('{} must have list of sin input names.'.format( sin_input_names)) kitti_native_code_copies = [os.path.join(output_dir,checkpoint_name) + \ '/predictions_sin_{}_{}_{}/{}/kitti_native_eval/'.format( sin_type, sin_level, sin_repeat,sin_input_name) \ for sin_input_name in sin_input_names] elif do_eval_ain: kitti_native_code_copies = [os.path.join(output_dir,checkpoint_name) + \ '/predictions_ain_{}_{}_{}/kitti_native_eval/'.format( sin_type, sin_level, sin_repeat)] else: kitti_native_code_copies = [os.path.join(output_dir,checkpoint_name) + \ '/predictions/kitti_native_eval/'] # Only copy if the code has not been already copied over for (idx, kitti_native_code_copy) in enumerate(kitti_native_code_copies): if not os.path.exists(kitti_native_code_copy): os.makedirs(kitti_native_code_copy) original_kitti_native_code = avod.top_dir() + \ '/scripts/offline_eval/kitti_native_eval/' if do_eval_sin: predictions_dir = os.path.join(output_dir,checkpoint_name) + \ '/predictions_sin_{}_{}_{}/{}/'.format( sin_type, sin_level, sin_repeat,sin_input_names[idx]) elif do_eval_ain: predictions_dir = os.path.join(output_dir,checkpoint_name) + \ '/predictions_ain_{}_{}_{}/'.format( sin_type, sin_level, sin_repeat) else: predictions_dir = os.path.join(output_dir,checkpoint_name) + \ '/predictions/' # create dir for it first dir_util.copy_tree(original_kitti_native_code, kitti_native_code_copy) # run the script to compile the c++ code script_folder = predictions_dir + \ 'kitti_native_eval/' make_script = script_folder + 'run_make.sh' subprocess.call([make_script, script_folder]) # Set up the results folders if they don't exist if output_dir is None: results_dir = avod.top_dir() + '/scripts/offline_eval/results' results_05_dir = avod.top_dir( ) + '/scripts/offline_eval/results_05_iou' else: results_dir = os.path.join( output_dir, checkpoint_name) + '/offline_eval/results' results_05_dir = os.path.join( output_dir, checkpoint_name) + '/offline_eval/results_05_iou' if do_eval_sin: results_dir += '_sin_{}_{}_{}/{}'.format(sin_type, sin_level, sin_repeat, sin_input_names[idx]) results_05_dir += '_sin_{}_{}_{}/{}'.format( sin_type, sin_level, sin_repeat, sin_input_names[idx]) elif do_eval_ain: results_dir += '_ain_{}_{}_{}'.format(sin_type, sin_level, sin_repeat) results_05_dir += '_ain_{}_{}_{}'.format(sin_type, sin_level, sin_repeat) if not os.path.exists(results_dir): os.makedirs(results_dir) if not os.path.exists(results_05_dir): os.makedirs(results_05_dir)