![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Rivers(成长版)
这个作者很懒,什么都没留下…
展开
-
tensorboard画图
记录一次使用tensorboard画图实例# 导入包from torch.utils.tensorboard import SummaryWriter# 实例化内容writer = SummaryWriter('./output/log')for i in range(100):# 分别是 题目,数值,x坐标 writer.add_scalar(tag, scalar_value, global_step=None) writer.close()查看在终端输入tens原创 2022-01-01 16:02:04 · 2645 阅读 · 2 评论 -
读取文件指定行内容
python读取文件指定行内容import linecache def get_line_context(file_path, line_number): # 索引加一就是行 return linecache.getline(file_path, line_number+1).strip()原创 2021-12-27 18:30:20 · 188 阅读 · 0 评论 -
jupyter 内核挂掉或者正忙
1.python版本混乱2.pyzmq版本过高降低版本即可pip uninstall pyzmqpip install pyzmq==19.0.2原创 2021-11-16 15:31:20 · 1827 阅读 · 0 评论 -
记录一个数据集处理的类
加载数据集和相应标签熟悉一下预处理的功能import osimport cv2class Mydata(): def __init__(self, root_dir, label_dir): self.root_dir = root_dir # 所在的文件夹 self.label_dir = label_dir # 标签名称 self.path = os.path.join(self.root_dir, self.label_dir)原创 2021-09-08 00:22:29 · 69 阅读 · 0 评论 -
python打包exe
进入文件目录shift +右键 进入PowerShell输入pyinstaller -F xxx.py打包为一个文件原创 2021-03-02 17:06:32 · 65 阅读 · 0 评论 -
解决python文件读取时顺序错误问题
文件读取乱序问题文件操作的时候,经常需要处理的往往不是一个单一的文件,所以需要对文件夹进行遍历处理。这里会使用到listdir()函数获取文件夹下所有文件的文件名列表如图但是获取的顺序并不是整齐的,在做数据对应的时候可能会出现组合错误的情况。直接上代码对返回文件名列表的后缀进行切割,只对文件名进行数字比较排序值得注意,如果出现字母可能会导致错误!import osdef dir_name(path): file_list = os.listdir(path) file_原创 2021-02-28 18:40:31 · 1824 阅读 · 2 评论 -
python 获取文件夹内无后缀的文件名
自己做文件处理时写的函数,整理一下# 获取文件名def files_name(path): filesname_list = [] for i in range(len(path)): (filepath, tempfilename) = os.path.split(path[i]) (filesname, extension) = os.path.splitext(tempfilename) filesname_list.append(f原创 2021-02-22 15:38:15 · 4247 阅读 · 0 评论 -
Linux pip安装手动换源
国内源地址 阿里云 https://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣(douban) http://pypi.douban.com/simple/ 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/加-i 加源地址原创 2021-02-15 19:22:11 · 147 阅读 · 2 评论 -
python 正则表达式
# =================================匹配模式=================================#一对一的匹配# 'hello'.replace(old,new)# 'hello'.find('pattern')#正则匹配import re#\w与\Wprint(re.findall('\w','hello egon 123')) #['h', 'e', 'l', 'l', 'o', 'e', 'g', 'o', 'n', '1', '2',转载 2021-02-06 10:27:33 · 82 阅读 · 0 评论 -
python标准库基础学习
TIME模块1.时间戳代表1970年到现在的秒数一般用来算时间差print(time.time())2.按照某种格式显示的时间用于展示时间,例如记录日志2021-01-23 22:06:00# coding:utf-8import time# 例如2021-01-23 22:06:00print(time.strftime('%Y-%m-%d %H:%M:%S'))下面这个式子是默认以冒号分割的写法print(time.strftime('%Y-%m-%d %X'))3.原创 2021-01-26 14:49:20 · 153 阅读 · 0 评论 -
优化elif代码案例
记一次优化多重if / elif代码案例可以在只修改功能列表和函数定义情况下进行多功能的添加,简化添加步骤# coding:utf-8def login(): print("login successful")def search(): print("search")def close(): print("close !")# 通过字典调用函数func_list = {'0': ['exit', None], '1': ['logi原创 2021-01-06 17:35:58 · 142 阅读 · 0 评论 -
Python 文件基础操作
python文件操作1.打开文件open(r'C:a/b/c.txt') 在windows下“\”是转义字符,所以添加 r 可以去除转义效果如果不加 r 可以将所有右斜杠换成左斜杠2.读取文件r是文件可读t是文本模式f=open('1.txt',mode='rt',encoding='utf-8')res=f.read()print(res)3.关闭文件关闭文件,回收空间f.close()del f一般情况下因为操作系统的打开文件数会影响性能所以关闭文件是必要的回原创 2020-12-23 00:36:44 · 87 阅读 · 0 评论 -
python for循环的语法
python for循环1.什么是for循环毋庸置疑,循环就是重复执行那我们就要知道for循环的便利性2.存在意义for在循环取值上的便利性高于while。3.基本语法for 变量名 in 可迭代对象: 代码可迭代对象 例如,遍历字符串,数组,列表,字典,元组做一个简单的循环取值for i in ['mm_boy','giao_brother','yaoshui']: print(i)mm_boygiao_brotheryaoshuifor循环次数等于可迭代原创 2020-12-04 17:41:49 · 441 阅读 · 0 评论 -
numpy基本用法
numpy1.reshape 变换形状import numpy as np#建立一维数组t1=np.arange(12)#转为3行4列t2=t1.reshape((3,4))t2array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])此时有两种变化形式括号中第二个数字的不同第一种情况#reshapeimport numpy as np#建立一维数组t1=np.arange(12)原创 2020-11-22 16:43:08 · 481 阅读 · 1 评论 -
Linux服务器运行easyocr代码
Linux服务器上运行easyocr代码上一篇文章介绍过如何安装easyocr这里我们使用jupyter notebook进行编译1.生成密钥,这里可以自己设定一个密码用于登录jupyterfrom notebook.auth import passwdpasswd()2.密码设置成功之后会生成一串哈希字符(对密码的加密)形如 sha1:xxx:xxx 的一串字符3.命令行输入以下代码,生成config配置文件jupyter notebook --generate-config4.原创 2020-11-20 10:53:01 · 822 阅读 · 0 评论 -
Linux下安装python torch easyocr
linux下安装torch、easyocreasyocr 是一个文字识别的第三方库但是安装步骤有点麻烦,也是花费了大半天,总结一下。由于easyocr库的安装需要torch库的支持,所以先去安装torch库torch库的下载链接https://pytorch.org/get-started/locally/#installing-on-linux选择自己适合的版本,底下会显示出下载命令下载完成之后一般情况下会成功安装,但是也有二般情况hhh有一个PEP517的错误tips:这里我用ctr原创 2020-11-18 22:16:17 · 1138 阅读 · 2 评论 -
python第三方库解决超时报错
python库的安装问题解决超时报错pip升级python -m pip install --upgrade pip -i https://pypi.douban.com/simplepip安装库pip install -i https://pypi.doubanio.com/simple/ 库名还可以尝试在下面文件夹的 pip.ini文件中添加一些内容c/USER/admin//appdate/roaming内容如下[global]timeout = 60000index-url原创 2020-09-24 23:10:52 · 176 阅读 · 0 评论