加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
train.py 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
KX 提交于 2023-02-12 16:34 . f
# -*- coding: utf-8 -*-
import dlib
# options用于设置训练的参数和模式
options = dlib.simple_object_detector_training_options()
# Since faces are left/right symmetric we can tell the trainer to train a
# symmetric detector. This helps it get the most value out of the training
# data.
# 将训练集扩大一倍
options.add_left_right_image_flips = True
# 支持向量机的C参数,通常默认取为5.自己适当更改参数以达到最好的效果
options.C = 20
options.epsilon = 0.01
# 线程数,你电脑有4核的话就填4
options.num_threads = 8
#显示输出信息
options.be_verbose = True
# 获取路径
current_path = 'E:/dlib-master/tools/imglab/build/Release'
train_folder = current_path + '/cats_train/'
test_folder = current_path + '/cats_test/'
train_xml_path = train_folder + 'mydata1.xml'
test_xml_path = test_folder + 'phone.xml'
print("training file path:" + train_xml_path)
# print(train_xml_path)
print("testing file path:" + test_xml_path)
# print(test_xml_path)
# 开始训练
print("start training:")
dlib.train_simple_object_detector(train_xml_path, 'detector.svm', options)
print("Testing accuracy: {}".format(
dlib.test_simple_object_detector(test_xml_path, "detector.svm")))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化