- 새 채널 생성

- 슬랙에
Incoming WebHooks
앱 추가


- 앱을 설치할 채널 선택

- URL 저장

- 메세지 전송
import json
import sys
import random
import requests
import os
import numpy as np
import torch
def send_msg(msg):
url =
message = ("Train 완료!!!\n" + msg)
title = (f"New Incoming Message :zap:")
slack_data = {
"username": "NotificationBot",
"icon_emoji": ":satellite:",
"attachments": [
{
"color": "#9733EE",
"fields": [
{
"title": title,
"value": message,
"short": "false",
}
]
}
]
}
byte_length = str(sys.getsizeof(slack_data))
headers = {'Content-Type': "application/json", 'Content-Length': byte_length}
response = requests.post(url, data=json.dumps(slack_data), headers=headers)
if response.status_code != 200:
raise Exception(response.status_code, response.text)
- 활용
메세지는 자유롭게 변경 가능하지만 나는 .py로 파일을 따로 만들어 train이 끝날 때마다 호출해서 arg로 넘겨준 epoch, loss, acc 등을 출력하게 만들었음

