Skip to content

Commit

Permalink
!2 发布 fitlog 的 0.9.13 版本
Browse files Browse the repository at this point in the history
Merge pull request !2 from WillQvQ/send_to_bot
  • Loading branch information
WillQvQ authored and gitee-org committed Sep 13, 2020
2 parents c8310df + 163b660 commit 465b356
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ fitlog = fast + git + log, 是一款用于辅助用户记录日志和管理代

filog 是我们实验室内部使用的一款工具,大部分功能口口相传,文档和教程还没有特别全。感谢大家的尝试使用,遇到问题可以在 Issues 处提出。

更新计划包括:

- [ ] 增加更多的使用案例
- [x] 检查并更详细地介绍 [命令行工具](https://fitlog.readthedocs.io/zh/latest/user/command_line.html) 的使用方法
- [ ] 完成[网页服务](https://fitlog.readthedocs.io/zh/latest/user/website.html)的详细介绍


## 一些使用说明
1. 如果在debug阶段,不希望fitlog发生任何作用,那么直接在入口代码处(import fitlog的下一行)加入fitlog.debug()就可以让所有的fitlog调用不起任何作用,debug结束再注释掉这一行就可以了。 如果希望在某一段代码不要记录,可以在这段代码之前fitlog.debug(flag=True), 跑出这段代码之后fitlog.debug(flag=True)即可恢复
Expand All @@ -46,7 +40,26 @@ filog 是我们实验室内部使用的一款工具,大部分功能口口相
6. 传入到fitlog的各种参数、metric的名称,请 **避免特殊符号(例如$%!#@空格),请只使用_与各种字母的组合** ,因为特殊符号可能导致网页端显示不正常。
7. **在命令行中通过fitlog log logs打开网页的时候,如果出现了网页无法访问的情况,首先检查一下ip地址是否正确,例如如果是在服务器上启动的服务,在电脑这端应该用http://服务器的ip:5000 来访问,如果是在本地电脑启动的,可以尝试通过http://0.0.0.0:5000 或http://127.0.0.1:5000 或http://localhost:5000 访问。如果以上仍然不能访问,可以通过ctrl+c关闭fitlog服务,然后通过命令fitlog log logs --ip 127.0.0.1启动再试一下能不能访问。**

## Developing Features(2020.09.13)

以下为正在开发中的功能,API 可能发生变化。

为函数 `fitlog.finish` 增加了可选参数 send_to_bot,传入一个字符串,为飞书机器人的 webhook 地址。 使用这个参数可以让用户在训练完成时收到通知。

例如:设定 status 为 1, send_to_bot 为 webhook 的地址,可让飞书机器人发布训练发生错误的讯息。(status默认值为0,表示实验成功结束)

```python
fitlog.finish(status=1,
send_to_bot="https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx")
```

#### 添加飞书机器人的方法

如下图所示,打开群聊后点击 "设置-群机器人-添加机器人-Custom Bot" 可以打开机器人窗口,点击添加后可以获得飞书机器人的 webhook 地址。

![add_bot_1](doc/source/figures/add_bot_1.png)

另外,可以参考[一个人也可以用的群聊机器人](https://getfeishu.cn/hc/zh-cn/articles/360024984973-%E5%9C%A8%E7%BE%A4%E8%81%8A%E4%B8%AD%E4%BD%BF%E7%94%A8%E6%9C%BA%E5%99%A8%E4%BA%BA)

## New Features(2020.06.11)
以下的功能都没有经过实战使用检验,可能有bug。
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'fastNLP'

# The short X.Y version
version = '0.7.1'
version = '0.9.13'
# The full version, including alpha/beta/rc tags

# -- General configuration ---------------------------------------------------
Expand Down
Binary file added doc/source/figures/add_bot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions fitlog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import argparse
from configparser import ConfigParser

__version__ = '0.7.1'
__version__ = '0.9.13'


def get_commit_id(file):
Expand Down Expand Up @@ -139,13 +139,13 @@ def debug(flag=True):
_logger.debug(flag=flag)


def finish(status: int = 0):
def finish(status: int = 0, send_to_bot: str = None):
"""
使用此方法告知 fitlog 你的实验已经正确结束。你可以使用此方法来筛选出失败的实验。
:param int status: 告知当前实验的状态。0: 结束了; 1: 发生了错误
"""
_logger.finish(status)
_logger.finish(status, send_to_bot)


def add_metric(value: Union[int, str, float, dict], step: int, name: str = None, epoch: int = None):
Expand Down
38 changes: 36 additions & 2 deletions fitlog/fastlog/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
import requests
import json
from datetime import datetime
from copy import deepcopy
import argparse
Expand Down Expand Up @@ -279,11 +281,13 @@ def __add_meta(self):

@_check_debug
@_check_log_dir
def finish(self, status:int=0):
def finish(self, status: int=0, send_to_bot: str=None):
"""
使用此方法告知 fitlog 你的实验已经正确结束。你可以使用此方法来筛选出失败的实验。
:param int status: 告知当前实验的状态。0: 结束了; 1: 发生了错误
:param status: 告知当前实验的状态。0: 结束了; 1: 发生了错误
:param send_to_bot: 飞书机器人的 webhook 地址,设置后可以
:return:
"""
if status not in (0, 1):
raise ValueError("status only supports 0,1 to stand for 'finish','error'.")
Expand All @@ -295,6 +299,36 @@ def finish(self, status:int=0):
self._write_to_logger(json.dumps(_dict), 'meta_logger')
self.add_other(value=get_hour_min_second(time.time()-self._start_time), name='cost_time')

if send_to_bot is not None:
if isinstance(send_to_bot, str):
if status == 0:
title = "[ fitlog 训练完成 ]"
text = "fitlog 提醒您:您的训练任务已完成!"
else:
title = "[ fitlog 训练错误 ]"
text = "fitlog 提醒您:您的训练任务发生了错误。"
data = {
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": title,
"content": [
[
{
"tag": "text",
"text": text
},
]
]
}
}
}
}
requests.post(url=send_to_bot, headers={'Content-Type': 'application/json'}, data=json.dumps(data))
else:
print("[send_to_bot] 应该设置为飞书机器人的 webhook 地址")

@_check_debug
@_check_log_dir
def add_best_metric(self, value: Union[int, str, float, dict], name: str = None):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='fitlog',
version='0.7.1',
version='0.9.13',
description='fitlog: Log tool for Deep Learning, developed by Fudan FastNLP Team',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 465b356

Please sign in to comment.