![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
scut_salmon
这个作者很懒,什么都没留下…
展开
-
正则转义和字符串转义
在学习Python正则式的过程中,有一个问题一直困扰我,如何去匹配一个反斜杠(即“\”)?一、引入在学习了Python特殊字符和原始字符串之后,我觉得答案应该是这样的:1)普通字符串:'\\'2)原始字符串:r'\'但事实上在提取诸如“3\8”反斜杠之前的数字时,我屡次碰壁,始终得不到结果。最终发现自己理解错了,原来原始字符串和“正则转义”没有一点关系;下面详细谈一谈。二、字符串转义反斜杠,在Python中比较特殊,就是它可以用来构成一些特殊字符...转载 2021-01-13 16:48:18 · 1676 阅读 · 0 评论 -
cv2.imread返回none type解决方案
cv2.imread有时返回none type,可能是因为路径含有中文路径,也可能不是这个原因,但是图片是好的,可以正常打开。这时可以换一个文件读取方案:import PILnp.array(PIL.Image.open('000.jpg').convert('RGB'))...原创 2020-02-25 20:11:51 · 4982 阅读 · 3 评论 -
python PIL图片拼接
w_num = 5 h_num = int(len(imgs)/w_num) + 1 UNIT_SIZE = 200 # 一张图的大小是200*200 target_shape = (w_num * (UNIT_SIZE + 10), h_num * (UNIT_SIZE + 10)) # shape[0]表示横坐标,shape[1...原创 2019-09-16 17:21:53 · 2710 阅读 · 0 评论 -
python实现引用参数
1. 问题描述python没有C++中的指针和引用这些概念,直接传入变量不能实现类似引用参数的功能。def incr_num(num): num += 1num = 0num0incr_num(num)num0这是因为:2. python中的整数都有其固定id>>> a=5>>> b=5>>&g...原创 2019-05-12 10:54:38 · 3423 阅读 · 0 评论 -
python cv2 findContours函数和drawContours函数介绍
findContours函数和drawContours函数是画轮廓很方便的函数首先贴两张函数参数表,这是C++上的OpenCV接下来分别看具体用法和参数格式1.findContourscontours, hierarchy = cv2.findContours( thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SI...原创 2019-04-19 17:26:33 · 5410 阅读 · 0 评论 -
python cv2获取中心点坐标
img = cv2.imread(pic_path)h, w = img.shape[0]w表示横方向的长度,h表示纵方向的长度,一般我们表示坐标位置都是横轴为x,纵轴为y,所以中心点坐标应该表示为(w/2, h/2)...原创 2019-04-22 13:14:31 · 12194 阅读 · 0 评论 -
tf.graph为什么要加个as_default
我理解的原因参考自这两篇博客:https://www.cnblogs.com/studylyn/p/9105818.htmlhttps://blog.csdn.net/dcrmg/article/details/79028032也就是as_default应用于有多个graph的场景,如果整个程序中只有一个graph,写法是这样的: a = tf.constant([1.0,...原创 2018-11-30 16:51:55 · 1235 阅读 · 0 评论 -
torch代码解析 为什么要使用optimizer.zero_grad()
optimizer.zero_grad()意思是把梯度置零,也就是把loss关于weight的导数变成0.在学习pytorch的时候注意到,对于每个batch大都执行了这样的操作: # zero the parameter gradients optimizer.zero_grad() # forward + backward + optim...原创 2018-09-05 09:58:20 · 152404 阅读 · 47 评论 -
python for循环显示进度
from progressbar import Percentage, ProgressBar,Bar,ETAbar = ProgressBar(widgets=[Bar('>', '[', ']'), ' ', Percentage(), ' ', ETA()],maxval=len(im_files))其中im_files为要循环的目标,如:for im_file in bar(im_f...原创 2018-03-22 21:19:18 · 4518 阅读 · 0 评论 -
如何使用ipynb文件并转化为py文件
首先使用pip install jupyter安装jupyter notebook。在ipynb所在的目录打开jupyter notebook ,只需要在终端输入:jupyter notebook在浏览器打开的jupyter即可打开并使用ipynb文件,File=》Download as =》Python(.py)即可把ipynb文件转化为py文件原创 2018-02-07 13:04:27 · 22100 阅读 · 0 评论 -
numpy.concatenate 中的axis参数怎么理解
首先numpy.concatenate的官方使用说明为:https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.concatenate.htmlnumpy.concatenate中有两个参数,一个是由被连接的数组组成的序列(a1, a2, ...);另一个就是axis。1. 假设被连接的数组有两个,为a, b,连接之后为数...原创 2018-02-12 19:51:17 · 18537 阅读 · 2 评论 -
如何用matplotlib画图并保存图像
1. 首先,import头文件如下:import matplotlib matplotlib.use('Agg')import matplotlib.pyplot as pltfrom matplotlib.pyplot import plot,savefig2. 画图时:fig, ax = plt.subplots(figsize=(12, 12))...原创 2017-12-18 15:08:32 · 40684 阅读 · 4 评论 -
python中的getopt怎么理解
在看crfascnn代码的demo时看到这个语句,上网查了一下,可以参考这个博文:http://blog.csdn.net/chengxuyuanyonghu/article/details/42556885demo中相关的代码以及我的解释如下: try: opts, args = getopt.getopt(argv, 'hi:o:g:', ["ifile=原创 2018-01-22 16:50:05 · 658 阅读 · 0 评论 -
如何输出python中list的维度
import numpy as npa = [[1,2],[3,4]]print(np.array(a).shape)print(len(a), len(a[0]))原创 2017-12-18 15:36:35 · 75983 阅读 · 3 评论 -
AU标注辅助小程序
人生苦短,我用python~import cv2import osimport matplotlibimport matplotlib.pyplot as pltimport numpy as npimport shutilimport csvdef check_landmark(): os.system('cls') path = os.getcwd() path =原创 2017-12-24 23:43:24 · 930 阅读 · 0 评论 -
读取csv文件快速返回行数
csv_reader = csv.reader(open('somefile.csv', encoding='utf-8')) # 有的文件是utf-8编码np.array(list(csv_reader)).shape[0]原创 2017-12-23 16:34:58 · 20862 阅读 · 7 评论 -
numpy中的True/False如何转化成1/0
在array后加个0就可以,操作如下:原创 2017-12-13 23:42:17 · 21218 阅读 · 0 评论