使用TensorFlow进行手写数字识别并导出PB模型供OpenCV的C++版本的DNN模块调用

手写数字识别是机器学习中的一个经典问题,而TensorFlow是一个广泛使用的机器学习框架,它提供了丰富的工具和库来构建和训练深度学习模型。本文将介绍如何使用TensorFlow实现手写数字识别,并将训练好的模型导出为Protocol Buffer(PB)格式,以便后续在OpenCV的C++版本中使用DNN模块进行调用。

首先,我们需要准备训练数据。我们将使用MNIST数据集,该数据集包含大量的手写数字图像及其对应的标签。我们可以使用TensorFlow提供的内置函数来加载和预处理这些数据。

import tensorflow as tf

# 加载MNIST数据集
mnist = tf.keras.datasets.mnist
(train_images, train_labels)
机器学习笔记 - 基于OpenCV图像处理和手写数字识别进行数独求解 使用简单神经网络训练的手写数字模型,并基于一些基础图像处理的技术,编写oythonn程序进行数独求解。 阅读详情

相关推荐

opencv dnn 人脸 年龄

https://github.com/spmallick/learnopencv/blob/master/AgeGender/AgeGender.py # Import required modules import cv2 as cv import math import time import argparse def getFaceBox(net, frame, conf_th...

jacke121的专栏 2652

TensorFlow训练模型如何用OpenCV DNN在C++端部署落地

模型训练与部署是两种截然不同的工程场景。在Python中借助TensorFlow可以快速训练出高精度的图像识别模型,但真正落地到C++客户端、工业视觉或边缘设备时,往往受限于运行环境与依赖库的复杂性。OpenCV DNN模块提供了一条轻量级推理路径,可直接加载TensorFlow导出的pb图模型,在C++环境中完成前向计算,无需庞大的TensorFlow运行时。本文以MNIST手写数字识别为例,完整梳理了从Keras训练、冻结导出pb、生成pbtxt描述文件,到C++调用readNetFromTensorf

weixin_29062613的博客 291

从Keras到OpenCV C++:手写数字识别模型部署实战

深度学习模型训练完成后,部署到生产环境往往比训练本身更具挑战。尤其在跨语言场景下,模型需要转换为无依赖的静态推理格式,才能在C++等原生环境中高效运行。TensorFlow的冻结图(pb)格式正好满足这一需求,它将权重和计算图固化为单一文件,无需TensorFlow运行时即可被OpenCV DNN模块加载。OpenCV作为主流计算机视觉库,其DNN模块为轻量级推理提供了便捷接口,适合桌面程序、嵌入式视觉等场景。通过一个完整的手写数字识别项目,从Keras训练、导出pb模型,到OpenCV C++代码中实现图

weixin_29054399的博客 240

TensorFlow训练CNN并用OpenCV DNN实现手写数字识别C++部署

深度学习模型的落地部署是工程实践中的关键一环,训练好的模型需要通过高效、轻量的方式集成到实际应用中。卷积神经网络(CNN)是图像识别任务的基础架构,而TensorFlow作为主流训练框架,能够快速构建并训练高精度模型。训练完成后,将模型导出为通用的pb格式,再借助OpenCV的DNN模块在C++环境中完成推理,即可实现无需重型依赖的端到端部署。这种方案特别适合资源受限的桌面或嵌入式系统,在工业视觉、自动化检测等场景中具有广泛的应用价值。本文围绕手写数字识别这一经典任务,详细讲解从TensorFlow 2.0

weixin_29032489的博客 236

opencv调用tensorflow pb模型

这是一个使用C++的opencv调用tensorflow训练好的一个二分类的模型, 代码包括C++文件和训练的python文件,训练设备为python3.5+tensorlfow-gpu1.4.0+ubuntu16.04 C++文件也是在ubuntu下写的,但是在windows下只需要稍作修改就可直接运行

Titans:谷歌新型神经记忆架构,突破 Transformer 长序列处理的瓶颈

Titans 是谷歌推出的新型神经网络架构,通过神经长期记忆模块突破 Transformer 在处理长序列数据时的瓶颈,支持并行计算,显著提升训练效率。

士多啤梨先生の博客 994

