KANIKIG

KANIKIG

just for fun | 兴趣使然 Ph.D. in Engineering|❤️ #NFT $ETH| [Twitter](https://twitter.com/kanikig2)|[Github](https://github.com/KANIKIG)|[Telegram channel](https://t.me/kanikigtech)

Lazy Person's Hack - Send Notification to Phone When Model Training is Complete

image

Introduction#

Nowadays, large-scale numerical calculations or training of machine learning models can take hours or even days. Naturally, we would like to receive notifications when the process is completed so that we don't have to keep checking.

Surprisingly, there are very few related tutorials available online. This article provides the usage methods of two free push services, "bark" and "wxpusher", to automatically send notifications to your phone or WeChat when a script is finished running.

bark#

bark is a free and open-source push service that only supports iOS.

Download and Installation#

iShot2022-04-04 15.14.24

After entering the app, simply copy the link shown in the image above.

Python Implementation#

First, you need the requests package.

import requests

Add the following line after the code block for model training:

ret = requests.get('https://api.day.app/8BZtwxVav***********/AlarmDingDingDing/TestMessage')

Replace the above link with your own and modify the content as desired.

When the program reaches this line, a notification will be sent to your phone.

wxpusher#

If you have an Android phone, you can use wxpusher to push messages to WeChat. It is currently completely free. A similar and well-known service called "Server 酱" now only provides 5 free pushes per day, so it is not recommended.

Create an Application#

Simply scan the QR code with WeChat to register automatically. After entering, create an application by filling in the required fields. Once created, you will be given an appToken, so be sure to save it. The format is as follows:

AT_yn7Xsvz**********

After creating the application, a QR code will be displayed. Scan it with WeChat to associate yourself with the application. Then click on the user list on the left, and copy your UID.

iShot2022-04-04 14.57.23

The format is as follows:

UID_VO8eFt***********

Python Implementation#

Compared to "bark", the WeChat interface has some limitations and requires the use of the JSON format for transmission.

import requests
import json

# wxpusher
headers = {'content-type': "application/json"}
body = {
  "appToken":"AT_yn7Xsvz**********",
  "content":"This is a test message",
  "summary":"AlarmDingDingDing",
  "contentType":1,
  "topicIds":[],
  "uids":["UID_VO8eFt***********"]
}

Replace "appToken" and "uids" with your own.

Add the following lines after the code block for model training:

ret = requests.post('http://wxpusher.zjiecode.com/api/send/message', data=json.dumps(body), headers=headers)

This will send a "post" request to the API and immediately send a notification to your WeChat when the program finishes running.

Final Result#

It is very fast, and you will receive a notification almost immediately after execution.

IMG_1722

The only downside is that "wxpusher" is subject to certain restrictions imposed by WeChat, so the notification cannot directly display the content and you need to click to view it.

Advanced#

  1. Not only applicable to model training, but can also be used for any long-running program.
  2. Can be further developed, for example, sending notifications when an exception occurs during program execution.
  3. This article only provides Python examples, but it can also be applied to MATLAB (refer to here) or other scripting languages as long as they can send HTTP requests.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.