跳至内容

掌握YOLOv5 🚀 在Google 云平台 (GCP) 上部署深度学习虚拟机 (VM) ⭐

Embarking on the journey of artificial intelligence and machine learning can be exhilarating, especially when you leverage the power and flexibility of a cloud platform. Google Cloud Platform (GCP) offers robust tools tailored for machine learning enthusiasts and professionals alike. One such tool is the Deep Learning VM that is preconfigured for data science and ML tasks. In this tutorial, we will navigate through the process of setting up YOLOv5 on a GCP Deep Learning VM. Whether you're taking your first steps in ML or you're a seasoned practitioner, this guide is designed to provide you with a clear pathway to implementing object detection models powered by YOLOv5.

🆓 另外,如果您是 GCP 的新用户,您将有幸获得 300 美元的免费信用额度来启动您的项目。

除 GCP 外,还可探索YOLOv5 的其他可访问的快速入门选项,如我们的 Colab 笔记本 在 Colab 中打开 基于浏览器的体验,或 亚马逊 AWS.此外,容器爱好者还可以在以下网址使用我们的官方 Docker 镜像 Docker Hub Docker 拉动 用于封装环境。

Step 1: Create and Configure Your Deep Learning VM

让我们首先创建一个针对深度学习进行优化的虚拟机:Let's start by create a virtual machine that's tuneed for deep learning:

  1. 前往GCP 市场,选择深度学习虚拟机
  2. 选择n1-standard-8实例;它提供 8 个 vCPU 和 30 GB 内存,非常适合我们的需求。
  3. Next, select a GPU. This depends on your workload; even a basic one like the T4 will markedly accelerate your model training.
  4. 勾选 "首次启动时自动安装NVIDIA GPU 驱动程序?",即可轻松完成安装。
  5. 分配一个 300 GB SSD 持久磁盘,确保不会出现 I/O 操作瓶颈。
  6. 点击 "部署",让 GCP 发挥它的魔力,配置您的自定义深度学习虚拟机。

该虚拟机装载了大量预装工具和框架,包括Anaconda Python 发行版,其中方便地捆绑了YOLOv5.NET 所需的所有依赖项。

GCP Marketplace 设置深度学习虚拟机示例

第 2 步:准备好虚拟机YOLOv5

环境设置完成后,让我们运行YOLOv5 :

# Clone the YOLOv5 repository
git clone https://github.com/ultralytics/yolov5

# Change the directory to the cloned repository
cd yolov5

# Install the necessary Python packages from requirements.txt
pip install -r requirements.txt

This setup process ensures you're working with a Python environment version 3.8.0 or newer and PyTorch 1.8 or above. Our scripts smoothly download models and datasets rending from the latest YOLOv5 release, making it hassle-free to start model training.

步骤 3:训练和部署YOLOv5 模型 🌐

设置完成后,您就可以在 GCP 虚拟机上使用YOLOv5 进行训练和推理了:

# Train a model on your data
python train.py

# Validate the trained model for Precision, Recall, and mAP
python val.py --weights yolov5s.pt

# Run inference using the trained model on your images or videos
python detect.py --weights yolov5s.pt --source path/to/images

# Export the trained model to other formats for deployment
python export.py --weights yolov5s.pt --include onnx coreml tflite

With just a few commands, YOLOv5 allows you to train custom object detection models tailored to your specific needs or utilize pre-trained weights for quick results on a variety of tasks.

说明在 GCP 深度学习虚拟机上进行模型训练的终端命令图像

分配交换空间(可选)

对于需要处理大量数据集的用户,可以考虑为 GCP 实例增加 64GB 的交换内存:

sudo fallocate -l 64G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h  # confirm the memory increment

结束语

Congratulations! You are now empowered to harness the capabilities of YOLOv5 with the computational prowess of Google Cloud Platform. This combination provides scalability, efficiency, and versatility for your object detection tasks. Whether for personal projects, academic research, or industrial applications, you have taken a pivotal step into the world of AI and machine learning on the cloud.

请记住记录您的旅程,与Ultralytics 社区分享您的见解,并利用GitHub 讨论等合作平台进一步发展。现在,通过YOLOv5 和 GCP 去创新吧!🌟

想要不断提高您的 ML 技能和知识?深入了解我们的文档和教程,获取更多资源。让您的人工智能探险继续下去!


📅 Created 11 months ago ✏️ Updated 11 days ago

评论