kendryte / nncase

Open deep learning compiler stack for Kendryte AI accelerators ✨
Apache License 2.0
748 stars 181 forks source link

转换tflite模型出错 #622

Closed Namedqianli closed 2 years ago

Namedqianli commented 2 years ago

Describe the bug 我在使用示例代码将一个tflite模型转换成kmodel时出错。

Origin model and code 代码

import nncase

def read_model_file(model_file):
    with open(model_file, 'rb') as f:
        model_content = f.read()
    return model_content

def main():
    model='./model_float32.tflite'
    target = 'k510'

    # compile_options
    compile_options = nncase.CompileOptions()
    compile_options.target = target
    compile_options.dump_ir = True
    compile_options.dump_asm = True
    compile_options.dump_dir = 'tmp'

    # compiler
    compiler = nncase.Compiler(compile_options)

    # import_options
    import_options = nncase.ImportOptions()

    # import
    model_content = read_model_file(model)
    compiler.import_tflite(model_content, import_options)

    # compile
    compiler.compile()

    # kmodel
    kmodel = compiler.gencode_tobytes()
    with open('test.kmodel', 'wb') as f:
        f.write(kmodel)

if __name__ == '__main__':
    main()

模型 https://drive.google.com/file/d/11YLBkSMN41M1f9i_IUGsmBeXfXSDupC8/view?usp=sharing 结果

  1. Import graph... Traceback (most recent call last): File "/home/thousands/code/model/tflite2nncase.py", line 38, in main() File "/home/thousands/code/model/tflite2nncase.py", line 27, in main compiler.import_tflite(model_content, import_options) RuntimeError: Shape must be same: model/ms_tcn/StatefulPartitionedCall/StatefulPartitionedCall/dual_dilated_block_0/conv1d_1/Conv1D/SpaceToBatchND_s2b_out_tp[Transpose] != model/ms_tcn/StatefulPartitionedCall/StatefulPartitionedCall/dual_dilated_block_0/conv1d_1/Conv1D/SpaceToBatchND[output] has shape mismatch: [1,2,8,128] != [8,2,8,128]

Environment (please complete the following information):

Additional context Add any other context about the problem here.

curioyang commented 2 years ago

@Namedqianli 模型里space_to_batch 、conv、batch_to_space之间的reshape去掉以免产生CPU算子影响板上运行的速度

621 合并以后,可以测试