本文实现了俩种环境的设置,一种是windows的CPU版本,还有服务器上的GPU版本。CPU版本仅用来实现检测,而GPU版本用来训练自己的数据集!(选择其中一个环境运行后,训练自己的数据集)
1.环境1:windows11, anaconda虚拟环境(python3.9),pycharm
ultralytics/ultralytics: YOLOv8 🚀 in PyTorch > ONNX > CoreML > TFLite (github.com)
下载文件到本地后解压缩
pip install -r requirements.txt
根据自己的路径位置,下载所需要的包

(或者pip install ultralytics都一样)
配置环境后,检测
yolo task=detect mode=predict model=yolov8n.pt source="https://ultralytics.com/images/bus.jpg"


测试自己的照片


1.环境2:Ubuntu (docker)版本运行
git clone https://github.com/ultralytics/ultralytics

克隆项目
ls:查询当前文件夹
cd ultralytics:打开ultralytics文件夹
配置需要的运行库
pip install ultraklytics
pip install -r requirements.txt


结果

2.训练自己的数据集
2.1.数据格式

把Ubuntu服务器上的数据集复制到docker容器内(在服务器上操作,并非容器内)
docker cp data_sample torch_na:/workspace/ultralytics
复制后容器内可查看数据集

我的情况是韩语不显示,所以重新设置语言,相似的可参考【PS2】
原数据集json文件格式
[
{
"Code Name": "A220148XX_04547.jpg",
"Name": "baeghyang-gwa",
"W": "0.377474",
"H": "0.511151",
"File Format": "jpg",
"Cat 1": "22",
"Cat 2": "01",
"Cat 3": "48",
"Cat 4": "xx",
"Annotation Type": "binding",
"Point(x,y)": "0.313830,0.609444",
"Label": "0",
"Serving Size": "xx",
"Camera Angle": "xx",
"Cardinal Angle": "xx",
"Color of Container": "xx",
"Material of Container": "xx",
"Illuminance": "xx"
}
]
food_classes.json
{
"백향과": 1,
"베이글샌드위치": 2,
"보쌈": 3,
"복숭아": 4,
"볶음면": 5,
"볶음밥": 6,
"부침개": 7,
"비빔밥": 8,
"빵": 9,
"사과파이": 10,
}
~
数据处理中(更新中)。。。
问题与解决(PS)
【PS1】yolo运行时出错:ImportError: libGL.so.1: cannot open shared object file: No such file or directory

错误分析
Ubuntu18.04基础设置的docker pytorch深度学习镜像中,出现以上的错误。
这是docker镜像生成时使用apt-get时的libgl1-mesa-glx库问题
解决办法
apt-get update
apt-get -y install libgl1-mesa-glx
效果

Ubuntu系统再次运行后出现
ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
解决办法
apt-get update
apt-get install libglib2.0-dev
效果如图

然后就可以啦~
【PS2】
更改 Ubuntu 上的 Locale
先安装韩文包
apt-get install language-pack-ko

通过locale-gen 安装 Locale
locale-gen ko_KR.UTF-8

更新系统 LANG 设置。update-locale
update-locale LANG=ko_KR.UTF-8 LC_MESSAGES=POSIX
/etc/default/locale修改文件
LANG=ko_KR.UTF-8
LC_MESSAGES=POSIX

按下快捷键Esc,输入:wq后保存退出。如果还是不行,需要修改环境变量【1】

参考文献
【1】로케일(Locale)이란? 국가 및 언어 설정 | 44BITS
【2】 详细!正确!COCO数据集(.json)训练格式转换成YOLO格式(.txt)_qq_42012888的博客-CSDN博客_coco数据集的json文件
[3]Roboflow: Give your software the power to see objects in images and video