tvm交叉编译android opencl

文章讲述了如何使用TVM将ONNX模型转换为Android设备可用的格式,涉及构建、编译和性能评估的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

模型编译:

#encoding:utf-8

import onnx

import numpy as np

import tvm

import tvm.relay as relay

import os

from tvm.contrib import ndk

onnx_model = onnx.load('mobilenet_v3_small.onnx')

x = np.ones([1,3,224,224])                      

input_name = 'input1'                                              

shape_dict = {input_name: x.shape}

sym, params = relay.frontend.from_onnx(onnx_model, shape_dict)

target = "opencl -device=adreno"

target_host = "llvm -mtriple=arm64-linux-android"

with tvm.transform.PassContext(opt_level=3):

    graph, lib, params = relay.build(sym, target=target, target_host=target_host, params=params)

lib.export_library("deploy.so", cc="/path_to_ndk/26.0.10792818/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang++")

graph_json_path = "deploy.json"

with open(graph_json_path, 'w') as fo:

    fo.write(graph)

param_path = "deploy.params"

with open(param_path, 'wb') as fo:

    fo.write(relay.save_param_dict(params))

------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值