CV-部署芯片接续-CV全流程部署-TF版本
CV-部署芯片接续-CV全流程部署-TF版本
1 单个CNN算子
import cv2
import numpy as np
import tensorflow as tf
import os
from tensorflow.python.framework import graph_util # 参考连接 https://blog.csdn.net/tensorflowforum/article/details/112352764 代码
# 参考连接 参数详解:https://blog.csdn.net/weixin_43529465/article/details/124721583
# https://blog.csdn.net/rain6789/article/details/78754516 class SingleCnn(tf.keras.Model):
def __init__(self):
super(SingleCnn, self).__init__()
# filters=1 卷积核数目,相当于卷积核的channel
self.conv = tf.keras.layers.Conv2D(filters=1,
kernel_size=[1, 1],
# valid表示不填充, same表示合理填充
padding='valid',
# data_format='channels_last',-> 表示HWC,输入可以定义批次
data_format='channels_last',
use_bias=False,
kernel_initializer=tf.keras.initializers.he_uniform(seed=None),
name="conv") def call(self, inputs):
x = self.conv(inputs)
return x
if __name__ == "__main__":
# 图像数据
imagefile = r"catanddog\cat\5.JPG"
img = cv2.imread(imagefile)
img = cv2.resize(img, (64, 64))
img = np.expand_dims(img, axis=0)
print(img.shape, type(img), img.dtype)
img = img.astype(np.uint8)
singlecnn = SingleCnn() output = singlecnn(img)
2 图片导入
imagefile = r"catanddog\cat\5.JPG"
img = cv2.imread(imagefile)
img = cv2.resize(img, (64, 64))
img = np.expand_dims(img, axis=0)
print(img.shape, type(img), img.dtype)
img = img.astype(np.uint8)
3 推理时报错
output = singlecnn(img)
Value for attr 'T' of uint8 is not in the list of allowed values: half, bfloat16, float, double, int32
; NodeDef: {{node Conv2D}}; Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_BFLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID", "EXPLICIT"]; attr=explicit_paddings:list(int),default=[]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]; attr=dilations:list(int),default=[1, 1, 1, 1]> [Op:Conv2D] Call arguments received by layer 'conv' (type Conv2D):
• inputs=tf.Tensor(shape=(1, 64, 64, 3), dtype=uint8)
已解决:
# 未量化的model不支持int32和int8
# img = img.astype(np.int32)
img = tf.convert_to_tensor(img, np.float32)
print(img.shape, type(img), img.dtype)
4 保存为PB文件
不是ckpt文件
# =========== ckpt保存 with session的写法tf2 已不再使用 ===========
# with tf.Session(graph=tf.Graph()) as sess:
# constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['op_to_store']) # 保存参考 https://zhuanlan.zhihu.com/p/146243327
# save_format='tf' 代表保存pb
singlecnn.save('./pbmodel/singlecnn.pb', save_format='tf') # 加载模型 验证可以加载
new_model = tf.keras.models.load_model('./pbmodel/singlecnn.pb', compile=False)
output_ = new_model(img)
# print(output_.shape, output_[0][2:6][2:6])
print(output_.shape)

