Hyperparameter Tuning using MLOps

Hyperparameter Tuning using MLOps

The percentage of AI models created but never put into production in large enterprises has been estimated to be as much as 90% or more. With massive investments in data science teams, platforms, and infrastructure, the number of AI projects is dramatically increasing — along with the number of missed opportunities.

I made this project by Integrating Machine Learning with DevOps. Technologies used : Git , Github , Jenkins , Docker , Keras , Tensorflow , Python

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, run docker container to deploy code and start training.

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

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

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

Creating Docker Image

I used Dockerfile to create a Docker image with Python , Keras and TensorFlow installed. Also, as I used Mnist dataset for training so I downloaded that too in the image.

No alt text provided for this image

Here, I used "CMD python3 mlops.py" to run the python code and start training the model as soon as user runs the Container.

Creating Job Chain Using Jenkins

  • Job 1

Job 1 was to Pull the Github repo automatically when some developers push repo to Github. As i wanted complete automation , I used post-commit hook of git (Pushes the code the github and runs Jenkins Task of Pulling the code as soon as the user commits the code)

No alt text provided for this image
#!/bin/bash


git push  #pushes the code the github

curl --user "admin:root" https://192.168.99.101:8080/job/Git%20Clone/build?token=job1  #Runs Jenkins task using Build Triggers

In the Jenkins Job, I copied the pulled repo from Github to /root/mlhp/. We will mount this volume to Docker container.

No alt text provided for this image
  • Job 2

This job included running docker container to deploy code and start training. This job runs automatically if Job1 is stable.

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

As we can see, the code searches for container named "mlops_container" . If the container is stopped previously, we remove it and run another container using the same name.

sudo docker run -t --name mlops_container -v /root/mlhp/:/model/ mlops:v1

As soon as we run this Job, the docker container starts training the model.

No alt text provided for this image
  • Job 3

Job 3 was Training the model and predicting accuracy. I used Random module of python for Hyperparameter tuning to improve the accuracy of the model.

No alt text provided for this image

The above code adds random number of Convolution layers containing random filters and random kernel size. The Dense layer also contains random activation functions. At the time of compilation I used random optimizers (RMSprop, Adam, SGD, Nadam, Adamax). I used accuracy as metrics to show the accuracy at the time of epochs. the model gives different accuracy every time we run it as it uses random layers.

No alt text provided for this image
  • Job 4 & Job 5

These Jobs included tweaking the machine learning model architecture if metrics accuracy is less than 95% and Sending an Email to the user if metrics accuracy is greater than 95%.

I used smtplib module for sending the mail and os module to re-train the model.

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

As soon as the curl command accesses this site, Job2 runs again and Retrains the model, If the New accuracy is more than 95% then the program Sends a mail to the user telling the present Accuracy and the Layers used to achieve that accuracy.

However, If the New accuracy is again less than 95%, then the programs runs another Docker container and re-trains the model using different activation function and layers. This process continues until we achieve the desired accuracy.

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

Click Here for Github Repo

Atul Yadav

Android Developer | 4+ Years | Kotlin, Java, Jetpack, MVVM, Firebase, REST APIs | Open to Work

4 年

Great work, keep it up

要查看或添加评论,请登录

Gaurav Yadav的更多文章

  • Hosting Wordpress on AWS with maximum Security

    Hosting Wordpress on AWS with maximum Security

    Task Write a Infrastructure as code using terraform, which automatically create a VPC. In that VPC we have to create 2…

    2 条评论
  • Jenkins Automation Using Groovy

    Jenkins Automation Using Groovy

    In this tutorial I tried to Show how to use Groovy script to build a Jenkins pipeline. Groovy is suitable for beginners…

    1 条评论
  • Deploying Prometheus and Grafana over Kubernetes

    Deploying Prometheus and Grafana over Kubernetes

    Task: Creating Docker images for Prometheus & Grafana. Deploying Prometheus & Grafana as pods on top of Kubernetes by…

  • Setting Up WordPress On AWS Using Amazon EKS

    Setting Up WordPress On AWS Using Amazon EKS

    Tasks: Kubernetes Cluster using AWS EKS. Integrate EKS with EC2,EBS,LB,EFS.

  • Deploying Openstack on AWS

    Deploying Openstack on AWS

    Probably everyone with OpenStack hands-on experience would agree that sometimes it could be hard and frustrating to…

    3 条评论
  • Kubernetes deployment and Monitoring using Jenkins

    Kubernetes deployment and Monitoring using Jenkins

    Task: Using Jenkins Server on Rhel, Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in…

    1 条评论
  • Number Plate Detection With Supervise.ly

    Number Plate Detection With Supervise.ly

    What is Supervisely? There are many open-sourced implementations of state of the art neural network architectures. But…

    8 条评论
  • Infrastructure as Code with AWS and Terraform

    Infrastructure as Code with AWS and Terraform

    For This Task, I first created an Amazon Machine Image(AMI) from an instance in which I configured Jenkins and Apache…

    20 条评论
  • CI/CD Pipeline Using Kubernetes

    CI/CD Pipeline Using Kubernetes

    Task Description 1. Create container image that’s has Linux and other basic configuration required to run Slave for…

    4 条评论
  • Facial Recognition using Transfer Learning

    Facial Recognition using Transfer Learning

    Transfer learning is a machine learning method where a model developed for a task is reused as the starting point for a…

    1 条评论

社区洞察

其他会员也浏览了