# paddle模型转onnx
# paddlepaddle==2.2.1
# paddlenlp==2.3.4
# onnx==1.12.0
# onnxruntime==1.12.1
import paddle
from paddlenlp.transformers import AutoModelForMaskedLM
import onnxruntime
import numpy as np
import time
model_for_mask_lm = AutoModelForMaskedLM.from_pretrained('ernie-3.0-base-zh')
model_for_mask_lm.eval()
input_spec = paddle.static.InputSpec(shape=[1, None], dtype='int32', name='input_ids')
# 导出模型ernie_mask_lm.onnx
# paddle.onnx.export(model_for_mask_lm, 'ernie_mask_lm', input_spec=[input_spec], opset_version=12, enable_onnx_checker=True)
# 推理
session = onnxruntime.InferenceSession('ernie_mask_lm.onnx',
providers=['TensorrtExecutionProvider',
'CUDAExecutionProvider', 'CPUExecutionProvider'])
x = np.array([[1, 234, 2345, 234, 2345, 2]])
x_pd = paddle.to_tensor(x)
start = time.time()
inputs = {session.get_inputs()[0].name: x}
outs = session.run(None, inputs)[0]
print('onnx:', time.time() - start)
print(outs[0, 0, :5])
start2 = time.time()
outs2 = model_for_mask_lm(x_pd)
print('pd:', time.time() - start2)
print(outs2[0, 0, :5].numpy())
"""
运行结果
onnx: 0.022006750106811523
[-20.545616 -29.175095 -12.939949 -18.544882 5.578158]
pd: 0.20505905151367188
[-20.545612 -29.175083 -12.939948 -18.544868 5.5781507]
"""
相关推荐
paddle 51 动态图转onnx(实现动态size)
paddle并不支持将动态图导出为支持动态size的onnx模型。参考:https://blog.csdn.net/ab0902cd/article/details/120200557 ,对导出后的onnx模型进行修改。最终实现,使paddle导出的模型支持动态size。以下以语义分割模型为例,将导出的静态size模型修改为动态size。
paddlepaddle导出onnx
地平线工具链支持的ONNX模型需要满足 opset_version=10/11 且 ir_version≤7,当拿到的ONNX模型不满足这两个要求时,可以修改代码重新导出,或者尝试编写脚本直接修改ONNX模型的对应属性,第二种方式的示例代码如下。检查导出的ONNX模型和原始的PaddlePaddle模型是否有相同的计算结果。此时ONNX模型的ir_version=6,opset_version=10,满足地平线工具链的转换条件。验证ONNX模型的正确性,会检查模型的版本,图的结构,节点及输入输出。
Spring Cloud 整合(一) CRUD
Springcloud 整合之 CRUDSpringcloud介绍功能概述为什么要选用Springcloud Springcloud介绍 功能概述 实现微服务 Spring Cloud为开发人员提供了工具,以快速构建分布式系统中的某些常见模式(例如,配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁,领导选举,分布式会话,群集状态)。分布式系统的协调导致样板式样,并且使用Spring Cloud开发人员可以快速站起来实现这些样板的服务和应用程序。 为什么要选用Springcloud
【openVINO+paddle】基于 Paddle2ONNX实现Paddle-Detection/OCR/Seg导出
【openVINO+paddle】基于 Paddle2ONNX实现Paddle-Detection/OCR/Seg导出 这篇文章所有的代码我都已经跑通。我会提供所有的源代码和数据集和相关文件,我这个用的环境是BML codeLAB ,他的文件路径是/home/work/而不是aistudio的/home/aistudio/这一个路径,所以请小伙伴们开发时注意下路径转化问题,有任何不懂或者出错的地方,欢迎到CSDN搜索翼达口香糖这个账号私聊我。 我已经把代码和数据都上传到aistudio ,想要对照结果或者体
[Linux]双网卡 CentOS 系统中指定网络请求走特定网卡的配置方法
本文详细介绍了在双网卡CentOS系统中指定特定域名/IP通过指定网卡传输流量的方法。核心步骤包括:1)确认网卡信息(ip addr)和域名IP解析(nslookup);2)添加临时路由(ip route add);3)持久化配置(创建route-eth1文件);4)验证配置(ip route show和curl测试)。文章还提供了网关查询、路由删除等常见问题的解决方法,并区分了不同CentOS版本重启网络服务的命令差异。通过合理配置路由规则,可实现流量的定向传输需求。
R链式中介:如何一次性生成4个变量所有可能的链式中介结果?(含结果解读与粗略作图)#bruceR#ggplot2
一次性生成4个变量所能生成的24种链式中介并作图
【PaddlePaddle】:一元线性回归与ONNX格式导出预测
本文记录PaddlePaddle中简单的一元线性回归案例与ONNX格式导出,后续部署在嵌入式平台。
C++坦克大战源代码
【代码】C++坦克大战源代码。
导出动态输入(输出)尺寸的onnx并使用openvino2022进行动态推理
从导出动态输入尺寸onnx到动态尺寸模型的推理
手把手教你学BSP(11.3)--BSP实例:基于Raspberry Pi 4 Model B的Linux BSP开发实例
通过以上步骤,我们完成了一个基于Raspberry Pi 4 Model B的Linux BSP开发过程,包括硬件初始化、设备驱动编写、Bootloader配置、内核配置和编译,以及最终映像的生成。每个步骤都非常重要,确保每一步都正确无误才能使整个系统正常运行。
从 central AAE 到 non-central AAE,重新理解 SAP PI 和 AEX 里的适配器引擎部署策略
摘要: SAP PI 项目中后期常面临运行时部署问题(如流量、隔离、权限等),而 Advanced Adapter Engine(AAE)是关键组件。AAE 分为 central(与集成服务器绑定,适合简单场景)和 non-central(独立部署,适合跨区域复杂网络)。non-central AAE 支持本地用户管理,增强独立性但增加治理复杂度。AEX(Java-only 轻量版 PI)与 non-central AAE 不同,前者是安装选项,后者是运行时部署方式。实际应用中,non-central AA
人像分割PP-HumanSeg模型onnx C++ windows部署
本文将PaddleSeg的人像分割(PP-HumanSeg)模型导出为onnx,并使用C++部署到windows,实现人像分割。 一、下载PaddleSeg git clone https://github.com/PaddlePaddle/PaddleSeg.git 二、下载模型 进入PP-HumanSeg目录,使用pip安装paddleseg库,并使用PaddleSeg提供的脚本下载预训练模型,该模型将用于后续导出为onnx。 %cd ~/PaddleSeg/c..
Sigrity SPEED2000 General SI Simulation模式如何进行信号仿真分析操作指导-DDR
本例是几个简单的板载DDR颗粒的结构,本例中使用General SI Simulation模式仿真DDR信号,结构拓扑如下,Addcmd,clk,cke都是T拓扑。Sigrity SPEED2000 General SI Simulation模式可以对信号进行仿真分析,仿真将电源视为理想电源,以下图为例进行说明。DQS的接收端模型设置为DQS_34_ODT60_1333。模式如何进行信号仿真分析操作指导-DDR。附带驱动和接收端的IBIS模型。
PP-HumanSeg模型ONNX导出避坑指南:从Paddle动态图到Windows C++可用的关键三步
本文详细解析了PP-HumanSeg模型从Paddle动态图转换为ONNX格式并在Windows C++环境中部署的三个关键技术难点:input_shape参数设置、opset_version兼容性问题以及int64掩码处理。针对每个问题提供了具体解决方案和性能优化技巧,帮助开发者成功实现高效部署。
Qt EGLFS 图形后端详解
EGLFS (EGL Full Screen) 是Qt框架在嵌入式Linux系统中的高性能图形显示后端,它提供了直接基于EGL和OpenGL ES的硬件加速渲染解决方案。
最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版
Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。
NLP原理和应用入门:paddle(梯度裁剪、ONNX协议、动态图转静态图、推理部署)
动态图(Dynamic Graph)和静态图(Static Graph)是深度学习框架中的两种模型建立方式。静态图是指在模型建立之前,先定义好整个计算图,然后再将数据输入计算图中进行计算。这种方式最早出现在 TensorFlow 中,用户需要先定义计算图的结构,然后再将数据输入计算图中进行计算,具有很好的性能和可扩展性。动态图是指在模型运行时才会生成计算图。例如,PyTorch 和 Chainer 就是使用动态图的深度学习框架。
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
PaddlePaddle模型格式转换工具:从训练到部署的全链路指南
在深度学习项目的完整生命周期中,模型格式转换是一个至关重要的环节。PaddlePaddle作为业界领先的深度学习框架,提供了一套完整的模型格式转换工具链,支持从训练模型到多种推理引擎的无缝转换。本文将深入解析PaddlePaddle的模型格式转换机制,帮助开发者掌握从模型保存、格式转换到最终部署的全流程。 ## 模型保存基础:理解PaddlePaddle的存储格式 ### 训练模型保存 Pa...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
PaddleRS-Deploy实战:遥感AI模型从训练到服务的完整部署指南
深度学习模型部署是AI工程化的核心环节,旨在将训练好的模型高效、稳定地转化为生产环境可用的服务。其核心原理在于通过模型格式转换(如从动态图转为静态图或ONNX)、推理引擎优化(如Paddle Inference、ONNX Runtime)以及计算图优化等技术,解决模型在真实场景中面临的性能瓶颈、依赖冲突和跨平台适配问题。这一过程的技术价值在于打通从算法研发到业务应用的闭环,显著提升模型推理速度与资源利用率,是实现AI落地价值的关键。在遥感影像分析、变化检测等具体应用场景中,部署工具链的成熟度直接影响着海量地
2、picodet转onnx裁剪及python onnxruntime推理
picodet转换onnx模型并对相关结构进行裁剪,最后进行推理
paddle2onnx的一个坑
解决方法将paddle2onnx升级到1.1.0以上(现在windows下可以直接装的貌似是1.0.6如果一定在windows下可能需要认为编译比较麻烦。条件允许可以考虑一下linux吧)。咱们要做的是直接把动态图加载好后转onnx这样实测下来精度没有丢失。正常步骤模型训练完成后转静态图,然后转onnx。但是实际对比发现这么干有精度丢失。
Paddle2ONNX最新升级:飞桨模型全面支持ONNX协议啦!
点击左上方蓝字关注我们16年前的电影《功夫》可以说是家喻户晓,并将武侠片推向了一个新的高潮。在电影中,街头小混混阿星偶然间被打通了任督二脉,因善开悟,再有“如来神掌”的加持,让他的武功变得...
Paddle模型的保存与加载以及转化ONNX
1、Paddle模型字典形式存储 paddle保存模型参数是parambase格式,paddle.save对要保存的字典对象的值会进行解码,对于parambase格式会进行转换。如果我们保存的格式是{‘model’: model.state_dict()},字典的值是字典(相当于2级字典),该2级字典的值是模型参数(parambase格式),但是paddle.save只对字典的值进行解码,对于该2级字典的值不会进行解译,因此需要手动修改。 def model_rebuild(model_state_dict
各主流深度学习框架转换onnx
Paddle2onnx 模型转换 动态图ONNX模型导出和静态图ONNX模型导出; 动态图 大致的原理就是动转静,然后再将静态图模型转换为ONNX模型,所以转换的代码上与动转静很相似; import os import time import paddle # 从模型代码中导入模型 from u2net import U2NETP # 实例化模型 model = U2NETP() # 加载预训练模型参数 model.set_dict(paddle.load([path to the pretrain
pytorch模型转paddle模型
1.pytorch保存模型形式onnx # model是加在权重后的pytorch模型,model.proto是生成的onnx模型 input = Variable(torch.randn(1, 3, 64, 64)) torch.onnx.export(model, input, 'model.proto', verbose=True) 2.onnx模型转成paddle https://git...
NLP涉及技术原理和应用简单讲解【一】:paddle(梯度裁剪、ONNX协议、动态图转静态图、推理部署)
¶在深度学习模型构建上,飞桨框架支持动态图编程和静态图编程两种方式,其代码编写和执行方式均存在差异。采用 Python 的编程风格,解析式地执行每一行网络代码,并同时返回计算结果。在模型开发章节中,介绍的都是动态图编程方式。静态图编程:采用先编译后执行的方式。需先在代码中预定义完整的神经网络结构,飞桨框架会将神经网络描述为 Program 的数据结构,并对 Program 进行编译优化,再调用执行器获得计算结果。动态图静态图优缺点:动态图编程体验更佳、更易调试,但是因为采用。......
部署“桨”坛 | 通过Paddle2ONNX在Atlas 200 DK上部署模型
本期【洞见AI硬件,部署讲坛】主要分享基于飞桨的昇腾310及相关硬件的多方案部署教程,包括:1. Paddle Lite在Atlas 200 DK上部署实战;2. 通过Paddle2ON...
1157




被折叠的 条评论
为什么被折叠?