出现问题 保存的pb 文件是一个目录 里面有多个pb文件不知道 用哪个部署 尝试单独使用某一个pb部署 都会报错。
所以需要合一的pb文件。
tf.keras.saving.save_model | TensorFlow v2.11.0
pb是protocol(协议) buffer(缓冲)的缩写
CV-部署芯片接续-CV全流程部署-TF版本的更多相关文章
- camunda流程部署的一些简单操作
act_re_deployment:(流程部署对象表)存放流程部署的显示名和部署时间 act_re_procdef:(流程定义表)存放流程定义的属性信息 act_ge_bytearray:(资源文件表 ...
- Win2k8&&vCenter部署全流程
几个不同的组件 vCenter Server:对ESXi主机进行集中管理的服务器端软件,安装在windows server 2008R2或以上的操作系统里,通过SQL 2008R2 或以上版本的数据库 ...
- Activiti系列:带有serviceTask的或者定时启动任务的流程部署失败的原因分析
在将两个带有serviceTask任务的流程部署到数据库的时候发现无法导入,最终分析出如下问题: 1)流程1是打算让定时启动事件可以每小时触发一次 由于原来是用 R/2015-11-01T01:00: ...
- Activiti 流程部署方式 activi 动态部署(高级源码篇)
Activiti的流程 部署方式有很多种方式,我们可以根据activit工作流引擎提供的ap方式进行部署. 当然了实际需求决定你要使用哪一种api操作,后面的总结详细介绍了使用场景. 下面看一下部署方 ...
- 以太坊geth主网全节点部署
以太坊geth主网全节点部署 #环境 ubuntu 16.4 #硬盘500GB(目前占用200G) #客户端安装 # 查看下载页面最新版 # https://ethereum.github.io/go ...
- 【JBPM4】流程部署
示例代码: ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositorySe ...
- Activiti 流程部署方式 activi 动态部署(高级源代码篇)
Activiti的流程 部署方式有非常多种方式,我们能够依据activit工作流引擎提供的ap方式进行部署. 当然了实际需求决定你要使用哪一种api操作,后面的总结具体介绍了使用场景. 以下看一下部署 ...
- Spring管理流程部署——Activiti
pom.xml <!-- activit jar 包 --> <dependency> <groupId>org.activiti</groupId> ...
- [转帖]从壹开始前后端分离【重要】║最全的部署方案 & 最丰富的错误分析
从壹开始前后端分离[重要]║最全的部署方案 & 最丰富的错误分析 https://www.cnblogs.com/laozhang-is-phi/p/beautifulPublish-most ...
- (四)Activiti之流程定义部署之ZIP方式和流程定义查询
一.流程定义部署之ZIP方式 上一章节我们使用classpath的方式加载流程定义文件,这里我们使用ZIP的方式. 1.1 用activiti插件生成bpmn和png图片之后,压缩到一个zip格式的压 ...
随机推荐
- 找素数(java)
什么是素数? 质数又称素数.一个大于1的自然数,除了1和它自身外,不能被其他自然数整除的数叫做质数:否则称为合数(规定1既不是质数也不是合数). 实际案例 比如我们想找出1-1000的所有素数 思路1 ...
- Linux(CentOS)安装Redis保姆级教程
Linux(CentOs)安装Redis教程 一,下载Redis(两种方式) 1,找到redis官网(https://redis.io/download) 如果想下载指定版本就去这个网址(https: ...
- GPS地图生成02之经典算法体验
经典的利用轨迹生成地图的算法与数据集可寻找于:Mapconstruction by pfoser Mapconstruction by pfoser数据集中,雅典数据集投影坐标系为(UTM, GGRS ...
- PostgreSQL中的row_number() 与distinct用法说明
一.示例 这两个SQL执行所得到的数据是一样的! select count(s.*) from ( select *, row_number() over (partition by fee_dat ...
- MyBatis-Plus通用Iservice 方法详解
public interface IService<T> { /** * 默认批次提交数量 */ int DEFAULT_BATCH_SIZE = 1000; /** * 插入一条记录(选 ...
- 记录 mysql修改密码报错问题 (ERROR 1054 (42S22): Unknown column 'password' in 'field list')
报错如图: 查了相关文档 MySQL官网手册表示MySQL5.7版本后,password这个字段被改成 authentication_string, 命令修改如下: update user set a ...
- Minio服务器搭建
记录Minio服务器搭建过程 参考 1.下载minio 从地址https://min.io/download#/windows 下载minio server和minio client. 2.将两个ex ...
- 用浏览器打开pdf格式的文件默认全屏显示
打开地址如 http://xxxxx.pdf 在文件地址后面添加#view=FitH,top,可实现全屏查看pdf文件. http://xxxxx.pdf#view=FitH,top,
- UE4启动顺序
GameMode PlayerController Actor Level gameMode , playerController控制pawn , 激活默认相机active camera , getP ...
- VsCode轻松使用docker容器-Remote Containers
VsCode轻松使用docker容器-Remote Containers 演示视频:BiliBili 使用docker容器过程中,最常见的操作是进入容器内查看文件.修改配置等操作 以前 使用shell ...