当前位置: 首页 > news >正文

佛山智家人网站网络推广策划培训班

佛山智家人网站,网络推广策划培训班,专业高端网站建设,驻马店市可以做网站的公司对象检测是一种计算机视觉技术#xff0c;它使软件系统能够从给定的图像或视频中检测、定位并跟踪物体。对象检测的一个特殊属性是它能识别对象的类别#xff08;如人、桌子、椅子等#xff09;并在给定图像中指出其具体位置坐标。这个位置通常通过在物体周围绘制一个边界框…对象检测是一种计算机视觉技术它使软件系统能够从给定的图像或视频中检测、定位并跟踪物体。对象检测的一个特殊属性是它能识别对象的类别如人、桌子、椅子等并在给定图像中指出其具体位置坐标。这个位置通常通过在物体周围绘制一个边界框来指出。边界框可能会也可能不会准确地定位物体的位置。在图像内定位物体的能力定义了用于检测的算法的性能。人脸检测就是对象检测的一个例子。 通常对象检测任务分为三个步骤 生成输入的小片段如下图所示。你可以看到大量的边界框覆盖了整个图像。对每个分割的矩形区域进行特征提取以预测矩形是否包含有效物体。将重叠的框合并成一个单一的边界矩形非极大值抑制。 TensorFlow是一个用于数值计算和大规模机器学习的开源库它简化了获取数据、训练模型、提供预测和完善未来结果的过程。TensorFlow集合了机器学习和深度学习模型与算法使用Python作为方便的前端并在优化的C中高效运行。 使用TensorFlow进行对象检测如上所述使用这个API不一定需要了解神经网络和机器学习的知识因为我们主要使用API中提供的文件。我们需要的只是一些Python知识和完成这个项目的热情。 按照以下步骤进行 第1步创建一个名为ObjectDetection的文件夹并用VS Code打开。 第2步通过在VS Code的终端输入以下命令从Github仓库下载Tensorflow API git clone https://github.com/tensorflow/models第3步设置虚拟环境 python -m venv --system-site-packages .\venv激活环境 .\venv\Scripts\activate将pip版本升级到最新 python -m pip install --upgrade --ignore-installed第4步安装依赖项 安装并升级tensorflow pip install tensorflow pip install --upgrade tensorflow安装matplotlib pip install pillow Cython lxml jupyter matplotlib导航到models文件夹中的research子文件夹。 cd \models\research\第5步现在我们需要下载Protocol BuffersProtobuf这是谷歌的一种语言中立、平台中立的扩展机制用于序列化结构化数据可以想象成XML但更小、更快、更简单。 在models文件夹的research子文件夹中提取从上述链接下载的zip的内容并访问bin文件夹复制那里的protoc.exe的路径。然后打开“编辑系统环境变量”并点击“环境变量”。 (i) 在系统变量下选择’path’并点击编辑。 (ii) 点击新建并粘贴’protoc.exe’的复制路径。 第6步然后在VS Code的终端运行这个命令 protoc object_detection/protos/*.proto --python_out.第7步在同一文件夹中创建一个名为detect.py的新Python文件并粘贴下面给出的代码 import numpy as np import os import six.moves.urllib as urllib import sys import tarfile import tensorflow as tf import zipfile import pathlib from collections import defaultdict from io import StringIO from matplotlib import pyplot as plt from PIL import Image from IPython.display import display from object_detection.utils import ops as utils_ops from object_detection.utils import label_map_util from object_detection.utils import visualization_utils as vis_util# 当前目录不是models时改变当前工作目录 while models in pathlib.Path.cwd().parts:os.chdir(..)# 加载模型函数 def load_model(model_name):base_url http://download.tensorflow.org/models/object_detection/model_file model_name .tar.gzmodel_dir tf.keras.utils.get_file(fnamemodel_name, originbase_url model_file,untarTrue)model_dir pathlib.Path(model_dir)/saved_modelmodel tf.saved_model.load(str(model_dir))return model# 路径到标签文件 PATH_TO_LABELS models/research/object_detection/data/mscoco_label_map.pbtxt # 创建类别索引 category_index label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_nameTrue)# 模型名称 model_name ssd_inception_v2_coco_2017_11_17 # 加载检测模型 detection_model load_model(model_name)# 为单个图像运行推理的函数 def run_inference_for_single_image(model, image):image np.asarray(image)# 输入需要是张量使用tf.convert_to_tensor进行转换。input_tensor tf.convert_to_tensor(image)# 模型期望图像的批量所以使用tf.newaxis添加一个轴。input_tensor input_tensor[tf.newaxis,...]# 运行推理model_fn model.signatures[serving_default]output_dict model_fn(input_tensor)# 所有输出都是批量张量。# 转换为numpy数组并取索引[0]来去除批量维度。# 我们只对前num_detections个检测感兴趣。num_detections int(output_dict.pop(num_detections))output_dict {key:value[0, :num_detections].numpy() for key,value in output_dict.items()}output_dict[num_detections] num_detections# detection_classes应该是整数。output_dict[detection_classes] output_dict[detection_classes].astype(np.int64)# 处理带有掩模的模型if detection_masks in output_dict:# 将边框掩模调整到图像大小。detection_masks_reframed utils_ops.reframe_box_masks_to_image_masks(output_dict[detection_masks], output_dict[detection_boxes],image.shape[0], image.shape[1]) detection_masks_reframed tf.cast(detection_masks_reframed 0.5,tf.uint8)output_dict[detection_masks_reframed] detection_masks_reframed.numpy()return output_dict# 展示推理的函数 def show_inference(model, frame):# 从摄像头获取画面并将其转换为数组image_np np.array(frame)# 实际检测。output_dict run_inference_for_single_image(model, image_np)# 对检测结果进行可视化。vis_util.visualize_boxes_and_labels_on_image_array(image_np,output_dict[detection_boxes],output_dict[detection_classes],output_dict[detection_scores],category_index,instance_masksoutput_dict.get(detection_masks_reframed, None),use_normalized_coordinatesTrue,line_thickness5)return(image_np)# 现在我们打开摄像头并开始检测物体 import cv2 video_capture cv2.VideoCapture(0) while True:# 逐帧捕获re,frame video_capture.read()Imagenpshow_inference(detection_model, frame)cv2.imshow(object detection, cv2.resize(Imagenp, (800,600)))if cv2.waitKey(1) amp; 0xFF ord(q):break video_capture.release() cv2.destroyAllWindows()第7步对于实时对象检测我们还需要一个额外的依赖库OpenCV。因此要安装OpenCV请在终端运行以下命令。 pip install opencv-python第8步现在我们已经准备就绪可以执行设置并进行对象检测了。执行’detect.py’文件。 python detect.py
http://www.pierceye.com/news/362205/

