kendryte / nncase

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

Unable to compile tflite model with k510 target #630

Closed 4d5645 closed 2 years ago

4d5645 commented 2 years ago

I'm trying to compile a tflite model with a 510 target, I end up with an error: RuntimeError: Cannot load module: libnncase.targets.k510.so, libnncase.targets.k510.so: cannot open shared object file: No such file or directory

import nncase
import os

dir_path = '/mnt/tflite/'

models = []
for file in os.listdir(dir_path):
    if file.endswith('.tflite'):
        models.append(dir_path + file)

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

def main():

    for model in models:
        print(model.split('/'))
        name = str(model.split('/')[3])[7:].split('.')[0]
        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(f'k510_{name}.kmodel', 'wb') as f:
            f.write(kmodel)

if __name__ == '__main__':
    main()
RuntimeError: Cannot load module: libnncase.targets.510.so, libnncase.targets.510.so: cannot open shared object file: No such file or directory

Environment :

sunnycase commented 2 years ago

Please install nncase-k510 plugin with pip install nncase-k510.