Auto-Hyper-parameter Optimization

Shrut Shah
5 min readMay 23, 2020

Integration of ML(Tensorflow+CNN) and Devops(Docker+Jenkins)

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

I have created one Dockerfile with miniconda pre-installed in it.

Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others.

This miniconda is needed because we need to install tensorflow , keras, pillow, smtplib and also to re-solve the dependencies between them

I Have uploaded the docker image on hub.docker.com so that any one easily access without any hassle .

just use : docker push shrutshah/autohyper:tagname

Output of this transaction is:

we receive 4 emails

1 CNN Architecture : After successful iterations the best CNN architecture is emailed to the Mlops team.

2 Accuracy: Best Accuracy is emailed to MLops team.

3 Optimizer: The optimizer which helped to gain the best accuracy is emailed to the Mlops team.

4 Learning Rate: The learning rate is also hyper-parameterised and the best LR is emailed.

Steps

1:First of all to start we need to write the code for CNN image detection for cat/dog.

2:I have created volume in which i have copied the image dataset

3: a- From Github the CNN code which i uploaded is circulated in jenkins pipeline in h-job1.

b- I have used Poll SCM for building trigger after every minute i-e the jenkins h-job1 will check the github repository and if any change it will pull the code from it

c- In the execute shell we will copy the CNN code into the the created volume

4: a- In the second job h-job2 we need to launch the container to run CNN model , after successful run we exit from docker container. Here for detection of the code that whether it is code of CNN or code from sklearn we can simply go inside the .py file and search for keywords. For eg: we will serch for word keras for CNN using grep .

- v option is used for mounting the volume created to the volume in container

-a is used to show all (running is default)

grep is used for search.

b- build trigger is used because when the h-job1 is succesfully build then only h-job2 will run

5: h-job3 is used to check that whether docker is running or not. Also if not then new container is launched ,and as new container launched new architecture is obtained. In this way continuous auto hyper parameter can be obtained.

CNN code description

1:I’m already having 1 convolution layer(Convolution2D+MaxPool2D)

for hyper-parameter optimization i have provided option between

1 and 2 extra convolution layer.

Either 1 or 2 extra layer will get added to it.

2:For Fully connected layer i have options between 1, 2 or 3 dense layer with relu as activation.

3:for optimizer i have 3 options a:Adam b :RMSprop c :SGD

4:for Learning rate i have options of 0.1, 0.01, 0.001, 0.0001.

5:For email notification i have used smtplib . Here gmail 2 step verification is needed. also u need to create app to generate password. An email with subject and value as body is generated using the same python file.

Here is the link for github URL for reference:

https://github.com/ShrutShah/Auto-Hyper-Parameter-Optimization.git

--

--