Skip to content

Commit

Permalink
feat(converter): update optimize because paddlelite v2.8 does not exp…
Browse files Browse the repository at this point in the history
…ose set_passes_internal api
  • Loading branch information
JingyuanZhang committed May 12, 2021
1 parent 453c136 commit 24faa93
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions packages/paddlejs-converter/optimizeModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import collections
import argparse
import traceback
import paddlelite.lite as lite
from paddlelite import lite
import pkg_resources
from packaging import version

lite_version = pkg_resources.get_distribution("paddlelite").version

def optimizeModel(inputDir, modelPath, paramPath, outputDir):
""" 使用opt python接口执行模型优化 """
Expand All @@ -20,42 +24,46 @@ def optimizeModel(inputDir, modelPath, paramPath, outputDir):
opt.set_valid_places("arm")
opt.set_model_type("protobuf")
opt.set_optimize_out(outputDir)

optimize_passes = [
"lite_conv_elementwise_fuse_pass",
"lite_conv_bn_fuse_pass",
"lite_conv_elementwise_fuse_pass",
"lite_conv_activation_fuse_pass",
"lite_var_conv_2d_activation_fuse_pass",
"lite_fc_fuse_pass",
"lite_shuffle_channel_fuse_pass",
"lite_transpose_softmax_transpose_fuse_pass",
"lite_interpolate_fuse_pass",
"identity_scale_eliminate_pass",
"elementwise_mul_constant_eliminate_pass",
"lite_sequence_pool_concat_fuse_pass",
"lite_elementwise_add_activation_fuse_pass",
"static_kernel_pick_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_target_cast_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"io_copy_kernel_pick_pass",
"argument_type_display_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_precision_cast_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_layout_cast_pass",
"argument_type_display_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"runtime_context_assign_pass",
"argument_type_display_pass"
]
opt.set_passes_internal(optimize_passes)

if version.parse(lite_version) <= version.parse('2.7.1'):
print("python paddlelite version: " + lite_version)

optimize_passes = [
"lite_conv_elementwise_fuse_pass",
"lite_conv_bn_fuse_pass",
"lite_conv_elementwise_fuse_pass",
"lite_conv_activation_fuse_pass",
"lite_var_conv_2d_activation_fuse_pass",
"lite_fc_fuse_pass",
"lite_shuffle_channel_fuse_pass",
"lite_transpose_softmax_transpose_fuse_pass",
"lite_interpolate_fuse_pass",
"identity_scale_eliminate_pass",
"elementwise_mul_constant_eliminate_pass",
"lite_sequence_pool_concat_fuse_pass",
"lite_elementwise_add_activation_fuse_pass",
"static_kernel_pick_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_target_cast_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"io_copy_kernel_pick_pass",
"argument_type_display_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_precision_cast_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"type_layout_cast_pass",
"argument_type_display_pass",
"variable_place_inference_pass",
"argument_type_display_pass",
"runtime_context_assign_pass",
"argument_type_display_pass"
]
opt.set_passes_internal(optimize_passes)

opt.run()


Expand Down

0 comments on commit 24faa93

Please sign in to comment.