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

车商城网站建设成都门户网站建设

车商城网站建设,成都门户网站建设,宝尊代运营一年要多少钱,胖子马wordpress模板:q8免费版人脸检测 环境安装源设置conda 环境安装依赖库 概述数据集wider_face转yolo环境依赖标注信息格式转换图片处理生成 train.txt 文件 数据集展示数据集加载和处理 参考文章 环境 安装源设置 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/f…

人脸检测

  • 环境
    • 安装源设置
    • conda 环境安装依赖库
  • 概述
  • 数据集
    • wider_face转yolo
      • 环境依赖
      • 标注信息格式转换
      • 图片处理
      • 生成 train.txt 文件
    • 数据集展示
    • 数据集加载和处理
  • 参考文章

环境

安装源设置

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

conda 环境安装依赖库

conda create -n facePay python=3.7
conda activate facePay
conda install pytorch-cpu -c pytorch
#使用conda install pytorch-cpu会快很多
pip3 install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install bcolz
pip install scikit-learn
pip install tqdm
pip install easydict

概述

人脸检测属于目标检测领域,目标检测领域分两大类:通用目标检测(n+1分类),特定类别目标检测(2分类)
人脸检测算法:Faster-RCNN系列,YOLO系列,级联CNN系列
评价指标:召回率,误检率,检测速度

数据集

yolo 通过txt文件标注,标注内容:0 0.15 0.33 0.14 0.22
对应:类别 归一化后中心点坐标 [x,y,w,h]

wider_face转yolo

环境依赖

# PIL 安装
pip install -U Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
conda install Pillow
# pip 安装会报错,conda 安装正常

标注信息格式转换

import os
from PIL import Imageparent_path = "/home/ai/wider_face_split/"def convert_to_yolo_format(input_file, output_dir, image_dir):with open(input_file, 'r') as f:lines = f.readlines()i = 0while i < len(lines):image_path = lines[i].strip()  # Get the relative path of imagenum_boxes = int(lines[i + 1].strip())  # Get the number of boxes# Path of the label filelabel_path = os.path.join(output_dir, os.path.basename(image_path).replace('.jpg', '.txt'))os.makedirs(os.path.dirname(label_path), exist_ok=True)# Get the Absolute Path of the imageimage_abs_path = os.path.join(image_dir, image_path)# Open the image to get the real size of itwith Image.open(image_abs_path) as img:img_width, img_height = img.size# Create the file and write data inwith open(label_path, 'w') as label_file:for j in range(num_boxes):# Fetch the box data (x_min, y_min, width, height)box_data = list(map(int, lines[i + 2 + j].strip().split()))x_min, y_min, width, height = box_data[:4]# Calculate the center coordinate (x_center, y_center)x_center = (x_min + width / 2)y_center = (y_min + height / 2)# Convert to the relative coordinatesx_center /= img_widthy_center /= img_heightwidth /= img_widthheight /= img_height# The class is defaulted by 0label_file.write(f"0 {x_center} {y_center} {width} {height}\n")# Update the index and jump to the next imagei += 2 + (1 if num_boxes == 0 else num_boxes)if __name__ == "__main__":# Modify the additional section by your own pathinput_path = parent_path+"wider_face_split/"output_path = parent_path+"wider_for_yolo/"input_file_pre = "wider_face_"input_file_sub = "_bbx_gt.txt"if not os.path.exists(output_path):os.makedirs(output_path)# Train and Validationdatasetfile = ["train", "val"]for category in datasetfile:convert_to_yolo_format(input_path + input_file_pre + category + input_file_sub,output_path + category + "/labels",parent_path+f"WIDER_{category}/images")

图片处理

wider_face对不同情景的图片做了分类,YOLO要求训练图片在一个文件夹,因此训练前需要将数据集所有图片copy到一个文件夹下

import os
import shutildef copy_images(src_dir, dest_dir):# 确保目标目录存在if not os.path.exists(dest_dir):os.makedirs(dest_dir)# 递归查找所有图片for root, _, files in os.walk(src_dir):for file in files:if file.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.webp')):src_path = os.path.join(root, file)dest_path = os.path.join(dest_dir, file)# 如果目标文件已存在,可以选择覆盖或跳过if not os.path.exists(dest_path):shutil.copy2(src_path, dest_path)  # 保留原文件元数据print(f"Copied: {src_path} -> {dest_path}")else:print(f"Skipped (already exists): {dest_path}")# 配置源文件夹和目标文件夹路径
train_source_folder = r"/home/a/wider_face_split/WIDER_train/images"
train_destination_folder = r"/home/a/wider_face_split/WIDER_train/data"
val_source_folder = r"/home/a/wider_face_split/WIDER_val/images"
val_destination_folder = r"/home/a/wider_face_split/WIDER_val/data"# 执行复制
copy_images(train_source_folder, train_destination_folder)
copy_images(val_source_folder, val_destination_folder)

