Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 4dcab01

Browse files
committed
add 1st conv layer support for faster-rcnn/RFCN and int8 prototxt
1 parent 484f4bb commit 4dcab01

File tree

4 files changed

+64012
-6
lines changed

4 files changed

+64012
-6
lines changed

examples/faster-rcnn/tools/test_net.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def parse_args():
7777

7878
parser.add_argument('-wi', '--conv_algo', dest='conv_algo', action="store_true", default=False,
7979
help='to choose the convolution algorithm')
80+
parser.add_argument('-1st', '--enable_1st_conv_layer', dest='enable_1st_conv_layer', action="store_true", default=False,
81+
help='enable 1st conv layer')
8082
if len(sys.argv) == 1:
8183
parser.print_help()
8284
sys.exit(1)
@@ -117,14 +119,14 @@ def parse_args():
117119
if args.quantized_prototxt == None:
118120
test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis)
119121
else:
120-
(blobs, params, top_blobs_map, bottom_blobs_map, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, winograd_convolutions) = sample_net(args.prototxt, net, imdb, args.sample_iters, args.quant_mode)
122+
(blobs, params, top_blobs_map, bottom_blobs_map, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, winograd_convolutions) = sample_net(args.prototxt, net, imdb, args.sample_iters, args.quant_mode, args.enable_1st_conv_layer)
121123

122124
(inputs_max, outputs_max, inputs_min) = sampling.calibrate_activations(blobs, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, args.calibration_algos, "SINGLE", args.conv_algo)
123125
params_max = sampling.calibrate_parameters(params, winograd_convolutions, "DIRECT", args.quant_mode.upper(), args.conv_algo)
124-
calibrator.generate_sample_impl(args.prototxt, args.quantized_prototxt, inputs_max, outputs_max, inputs_min, params_max, False)
126+
calibrator.generate_sample_impl(args.prototxt, args.quantized_prototxt, inputs_max, outputs_max, inputs_min, params_max, args.enable_1st_conv_layer)
125127
compiled_net_str = caffe.compile_net(args.prototxt, caffe.TEST, "MKLDNN")
126128
raw_net_basename = os.path.basename(args.prototxt)
127129
compile_net_path = "./compiled_" + raw_net_basename
128130
with open(compile_net_path, "w") as f:
129131
f.write(compiled_net_str)
130-
calibrator.transform_convolutions(args.quantized_prototxt, compile_net_path, top_blobs_map, bottom_blobs_map, args.unsigned_range, args.concat_use_fp32, args.unify_concat_scales, args.conv_algo, False)
132+
calibrator.transform_convolutions(args.quantized_prototxt, compile_net_path, top_blobs_map, bottom_blobs_map, args.unsigned_range, args.concat_use_fp32, args.unify_concat_scales, args.conv_algo, args.enable_1st_conv_layer)

examples/rfcn/tools/test_net.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def parse_args():
8282

8383
parser.add_argument('-wi', '--conv_algo', dest='conv_algo', action="store_true", default=False,
8484
help='to choose the convolution algorithm')
85+
parser.add_argument('-1st', '--enable_1st_conv_layer', dest='enable_1st_conv_layer', action="store_true", default=False,
86+
help='enable 1st conv layer')
8587
if len(sys.argv) == 1:
8688
parser.print_help()
8789
sys.exit(1)
@@ -124,14 +126,14 @@ def parse_args():
124126
if args.quantized_prototxt == None:
125127
test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis)
126128
else:
127-
(blobs, params, top_blobs_map, bottom_blobs_map, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, winograd_convolutions) = sample_net(args.prototxt, net, imdb, args.sample_iters, args.quant_mode)
129+
(blobs, params, top_blobs_map, bottom_blobs_map, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, winograd_convolutions) = sample_net(args.prototxt, net, imdb, args.sample_iters, args.quant_mode, args.enable_1st_conv_layer)
128130

129131
(inputs_max, outputs_max, inputs_min) = sampling.calibrate_activations(blobs, conv_top_blob_layer_map, conv_bottom_blob_layer_map, winograd_bottoms, args.calibration_algos, "SINGLE", args.conv_algo)
130132
params_max = sampling.calibrate_parameters(params, winograd_convolutions, "DIRECT", args.quant_mode.upper(), args.conv_algo)
131-
calibrator.generate_sample_impl(args.prototxt, args.quantized_prototxt, inputs_max, outputs_max, inputs_min, params_max, False)
133+
calibrator.generate_sample_impl(args.prototxt, args.quantized_prototxt, inputs_max, outputs_max, inputs_min, params_max, args.enable_1st_conv_layer)
132134
compiled_net_str = caffe.compile_net(args.prototxt, caffe.TEST, "MKLDNN")
133135
raw_net_basename = os.path.basename(args.prototxt)
134136
compile_net_path = "./compiled_" + raw_net_basename
135137
with open(compile_net_path, "w") as f:
136138
f.write(compiled_net_str)
137-
calibrator.transform_convolutions(args.quantized_prototxt, compile_net_path, top_blobs_map, bottom_blobs_map, args.unsigned_range, args.concat_use_fp32, args.unify_concat_scales, args.conv_algo, False)
139+
calibrator.transform_convolutions(args.quantized_prototxt, compile_net_path, top_blobs_map, bottom_blobs_map, args.unsigned_range, args.concat_use_fp32, args.unify_concat_scales, args.conv_algo, args.enable_1st_conv_layer)

0 commit comments

Comments
 (0)