top of page
Search

Project 6c - Object detection II, Google Colab setup for training

  • Writer: James Canova
    James Canova
  • Sep 3, 2021
  • 3 min read

Project start: 20 February 2022

Project finish: 26 February 2022


Objective: to set-up Google Colab and transfer files to Google Drive and create/modify files required for training a YOLOv4 neural network.


I tried to train the YOLOv4 neural network in my Jetson Nano however it kept freezing. I was watching the Jetson Stats (jtop) window but I could not figure out why this was happening. I did increase the swap space to about 15GB. I suspect that there was just not enough memory resources available.


So, I turned to Google Colab. Unfortunately it is only available in a limited number of countries. One of them is Canada where I live. I believe that there are alternatives available. I think that Kaggle has a similar service and perhaps Amazon does as well.


You need a Google account to use Colab. The basic version is free and I believe that is all that is required to train the YOLOv4 neural network. The free version does not allow access to a terminal window so I upgraded to Google Colab Pro for about $15CAD/month.


If you don't upgrade to Google Pro and thus don't have access to a terminal you can execute command lines from within a .ipynb file by prefixing the command with "!".


To get started create a WiX (that's the service that hosts this blog) folder and then a myColab folder:


/content/gdrive//MyDrive/WiX/myColab


1) download (clone) "Darknet" which is the program required to train a YOLOv4 neural network (ref. https://jkjung-avt.github.io/yolov4/) with the following zipped .ipynb file.


Note: Google will ask you for some permissions that you will need to accept.




2) update the Makefile in /darknet


There are two options:


a) download the Makefile that I have already updated:



b) update the Makefile according to the following instructions. This can be done within a Jupyter Notebook by prefixing bash commands with the "!" symbol, or by using a text editor in a terminal window or by using the Google's text editor by right clicking the file. As mentioned, a subscription to Google Colab Pro is required to have access to a terminal window.


To install vim

apt-get update

apt-get install vim

(note: for some reason, vim must be reinstalled every time that you leave and enter Colab.)


Set the values in Makefile to:

GPU=1

CUDNN=1

CUDNN_HALF=1

OPENCV=1

AVX=0

OPENMP=0

LIBSO=1

ZED_CAMERA=0

ZED_CAMERA_v2_8=0

ARCH= -gencode


3) make Darknet, in /darknet

make clean

make -j

4) setup YOLOv4 configuration files


navigate to /darknet/cfg and create a folder called myYolov4

mkdir myYolov4

The following files are required in this folder:


a) myData.data (from project 6b)

b) Yolov4.conv137 (which is from the Udemy course and is over 160MB)

c) myYolov4.cfg (see below)


For convenience, these are contained in the attached zip file:



myYolov4.cfg is a modified version of yolov4.cfg download along with darknet in the /cfg folder.


This required modification are:


[net]

batch=32

subdivisions=16

width=416

height=416

max_batches = 8000

policy=steps

steps=6400,7200

classes=2


change classes=80 to classes=2 in all places


use the filter formula for convolution layer before YOLO layer (classes+5)x3

(ref: https://github.com/pjreddie/darknet/issues/2263)


filters=(2+5)x3 = 21


[convolutional]

size=1

stride=1

pad=1

filters=21

activation=linear



3) in /myColab make a folder called "project_d" and copy the dataset folder created in project 6b to this new folder






If you have any problems or need clarification please contact me: jscanova@gmail.com

 
 
 

Recent Posts

See All
Introduction

I became interested in artificial intelligence in mid 2021 after watching a documentary on this subject. In particular, I'm interested in...

 
 
 
References

1.Rashid, Tariq, Make Your Own Neural Network , Amazon , 2016 2.Portilla, Jose, "Python for Computer Vision with OpenCV and Deep...

 
 
 
Status of Projects

Last updated: 30 March 2024 Project 0: Read this to get a very basic understating on machine learning and neural networks. Project 1:...

 
 
 

Comments


Post: Blog posts

©2021 by My Machine Learning Blog. Proudly created with Wix.com

bottom of page