相关文章:

  • 做家具网站电影网站做流量吗
  • 免费1级做看网站制作单页网站要网址
  • 网站返回首页怎么做的好看自贡网站优化
  • 自己的网站如何做推广wordpress积分与奖励
  • 产品包装设计网站网站建设 中企动力宜昌
  • 英语营销型网站建设北京pk10网站开发
  • 交换链接适合哪些网站东莞小程序开发制作
  • 医院网站建设网站阿里巴巴网站是用什么技术做的
  • 潍坊 餐饮网站建设淘宝seo优化
  • 樟木头镇网站建设公司WordPress企业响应式主题
  • 怎么给网站做备份呢怎么去建设微信网站
  • 成都各公司网站中小企业网站建设 论文
  • 广告网站建设实训报告做电商从哪里入手
  • 建电子商务网站需要多少钱做网站的简称
  • 制定网站推广方案网络营销网站分析
  • 商城网站系网站 png逐行交错
  • 陕西网站建设陕icp备免费虚拟机安卓
  • 优化教程网站推广排名东莞网站建设推广有哪些
  • 金阳建设集团网站电子商务系统 网站建设
  • 网站建设规模哪里有做app软件开发
  • 建站工具上市手机视频网站设计
  • 代做道具网站做地方门户网站不备案可以吗
  • 电子商务 网站前台功能想做微商怎么找厂家
  • 网站建设电子书做网站引入字体
  • 顺德建设网站公司分发平台
  • 个人门户网站模板下载婚纱摄影网站定制
  • 提高网站流量的软文案例手机腾讯网
  • 网站只做内容 不做外链深圳宝安区天气
  • 生物网站 template淘宝的网站建设怎么建
  • 苏州哪家做网站好些推广之家app