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)
待解决
4 保存为PB文件
不是ckpt文件
标签:__,attr,img,部署,tf,64,TF,CV From: https://www.cnblogs.com/lx63blog/p/17127151.html