def build_lookup_table(self, network_def_full, resource_type, lookup_table_path, min_conv_feature_size=_MIN_CONV_FEATURE_SIZE, min_fc_feature_size=_MIN_FC_FEATURE_SIZE, measure_latency_batch_size=_MEASURE_LATENCY_BATCH_SIZE, measure_latency_sample_times=_MEASURE_LATENCY_SAMPLE_TIMES, verbose=True): # Build lookup table for latency ''' please refer to def build_latency_lookup_table(...) in functions.py ''' return fns.build_latency_lookup_table(network_def_full, lookup_table_path, min_conv_feature_size=min_conv_feature_size, min_fc_feature_size=min_fc_feature_size, measure_latency_batch_size=measure_latency_batch_size, measure_latency_sample_times=measure_latency_sample_times, verbose=verbose)
num_w = fns.compute_resource(network_def, 'WEIGHTS') flops = fns.compute_resource(network_def, 'FLOPS') num_param = fns.compute_resource(network_def, 'WEIGHTS') print('Number of FLOPs: ', flops) print('Number of weights: ', num_w) print('Number of parameters: ', num_param) print('-------------------------------------------') model = model.cuda() print('Building latency lookup table for', torch.cuda.get_device_name()) if build_lookup_table: fns.build_latency_lookup_table( network_def, lookup_table_path=lookup_table_path, min_fc_feature_size=MIN_FC_FEATRE_SIZE, min_conv_feature_size=MIN_CONV_FEATURE_SIZE, measure_latency_batch_size=MEASURE_LATENCY_BATCH_SIZE, measure_latency_sample_times=MEASURE_LATENCY_SAMPLE_TIMES, verbose=True) print('-------------------------------------------') print('Finish building latency lookup table.') print(' Device:', torch.cuda.get_device_name()) print(' Model: ', model_arch) print('-------------------------------------------') latency = fns.compute_resource(network_def, 'LATENCY', lookup_table_path) print('Computed latency: ', latency) latency = fns.measure_latency( model, [MEASURE_LATENCY_BATCH_SIZE, *INPUT_DATA_SHAPE]) print('Exact latency: ', latency)