July 18, 2024


A way to click “run” in your Python script and walk away until your model’s training has been completed.

*Note: I have no affiliation with the aporia and the mlnotify creators. I am simply sharing this to help others with their data science learning experience.

Photo by Aron Visuals on Unsplash

Everyone in their data science journey goes through the process: waiting for their machine learning model training to finish. What do you do? Do you sit at your computer and just wait for the model to be done? Or do you leave and risk the training process terminating early or wasting precious time thinking your model is still training while it’s actually done? I found a way to train your machine learning model, walk away from your computer, and get a notification when the training is complete. This can be super helpful if you have other to-dos in your life and need to walk away from your computer but do not want to waste precious analytical time once your model’s training has finished.

I recently came across mlnotify in my data science journey and thought it was too good to be true. You can find more information about mlnotify here. It was created by aporia and is a tool to notify machine learning enthusiasts when the training of their model has completed. After a user calls .fit() on their ML model, a QR code is provided to which a user can take a picture and receive a timer and update on their phone of the training’s completion. Additionally, users can opt to go to the mlnotify website to track their model’s training progress as well as opt-in to receive an email when the training has ceased.

In today’s example were going to create a basic Convolutional Neural Network (CNN) to classify the MNIST dataset. First, we want to import our packages.

import mlnotify
import tensorflow as tf
import keras
import numpy as np
from keras import layers

You will need to !pip install mlnotify before importing the library. Next, we want to load the MNIST dataset. The Keras API allows us to do this with their datasets method. To properly train our model we will need to scale the images between 0 and 1, convert them to float32 values, and reshape them to be (28,28,1). The final step will be to convert the class label vectors to binary matrices.

#Creating the training and test sets(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()#Image scaling
x_train = x_train.astype("float32") / 255
x_test = x_test.astype("float32") / 255
# Image Shaping
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)
#Class label vector conversion
num_class = 10
y_train = keras.utils.to_categorical(y_train, num_class)
y_test = keras.utils.to_categorical(y_test, num_class)

Now let’s create the model. The model will have two convolutional layers, each using 3×3 kernels and a Leaky ReLU (LReLU) activation function. The first convolutional layer will have 32 neurons and the second layer will be shaped with 64. Following the convolutional layers, we will use a max pooling layer with a parameter value of (2,2). Finally, the model will end with a dropout layer, flatten layer, and dense layer which uses the num_class parameter we created (in this case 10) for its number of neurons. The dense layer will utilize the Softmax activation function since this is a multi-classification problem.

model = keras.Sequential([
layers.Conv2D(32, kernel_size=(3, 3)),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3)),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Dense(num_classes, activation="softmax"),

Finally, it’s time to train the mode. Let’s see how mlnotify interacts with the training process. You will need to code in %%notify and mlnotify.start() (reference the code below) to call the mlnotify API into action.

batch_size = 128
epochs = 10
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)

When you execute his code a QR code will pop up which allows you to get the training progress on your phone.

QR Code for Training (Image from Author)

After scanning the QR code, a timer will popup on your phone tracking the training of your model.

Phone Timer Training (Image from Author)

You can also access the same timer through the link provided by mlnotify. Once the training is complete, mlnotify will let you know on your phone wherever you are!

Training Completion (Image from Author)

As we saw today, there are ways to be notified regarding when your machine learning model is done being trained while you are away from your desk instead of sitting at your computer staring at the progress bar. This API allows you to click run in your terminal and carry on doing other things in your day without having to constantly check on the model’s training progress. I have found this API super helpful when training models that take a long time. It allows me to go do other activities I love and enjoy in my day but quickly get back to the results of my trained model with the quick notification from mlnotify. I hope you find the same value in using this tool as I did!

If you enjoy today’s reading, PLEASE give me a follow and let me know if there is another topic you would like me to explore! If you do not have a Medium account, sign up through my link here! Additionally, add me on LinkedIn, or feel free to reach out! Thanks for reading!

How to Receive Machine Learning Model Training Completion Time Notifications on Your Phone Republished from Source https://towardsdatascience.com/how-to-receive-machine-learning-model-training-completion-time-notifications-on-your-phone-a8e6cdb02d1a?source=rss—-7f60cf5620c9—4 via https://towardsdatascience.com/feed




Source link