Skip to content

Commit

Permalink
fix preprocess error
Browse files Browse the repository at this point in the history
Change-Id: If68395d57e25b238c76556746d04b6f7ab18649a
  • Loading branch information
HarmonyHu committed Mar 2, 2023
1 parent 84663ac commit cfda275
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 9 additions & 5 deletions python/tools/model_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def _prepare_input_npz(self):
num_inputs = len(self.test_input)
self.do_validate = (0 < num_inputs)
if not self.do_validate:
if self.customization_format == '':
ppa = preprocess()
input_op = self.module.inputs[0].op
ppa.load_config(input_op)
self.customization_format = getCustomFormat(ppa.pixel_format, ppa.channel_format)
return
self.inputs = {}
#self.pre_inputs = {}
Expand All @@ -125,10 +130,9 @@ def _prepare_input_npz(self):
#use the first input_op's shape as input_shapes
input_shapes.append(Operation.shape(input_op))
ppa.load_config(input_op)
if self.customization_format == None:
if self.customization_format == '':
self.customization_format = getCustomFormat(ppa.pixel_format,
ppa.channel_format)
print(self.customization_format)
config = {
'input_shapes': input_shapes,
'resize_dims': ppa.resize_dims,
Expand All @@ -152,7 +156,7 @@ def _prepare_input_npz(self):
self.inputs[op.name] = data
if self.aligned_input and not self.fuse_preprocess:
ppa = preprocess()
if self.customization_format is None:
if self.customization_format == '':
#use the first input_op's pixel format
input_op = self.module.inputs[0].op
ppa.load_config(input_op)
Expand Down Expand Up @@ -247,7 +251,7 @@ def validate_model(self):
# fuse preprocess
parser.add_argument("--fuse_preprocess", action='store_true',
help="add tpu preprocesses (mean/scale/channel_swap) in the front of model")
parser.add_argument("--customization_format", default=None, type=str,
parser.add_argument("--customization_format", default='', type=str,
choices=supported_customization_format,
help="pixel format of input frame to the model")
parser.add_argument("--aligned_input", action='store_true',
Expand All @@ -274,7 +278,7 @@ def validate_model(self):
parser.add_argument("--debug", action='store_true', help='to keep all intermediate files for debug')
# yapf: enable
args = parser.parse_args()
if args.customization_format is not None and args.customization_format.startswith("YUV") >= 0:
if args.customization_format.startswith("YUV"):
args.aligned_input = True

tool = DeployTool(args)
Expand Down
2 changes: 1 addition & 1 deletion python/utils/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class YuvType(Enum):
'YUV_NV21',
'YUV_NV12',
'RGBA_PLANAR',
None
''
]

customization_format_attributes = {
Expand Down
9 changes: 9 additions & 0 deletions regression/script_test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ model_deploy.py \
--test_reference mobilenet_v2_top_outputs.npz \
--compare_all \
--model mobilenet_v2_1684x_int8_fuse.bmodel

# no test
model_deploy.py \
--mlir mobilenet_v2.mlir \
--quantize INT8 \
--chip bm1684x \
--calibration_table mobilenet_v2_cali_table \
--fuse_preprocess \
--model mobilenet_v2_1684x_int8_fuse2.bmodel
popd

0 comments on commit cfda275

Please sign in to comment.