Skip to main content

Wttch's train helper

Project description

wttch 的 AI 训练工具包

一、消息通知

1.1 钉钉 webhook 通知

钉钉 webhook 机器人API

from wttch.train.notification import DingtalkNotification

# 钉钉机器人 webhook 的链接
webhook_url = ''
# 消息签名的密钥
secret = ''

notification = DingtalkNotification(webhook_url, secret)

# 发送文本通知
notification.send_text("")
# 发送markdown
notification.send_markdown('')

1.2 企业微信 webhook 通知

企业微信机器人API

from wttch.train.notification import WechatNotification

# 企业微信机器人 webhook 的链接
webhook_url = ''
notification = WechatNotification(webhook_url)

# 发送文本通知
notification.send_text("")
# 发送markdown
notification.send_markdown('')

二、训练工具包

2.1 缓存工具

不需要修改太多代码就可以帮助你缓存数据到指定的缓存文件去。

(1). 添加 cache_wrapper; (2). 正常调用你的函数。

from wttch.train.utils import cache_wrapper

# 缓存的文件名字前缀,函数的参数会被添加到该名字后面
prefix = 'dataset'
# 缓存的文件夹位置
save_path = './dataset_cache'


@cache_wrapper(prefix=prefix, save_path=save_path)
def you_load_dataset_function():
    return {'a': 1, 'b': 2}


you_load_dataset_function()

2.2 计时器

from wttch.train.utils import StopWatch

stopwatch = StopWatch()
stopwatch.start("job 1")
# 费时操作
stopwatch.stop()
stopwatch.start("job 2")
# 费时操作
stopwatch.stop()

# 格式化打印
stopwatch.display()

2.3 进度条

简单包装了 tqdm 工具。

from wttch.train.utils.progress import Progress

with Progress(total=1000) as progress:
    for i in range(1000):
        # 在这里训练

        # 进度条末尾显示训练结果
        progress.train_result(loss=0.01, acc=0.02)

三、torch 工具包

3.1 方便设备获取

(1). 将使用的设备写入 thread local; (2). 从 thread local 中获取设备数据; (3). 训练。

from wttch.train.torch.utils import try_gpu, get_device_local, set_device_local

# 尝试获取 gpu 并写入 thread local
set_device_local(try_gpu(device_no=0))

# 从 thread local 读取设备
device = get_device_local()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wttch-train-helper-0.0.13.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

wttch_train_helper-0.0.13-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file wttch-train-helper-0.0.13.tar.gz.

File metadata

  • Download URL: wttch-train-helper-0.0.13.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for wttch-train-helper-0.0.13.tar.gz
Algorithm Hash digest
SHA256 659291d675ea94f1cf460aacdf5644737a57e319d179f0ad9a885ec3371fdbe3
MD5 aacd9487ddb2171c4f31cc9a5f57c249
BLAKE2b-256 0d95939e62a3035258571727323b9c7fc160219b47a488c3d2de01d810ecd865

See more details on using hashes here.

File details

Details for the file wttch_train_helper-0.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for wttch_train_helper-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c1a43a4da82d881bc0baf6afa5f5b6a50de32fc2796f5e14407e2dda0e5b3a0e
MD5 fb4ace36b1dddfe45e1d08c8f10a2c7f
BLAKE2b-256 a10f2cea2baa926cf5d8a736425b53c89f2a2248f6324d47019c8f064861aecb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page