这是篇关于炼丹期间如何摸鱼的文章~~
微信设置 本来可以通过itcahr,在模型训练完成后向文件传输助手发送消息来告知模型已经训练完毕。但是现在貌似网页版微信已经不可以使用了,所以基于ServerChan发送消息,分享给大家。
Server Chan 首先需要在server酱官网:http://sc.ftqq.com/3.version注册账号,直接绑定github账号即可,会获得一个SCKEY
发送消息非常简单,只需要向以下URL发一个GET或者POST请求:
1 https://sc.ftqq.com/SCU167709T5fac1f4393bbd77463bb8b3d13ce33836066159859760.send
接受两个参数:
text:消息标题,最长为256,必填。
desp:消息内容,最长64Kb,可空,支持MarkDown。
最简单的消息发送方式是通过浏览器,在地址栏输入以下URL,回车后即可发送:
1 https://sc.ftqq.com/SCU167709T5fac1f4393bbd77463bb8b3d13ce33836066159859760.send?text=主人服务器又挂掉啦~
在PHP中,可以直接用file_get_contents来调用:
1 file_get_contents('https://sc.ftqq.com/SCU167709T5fac1f4393bbd77463bb8b3d13ce33836066159859760.send?text='.urlencode('主人服务器又挂掉啦~'));
可以把它封装成一个函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 function sc_send( $text , $desp = '' , $key = 'SCU167709T5fac1f4393bbd77463bb8b3d13ce33836066159859760' ) { $postdata = http_build_query( array( 'text' => $text, 'desp' => $desp ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); return $result = file_get_contents('https://sc.ftqq.com/'.$key.'.send', false, $context); }
使用 直接用pip安装dinglingling插件或者使用上文的github链接中的代码根据教程自行安装后即可。 直接在需要监测的函数前加上装饰器wx_reminder即可。使用demo代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from dinglingling import wx_reminderSCKEY = "" proxy = "" @wx_reminder(SCKEY=SCKEY, proxy=proxy, remind_started=True ) def test_correct_func (): print ("hello world" ) @wx_reminder(SCKEY=SCKEY, proxy=proxy ) def test_error (): raise Exception("test error" ) if __name__ == "__main__" : test_correct_func() pass
邮件
设置好邮箱的smtp服务,(和outlook客户端收发邮件一个道理)
把需要发送的信息作为邮件发送出去
核心代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMultipartdef send_email (subject="No subject" , content="I am boring" ): mail_host = "smtp.163.com" mail_user = "yuetan@163.com" mail_pw = "********" sender = "yuetan@163.com" receiver = "yuetan@lynk.com" msg = MIMEText(content, "plain" , "utf-8" ) msg['Subject' ] = subject msg['From' ] = sender msg['To' ] = receiver try : smtp = smtplib.SMTP_SSL(mail_host, 994 ) smtp.login(mail_user, mail_pw) smtp.sendmail(sender, receiver, msg.as_string()) print ("Email send successfully" ) except smtplib.SMTPException: print ("Error: email send failed" ) if __name__ == '__main__' : send_email(subject="Training finished" , content="I am boring" )
邮箱设置 程序中有个mail_pw是邮箱授权码,可以通过自己的邮箱获取。登录自己常用的邮箱,以163为例。打开设置,将SMPT服务开启:
开启后,通过发送短信得到授权密码。(注意保密,泄漏后就相当于邮箱密码泄漏了)
将授权密码赋值给程序中的mail_pw变量即可。
其他
Loss出现NAN时,自动结束训练。可通过assert或if判断,否则继续训练没有意义了
可配合nohup命令使用,即使断开服务器连接也在后台继续训练
如果想定时发送邮件,可配合crontab命令