Skip to content

Mastering YOLOv5 🚀 Deployment on Google Cloud Platform (GCP) Deep Learning Virtual Machine (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.

🆓 Plus, if you're a fresh GCP user, you're in luck with a $300 free credit offer to kickstart your projects.

In addition to GCP, explore other accessible quickstart options for YOLOv5, like our Colab Notebook Open In Colab for a browser-based experience, or the scalability of Amazon AWS. Furthermore, container aficionados can utilize our official Docker image at Docker Hub Docker Pulls for an encapsulated environment.

Step 1: Create and Configure Your Deep Learning VM

Let's begin by creating a virtual machine that's tuned for deep learning:

  1. Head over to the GCP marketplace and select the Deep Learning VM.
  2. Opt for a n1-standard-8 instance; it offers a balance of 8 vCPUs and 30 GB of memory, ideally suited for our needs.
  3. Next, select a GPU. This depends on your workload; even a basic one like the Tesla T4 will markedly accelerate your model training.
  4. Tick the box for 'Install NVIDIA GPU driver automatically on first startup?' for hassle-free setup.
  5. Allocate a 300 GB SSD Persistent Disk to ensure you don't bottleneck on I/O operations.
  6. Hit 'Deploy' and let GCP do its magic in provisioning your custom Deep Learning VM.

This VM comes loaded with a treasure trove of preinstalled tools and frameworks, including the Anaconda Python distribution, which conveniently bundles all the necessary dependencies for YOLOv5.

GCP Marketplace illustration of setting up a Deep Learning VM

Step 2: Ready the VM for YOLOv5

Following the environment setup, let's get YOLOv5 up and running:

# Clone the YOLOv5 repository
git clone

# 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.

Step 3: Train and Deploy Your YOLOv5 Models 🌐

With the setup complete, you're ready to delve into training and inference with YOLOv5 on your GCP VM:

# Train a model on your data

# Validate the trained model for Precision, Recall, and mAP
python --weights

# Run inference using the trained model on your images or videos
python --weights --source path/to/images

# Export the trained model to other formats for deployment
python --weights --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.

Terminal command image illustrating model training on a GCP Deep Learning VM

Allocate Swap Space (optional)

For those dealing with hefty datasets, consider amplifying your GCP instance with an additional 64GB of swap memory:

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

Concluding Thoughts

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.

Do remember to document your journey, share insights with the Ultralytics community, and leverage the collaborative arenas such as GitHub discussions to grow further. Now, go forth and innovate with YOLOv5 and GCP! 🌟

Want to keep improving your ML skills and knowledge? Dive into our documentation and tutorials for more resources. Let your AI adventure continue!

Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (5), Burhan-Q (1)