新闻详情

新闻详情

首页 / 资讯中心 / 详情

yolo_anchors.txt超参数值设置

发布时间:2026/10/1 7:18:38来源:尧图网络
yolo_anchors.txt超参数值设置
keras-yolov3在训练自定义图片集之前设置合理的yolo_anchors.txt值有利于模型训练的收敛一般都带有默认的参数如下在实际项目中yolo_anchors的值可以根据kmeans.py计算获取通过聚类得到最佳anchors数据kmeans.py执行后即可得到合适的yolo_anchors参数值代码如下import numpy as np class YOLO_Kmeans: def __init__(self, cluster_number, filename): self.cluster_number cluster_number self.filename 2007_train.txt def iou(self, boxes, clusters): # 1 box - k clusters n boxes.shape[0] k self.cluster_number box_area boxes[:, 0] * boxes[:, 1] box_area box_area.repeat(k) box_area np.reshape(box_area, (n, k)) cluster_area clusters[:, 0] * clusters[:, 1] cluster_area np.tile(cluster_area, [1, n]) cluster_area np.reshape(cluster_area, (n, k)) box_w_matrix np.reshape(boxes[:, 0].repeat(k), (n, k)) cluster_w_matrix np.reshape(np.tile(clusters[:, 0], (1, n)), (n, k)) min_w_matrix np.minimum(cluster_w_matrix, box_w_matrix) box_h_matrix np.reshape(boxes[:, 1].repeat(k), (n, k)) cluster_h_matrix np.reshape(np.tile(clusters[:, 1], (1, n)), (n, k)) min_h_matrix np.minimum(cluster_h_matrix, box_h_matrix) inter_area np.multiply(min_w_matrix, min_h_matrix) result inter_area / (box_area cluster_area - inter_area) return result def avg_iou(self, boxes, clusters): accuracy np.mean([np.max(self.iou(boxes, clusters), axis1)]) return accuracy def kmeans(self, boxes, k, distnp.median): box_number boxes.shape[0] distances np.empty((box_number, k)) last_nearest np.zeros((box_number,)) np.random.seed() clusters boxes[np.random.choice( box_number, k, replaceFalse)] # init k clusters while True: distances 1 - self.iou(boxes, clusters) current_nearest np.argmin(distances, axis1) if (last_nearest current_nearest).all(): break # clusters wont change for cluster in range(k): clusters[cluster] dist( # update clusters boxes[current_nearest cluster], axis0) last_nearest current_nearest return clusters def result2txt(self, data): f open(yolo_anchors.txt, w) row np.shape(data)[0] for i in range(row): if i 0: x_y %d,%d % (data[i][0], data[i][1]) else: x_y , %d,%d % (data[i][0], data[i][1]) f.write(x_y) f.close() def txt2boxes(self): f open(self.filename, r) dataSet [] for line in f: infos line.split( ) length len(infos) for i in range(1, length): width int(infos[i].split(,)[2]) - \ int(infos[i].split(,)[0]) height int(infos[i].split(,)[3]) - \ int(infos[i].split(,)[1]) dataSet.append([width, height]) result np.array(dataSet) f.close() return result def txt2clusters(self): all_boxes self.txt2boxes() result self.kmeans(all_boxes, kself.cluster_number) result result[np.lexsort(result.T[0, None])] self.result2txt(result) print(K anchors:\n {}.format(result)) print(Accuracy: {:.2f}%.format( self.avg_iou(all_boxes, result) * 100)) if __name__ __main__: cluster_number 16 # 类别数量 filename 2007_train.txt kmeans YOLO_Kmeans(cluster_number, filename) kmeans.txt2clusters()替换原有默认的yolo_anchors.txt文件再进行模型训练。注意执行kmeans.py的时机需要在模型训练之前模型训练之前需要先写入新的anchors的值后续博客再做yolov3全流程开发补充。
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

GEO搜索优化服务商聚合增长:专注B2B行业知识图谱构建,增强AI答案引用率 2026/10/1 8:22:13

GEO搜索优化服务商聚合增长:专注B2B行业知识图谱构建,增强AI答案引用率

AI搜索时代,B2B企业获客入口正在迁移当采购决策的第一站从搜索引擎搬到AI对话框,能否被AI主动推荐,直接决定企业能否进入客户候选名单。 如今,装修方找辅材、采购负责人选型装备、政企筛选供应商,都习惯先向豆包、Deep…

阅读更多 →
MySQL 触发器有哪些应用场景?从入门场景到避坑实战 2026/10/1 8:22:13

MySQL 触发器有哪些应用场景?从入门场景到避坑实战

很多开发者对 MySQL 触发器的认知很极端:要么完全不用,要么滥用触发器把业务埋进数据库。 触发器听起来很“高级”:不用写代码,数据库自动帮你干活。但很多人不知道触发器到底适合做什么、哪些事绝对不能做、为什么互联网大厂基本…

阅读更多 →
CodeBuddy 用量看板:本地解析 Token 与积分消耗,不联网不上传 2026/10/1 8:22:13

CodeBuddy 用量看板:本地解析 Token 与积分消耗,不联网不上传

1. 项目背景 在使用 CodeBuddy(VSCode 扩展 tencent-cloud.coding-copilot)的过程中,很多开发者会关心一个问题:每天到底烧了多少 Token、花了多少积分、哪个项目在烧、用的哪个模型、缓存命中多少。官方没有提供本地化的用量统计…

阅读更多 →
AI中的数字人面试需要用到那些技术呢? 2026/10/1 8:22:13

AI中的数字人面试需要用到那些技术呢?

数字人面试是一个典型的多技术栈融合场景,核心链路是"听懂 → 想清楚 → 说出来 → 演出来"。先看一张整体架构图:以上就是数字人面试的完整技术栈拆解。补充几个落地时容易被低估的难点:打断与抢话:候选人中途插话时&a…

阅读更多 →
VSCode配置C/C++环境:MinGW-w64安装与调试实战 2026/10/1 8:22:13

VSCode配置C/C++环境:MinGW-w64安装与调试实战

简介:面向VScode初学者及需要搭建C/C开发环境的开发者,资源以保姆级讲解方式系统梳理了编辑器从安装设置到高效使用的完整路径。压缩包共包含1132个文件,体积约230.42MB,涵盖大量png/jpg操作截图、md格式图文笔记、sh辅助脚本&…

阅读更多 →
苏州地区GEO优化服务专业公司靠谱商家怎么选?聚合增长实力参考 2026/10/1 8:22:00

苏州地区GEO优化服务专业公司靠谱商家怎么选?聚合增长实力参考

苏州地区GEO优化服务专业公司靠谱商家怎么选?聚合增长实力参考 选GEO优化服务的4个踩坑痛点,你中过几个?在AI搜索成为企业获客核心入口的当下,不少苏州企业都尝试过找GEO优化服务公司,却常常踩进这些常见的坑: 选了号称上词的服…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