生成 train.txt 文件

ls -al images/ | awk '{print $NF}' > ../train.txt

数据集展示

import cv2
import os
import numpy as npif __name__ == "__main__":# 第一步:指定文件路径root_path ='/home/neucore/develop/code/pre_research/dl/face_ai/study/yoloDataset/train/images/'path = '/home/neucore/develop/code/pre_research/dl/face_ai/study/yoloDataset/train.txt'path_voc_names = '/home/neucore/develop/code/pre_research/dl/face_ai/study/yoloDataset/face.names'# 第二步:获取目标类别with open(path_voc_names ,'r') as f:lable_map = f.readlines()for i in range(len(lable_map)):lable_map[i] = lable_map[i].strip()print(i, lable_map[i])# 第三步:获取图像数据和标注信息with open(path ,'r') as file:img_files = file.readlines()# img_files = os.path.join(root_path, img_files[i][0:])for i in range(len(img_files)):img_files[i] = img_files[i].strip()# 图像的绝对路径, [0:]表示去掉多少个字节,[2:]表示去掉前两个字符img_files[i] = os.path.join(root_path, img_files[i][0:])# print(i, img_files[i])label_files = [x.replace('images','labels').replace ('.jpg','.txt') for x in img_files]# print(label_files)#第四步:将标注信息给制在图像上#读取图像并对标注信息进行绘# for i in range(len(img_files)):for i in range (3):print (img_files[i])# 图像读取,获取宽高img =cv2.imread(img_files[i])if img is None:print("Error: Image not found or path is incorrect.")w = img.shape[1]h = img.shape[0]# 标签文件的绝对路径print(i, label_files[i])if os.path.isfile(label_files[i]):# 获取每一行的标注信息with open(label_files[i], 'r') as file:lines = file.read().splitlines()# 获取每一行的标准信息(class,x,y,w,h)x = np.array([x.split() for x in lines], dtype=np.float32)for k in range(len(x)):anno = x[k]label = int(anno[0])# 获取框的坐标值,左上角坐标和右下角坐标x1 = int((float(anno[1]) - float(anno[3])/2) * w)y1 = int((float(anno[2]) - float(anno[4])/2) * h)x2 = int((float(anno[1]) + float(anno[3])/2) * w)y2 = int((float(anno[2]) + float(anno[4])/2) * h)# 将标注框绘制在图像上cv2.rectangle(img, (x1,y1), (x2,y2), (255,30,30), 2)# 将标注类别绘制在图像上cv2.putText(img, ("%s"%(str(lable_map[label]))), (x1,y1),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 1)cv2.imshow('img', img)cv2.waitKey()# if cv2.waitKey(1) == 27:#     breakcv2.destroyAllWindows()

数据集加载和处理

参考文章

WIDER FACE数据集转YOLO格式

http://www.dtcms.com/wzjs/21555.html

相关文章:

  • 四川省建设厅的注册中心网站seo优化培训课程
  • 查找做像册的网站郑州seo外包公司哪家好
  • html网页设计代码购物网站win7优化设置
  • 网站建设业务员培训华为seo诊断及优化分析
  • 现在还有企业做网站的吗seo推广系统
  • 广州专业建站网络广告销售
  • 网站优化成本百度推广退款投诉
  • 网站做多个镜像网络营销广告案例
  • 网站制作经费预算表南京 seo 价格
  • 网站建设发布教程视频百度运营公司
  • 网站开发过程和里程碑学网络营销好就业吗
  • 贵阳网站制作贵阳网站建设哪家好seo是什么职务
  • 青岛建站服务培训心得体会总结
  • 做食物网站免费seo关键词优化服务
  • 网站制作先做数据库还是前台seo关键词首页排名代发
  • 网站设计企业关键词歌词任然
  • 泉州企业网站开发手机百度2022年新版本下载
  • 购物类网站建设方案seo关键词优化排名公司
  • 如何建一个手机网站淘宝关键词top排行榜
  • 怎么上传自己做的网站手机端竞价恶意点击能防止吗
  • 网站 用php asp源码 比较好朋友圈广告推广文字
  • 网站开发的技术路线免费网络推广平台
  • php毕业设计二手网站怎么做企业网站建设方案策划书
  • 织梦网站图片设置多大花西子网络营销策划方案
  • 凉山州建设网站百度小说搜索风云榜总榜
  • 江西南昌网站开发网页开发流程
  • 做公司网站体验营销案例
  • 山东网站新品牌推广策划方案
  • 西安大型网站建设市场调研与分析
  • 微信分销平台有哪些佛山seo代理计费