(nginx) nginx5 nginx https部署实战

综上所述,相比 HTTP 协议,HTTPS 协议增加了很多握手、加密解密等流程,虽然过程很复杂,但其可以保证数据传输的安全。所以在这个互联网膨胀的时代,其中隐藏着各种看不见的危机,为了保证数据的安全,维护网络稳定,建议大家多多推广HTTPS。SSL 证书费用很高,以及其在服务器上的部署、更新维护非常繁琐HTTPS 降低用户访问速度(多次握手)网站改用HTTPS 以后,由HTTP 跳转到 HTTPS 的方式增加了用户访问耗时(多数网站采用302跳转)

weixin_50382197的博客 1505

分数计算器(C++课设)

需求概述 (1)设计一个分数计算器,进行分数的算术运算和逻辑运算。 (2)能够像使用基本数据的对象一样,对分数进行“+”、“-”、“*”和“/”等算术运算和比较两个分数的大小。 (3)以a/b的形式输入输出分数,允许输入输出整数这种特殊形式。 (4)对不是约化型的分数进行约化,避免分母为负数。 (5)如果分数的分母为0、除数为0或输入时格式有错,采用异常处理机制解决。 输入 以分数的形式输入。(如1/2) 若分母为0会抛出异常,重新输入。 菜单页面 RationalNumber.h(头文件) #ifnd

sadnessss的博客 8770

使用DrissionPage和自动化技术实现得物鞋子信息爬取

本文介绍了一个基于DrissionPage技术的得物鞋子信息采集系统,能自动化采集商品图片、价格等数据并保存为Excel。系统采用浏览器模拟技术处理动态加载内容,通过XPath定位元素,实现智能交互和完整数据采集。关键技术包括:图片URL提取与下载、Excel数据集成与图片嵌入、文件名安全处理等。项目适用于市场分析和学术研究,强调必须遵守法律法规和平台规则,仅用于非商业用途。与API爬虫相比,浏览器自动化能更好处理现代Web应用,但需注意知识产权保护。

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 1667

30天入门 SAP BTP 开发系列之十四: 将 SAP Business Application Studio 里开发好的 Node.js 应用部署到 Cloud Foundry 环境中

本教程详细介绍了如何将SAP Business Application Studio中的Node.js应用部署到Cloud Foundry环境。在完成本地开发和测试后,通过cf login命令连接Cloud Foundry环境,配置manifest.yml文件指定应用参数和路由信息。使用cf push命令完成应用的上传和部署,最终使应用运行在SAP BTP的云端环境中。教程包含从路由创建到部署验证的完整流程,确保开发者能够成功将Node.js应用发布到生产环境。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1084

物料分类账-返工工单(自身)差异分摊逻辑

如上图所示,当月入库的全部消耗,而返工消耗的数量为100PCS,所以返工消耗占总消耗的比例为100pcs/(205pcs+100pcs)=0.327868852。备注:红色箭头的物料号为产品自己本身所产生的价差,就是返工工单所承担的差异,而我们要计算的就是这个值,所以计算价差不会包括此项。价差合计就是不包括初始分摊的价差9153.7,剩下的价差合计就是返工工单自身所承担的差异4465.21。每一次返工工单所承担的差异都会按照价差*承担比例去计算承担的差异,知道承担完所有差异。

Yeol827的博客 2497

Qt代码-软件商店

ui->statusBar->showMessage(QString("%1 已卸载").arg(app["name"].toString()));ui->statusBar->showMessage(QString("开始下载 %1...").arg(app["name"].toString()));QString("%1 已下载完成,是否立即安装?ui->statusBar->showMessage(QString("%1 下载完成").arg(app["name"].toString()));

寒寒豆豆软件公司的博客 112

【专栏目录】

🌟 深度学习工程师的终极武器库!本专栏深度解析近3年CV领域最前沿的YoloV8改进方案,每一种方法都经过实战验证,性能显著提升!🌟。

m0_47867638的博客 1万+

深度学习工具包 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');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

上一篇: 机器学习笔记:使用FCN进行Pascal VOC数据集的语义分割
下一篇: Pandas获取DataFrame的行索引
普通网友
博客等级 码龄3年 53粉丝 167原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值