该脚本主要是为了更好的使用户使用训练任务,免去了训练前繁杂的配置环境问题,主要的特点是简单,便捷, 可自定义的地方已在脚本内部注明,可根据自我需要,进行自定义修改。
我一次写博客,写的比较拉,烦请见谅。。。
脚本代码如下:
import os
try:
"""这部分代码是修复镜像错误的,直接运行就行不用管,建议不要随便动"""
os.system(f"apt-get update -y")
os.system(f"apt install libgl1-mesa-glx -y")
os.system(f"apt-get install libglib2.0-dev -y")
print("修复成功")
except:
print("修复失败")
try:
"""这部分代码是自动配置环境的,其中 requirements.txt 文件里面主要写了一些所需要的环境包"""
os.system(f"pip install -r requirements.txt -i https://pypi.douban.com/simple/")
print("修复成功")
except:
print("修复失败")
try:
"""这部分代码主要是运行训练脚本的"""
os.system("python train.py")
print("运行成功")
except:
print("运行失败")
其中,train.py 为你要运行的训练脚本,可自由更改,requirements.txt 为训练所需的环境包文档,以我训练YOLOv5 环境为例,requirements.txt 如下所示:
# pip install -r requirements.txt
# Base ----------------------------------------
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.41.0
einops
timm
# Logging -------------------------------------
tensorboard>=2.4.1
wandb
# Plotting ------------------------------------
pandas>=1.1.4
seaborn>=0.11.0
# Export --------------------------------------
# coremltools>=4.1 # CoreML export
# onnx>=1.9.0 # ONNX export
# onnx-simplifier>=0.3.6 # ONNX simplifier
# scikit-learn==0.19.2 # CoreML quantization
# tensorflow>=2.4.1 # TFLite export
# tensorflowjs>=3.9.0 # TF.js export
# openvino-dev # OpenVINO export
# Extras --------------------------------------
albumentations>=1.0.3
Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
pycocotools>=2.0 # COCO mAP
roboflow
thop # FLOPs computation
requirements.txt,可根据自己训练的代码环境自定义修改,如实在看不懂 可以学一下 os.system() 函数。
最后感谢社区平台提供的免费训练资源,感谢老师们的帮助,谢谢老师!!
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》