Automate Hyper Parameter Tuning with DevOps

Automate Hyper Parameter Tuning with DevOps

Task description

1. Create container image that’s has Python3 and Keras or numpy installed using dockerfile 

2. When we launch this image, it should automatically starts train the model in the container.

3. Create a job chain of job1, job2, job3, job4 and job5 using build pipeline plugin in Jenkins 

4. Job1 : Pull the Github repo automatically when some developers push repo to Github.

5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective machine learning software installed interpreter install image container to deploy code and start training( eg. If code uses CNN, then Jenkins should start the container that has already installed all the softwares required for the cnn processing).

6. Job3 : Train your model and predict accuracy or metrics.

7. Job4 : if metrics accuracy is less than 80% , then tweak the machine learning model architecture.

8. Job5: Retrain the model or notify that the best model is being created

9. Create One extra job job6 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again from where the last trained model left

Note: Assuming that git, github, jenkins, docker are already installed in your system while performing this task"

Project description

Basically in this project I'm going to integrate machine learning with devops which is usually known as MLOPS . Here I'm going to use Deep Learning's Algorithm called Convolutional Neural Network in order to detect the object where I train 50000 samples and this model is having the accuracy of 91% of correct predictions. . I'm using DevOps tools like Git, Docker, Jenkins to automate the step of Hyper Parameter Tuning until we get the best accuracy of all time. In the final phases of this article, I've provided my Github Link where I've uploaded my trained model.

Git Use Case in this Project

Git is mainly used for Uploading and Downloading Changes on the Developer Side which he is using locally on the system and on the Automation Side by simple git push, pull, commit commands. Git will upload and download code from Github at the same time Github will use the feature called WebHook which notify the Jenkins Job to download code automatically for performing further operations. Here are some screenshots of webhook how it works and also of jenkins which automatically run the job to download the code.

No alt text provided for this image

In the above image, I've locally created a git hook called post-commit in which script is written that will automatically push code on Github as soon as developer run git commit command then the hook push that committed file automatically on the Github that's why we don't have to use git push. On Github, I've created a webhook that will notify Jenkins as soon as Developer Pushes the code on Github, following is the Screenshot of my Github WebHook.

No alt text provided for this image

Docker Use Case in this Project

Docker is famous in the market for its Agility, that it can launch OS in just 1 to 2 Seconds. Docker is generally using Containerization technology. In this Project, Docker is used for launching Environments or OS for running Deep Learning or Traditional Machine Learning Code in it to get the best accuracy for the ML Model. I've created two docker images one for the Traditional ML and one for Deep Learning Packages for running Python Code in it.

In order to make docker images, here are some ScreenShots of both the Dockerfiles following are the ScreenShots.

No alt text provided for this image

Above Screenshot is for creating Traditional ML(Machine Learning) image of docker

No alt text provided for this image

Above Screenshot is for installing Deep learning Packages used in this project, it'll create a Docker image. In order to create an image using this Dockerfile just use the following command.

docker build -t "ImageName" (if you want you can also give image version/tag name) "location of directory which contains Dockerfile" for example

  • docker build -t dl_image:v2 /ws/ML/DL

Role of jenkins in this project

In Jenkins, we have to make 5 Jobs/Items following are the description of these Jobs for an overview of my Jenkins Pipeline, I'm providing a visualization of Pipeline.

JOB 1 - job1(ML_code) 

This job automatically Pull Data from Github and will store data in the workspace of Jenkins as soon as the developer pushes the updated code on the Github and copy it to a directory which will be mounted as a volume to our container.

No alt text provided for this image
No alt text provided for this image


No alt text provided for this image

JOB 2 - job 2(smart job)

This job launches the desired environment by looking at the model.

No alt text provided for this image


No alt text provided for this image
No alt text provided for this image

JOB 3 - job 3

This job is the ace. It predicts the accuracy and validation accuracy, if accuracy and validation accuracy is less than 80% it tweaks the model using a python script and some bash commands as shown below.

By this we are adding an additional dense layer to the model and changing hyper parameters like number of epochs, batch size, neurons and learning rate. After tweaking the model it will train the model and predict accuracy again

This will keep happening until it achieves 80% accuracy or higher and creates the best model.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

JOB 4 - job 4

This job will determine the accuracy of the model which is trained in the previous step and check if the accuracy is less than 80% then it will automatically retrain the model again to get the better accuracy.

No alt text provided for this image

JOB 5 - job 5

If the accuracy of the code is greater than 80 % then this job will send the mail to the developer that the model accuracy is good .

No alt text provided for this image
No alt text provided for this image

JOB 6: job (Monitoring)

This job is for monitoring : If container where app is running, fails due to any reason then this job should automatically start the container again from where the last trained model left.

No alt text provided for this image


Build Pipeline View

No alt text provided for this image

Here I'm also providing the Github repository link for your reference.

To view or add a comment, sign in

More articles by Kunal Sharma

Insights from the community

Others also viewed

Explore topics