【小白学习tensorflow教程】四、使用 tfhub中的模型EfficientDet-Lite2 进行对象检测_刘润森!
@Author:Runsentfhub是tensorflow官方提供训练好的模型的一个仓库。今天,我使用 tfhub中的模型EfficientDet-Lite2 进行对象检测选择的模型是EfficientDet-Lite2 对象检测模型。它在具有 91 个不同标签的 COCO17 数据集上进行了训练,并针对 TFLite 应用程序进行了优化。EfficientDet-Lite 是一系列对移动/物联网友好的对象检测模型。目前暂时无法直接正常访问 //tfhub.dev,可以通过镜像 ht...
@Author:Runsen
tfhub是tensorflow手官打造体能训练方法好的模式化的其中一个库房。昨天,我运行 tfhub中的模式化EfficientDet-Lite2 去相亲对象判断加载TensorFlow 模型
圖片輸入:规格可变气门正时的三通管件道图片。輸入张量是一个个 tf.uint8兼有样式张量[None, height, width, 3]。
加载图像并将其处理为 TensorFlow 模型的tensor格式。
import tensorflow_hub as hub
import cv2
import numpy
import pandas as pd
import tensorflow as tf
import matplotlib.pyplot as plt
width = 1028
height = 1028
img = cv2.imread('image.jpg')
inp = cv2.resize(img, (width , height ))
rgb = cv2.cvtColor(inp, cv2.COLOR_BGR2RGB)
rgb_tensor = tf.convert_to_tensor(rgb, dtype=tf.uint8)
rgb_tensor = tf.expand_dims(rgb_tensor , 0)
打开EfficientDet-Lite2,逛网给予打开代码怎么用
detector = hub.load("//hub.tensorflow.google.cn/tensorflow/efficientdet/lite2/detection/1")
boxes, scores, classes, num_detections = detector(boxes, scores, classes, num_detections = detector(rgb_tensor))
读取字典构成:
detection_boxes:一个tf.float32形状的张量[N, 4]含有以下列顺序边界框坐标:[ymin, xmin, ymax, xmax]。detection_scores:包含检测分数tf.float32的形状张量[N]。detection_classes:包含标签文件中检测类索引tf.int的形状张量[N]。num_detections:一个tf.int只有一个值的张量,检测次数[N]。
接下是验测的scores和class
物体编号:47,72,77检测的置信度比较高。
label = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
'train', 'truck', 'boat', 'traffic light', 'fire hydrant', '-',
'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
'-', 'backpack', 'umbrella', '-', '-', 'handbag', 'tie',
'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite',
'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', '-', 'wine glass', 'cup', 'fork',
'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange',
'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair',
'couch', 'potted plant', 'bed', '-', 'dining table', '-', '-',
'toilet', '-', 'tv', 'laptop', 'mouse', 'remote', 'keyboard',
'cell phone', 'microwave', 'oven', 'toaster', 'sink',
'refrigerator', '-', 'book', 'clock', 'vase', 'scissors',
'teddy bear', 'hair drier', 'toothbrush', '-']
以下将tensor改变为numpy()
pred_labels = classes.numpy().astype('int')[0]
pred_labels = [labels[i] for i in pred_labels]
pred_boxes = boxes.numpy()[0].astype('int')
pred_scores = scores.numpy()[0]
在最后设制一两个阀值,将加测框加到图片文字上。
for score, (ymin,xmin,ymax,xmax), label in zip(pred_scores, pred_boxes, pred_labels):
if score < 0.5:
continue
score_txt = f'{100 * round(score)}%'
img_boxes = cv2.rectangle(rgb,(xmin, ymax),(xmax, ymin),(0,255,0),2)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img_boxes, label,(xmin, ymax-10), font, 0.5, (255,0,0), 2, cv2.LINE_AA)
cv2.putText(img_boxes,score_txt,(xmax, ymax-10), font, 0.5, (255,0,0), 2, cv2.LINE_AA)
plt.figure(figsize=(10,10))
plt.imshow(img_boxes)
plt.savefig('image_pred.jpg',transparent=True, )
皇冠新体育APP相关的文章
- 皇冠新体育APP:Go语言自学系列 | golang开发工具_COCOgsta_golang开发工具
- Flink checkpoint failed 问题解决_xiedelong_checkpoint无法正常使用
- flink数据格式转换,DataStream转换成指定对象_....../........_flink json转换
- Mac go环境搭建&&Idea配置环境_采坑先锋_idea运行go mac
- Go语言学习之viper读取yaml配置文件并转成struct_Charles Yan_viper读取多个yaml
- 皇冠新体育APP:Flink的多种时间概念介绍和应用场景_詹姆斯-穆里尼奥_flink事件时间应用
- 记一次自定义实现Flink-sql-connector-xxx过程_阳信鸭梨_flink-sql-connector
- 皇冠新体育APP:gomod的版本选择策略_yuchenfw_go mod 指定版本
- vue使用leafLet(绘图工具详解)_清虚桂意_vue画图组件
- 皇冠新体育APP:Vue注册组件的几种方式,你都知道吗?_稗子酒_vue注册组件
- 皇冠新体育APP:VUE常用组件库_艾米家的猫儿(傻钢)_vue组件库
- flink遇到的反压及解决思路和实操方案_这个程序猿可太秀了
- Dolphinscheduler集成Flink任务踩坑记录_若小鱼_dolphinscheduler flink
- 皇冠新体育APP:golang http连接池实现_ase2014_go http 连接池
- DTMO直播预告丨ChunJun 2022年开源规划&支持异构数据源DDL转换与自动执行_数栈DTinsight
- 皇冠新体育APP:Go安装与环境配置(主windows系统)_大熊的饲养员_go环境配置