![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
brooknew
这个作者很懒,什么都没留下…
展开
-
opencv 使用approxPolyDP轮廓近似
approx = cv2.approxPolyDP(contour,epsilon,True) 采用Douglas-Peucker算法,可参考:https://blog.csdn.net/foreverling/article/details/78066632第一个参数是轮廓的点集。第二个参数epsilon的含义如下所述,滤掉的线段集离新产生的线段集的距离为d,若d小于epsilon,则滤掉,...原创 2019-12-12 16:58:21 · 19803 阅读 · 3 评论 -
Tensorflow 中计算图Graph,会话Session,变量和操作的关系
计算图描述一个问题的解决方案,包含变量/占位符(统称张量,数据节点)、操作(运算节点),程序开始运行时会有一个缺省的计算图来收纳这些节点,也可以通过tf.Graph() .as_default()来创建新的计算图作为缺省的计算图。一个Session对应一个计算图,在tf.Session( graph=传入的计算图)中传参数达到,如省略参数,就使用缺省的计算图。张量和运算属于计算图,要是没有活跃的计...原创 2018-10-16 11:59:22 · 3282 阅读 · 0 评论 -
英文和数字手写数据集
是在 tablet 上手写的 Chars74k(http://www.ee.surrey.ac.uk/CVSSP/demos/chars74k/) 的一部分 ,放在 EnglishHnd.tgz 中 图像是1200x900的png文件。参考 https://www.cnblogs.com/qdsclove/p/5865463.html...转载 2018-10-09 16:35:14 · 11161 阅读 · 1 评论 -
Tensorflow 使用 pb 文件保存(恢复)模型计算图和参数
一 、 保存:graph_util.convert_variables_to_constants 可以把当前session的计算图串行化成一个字节流(二进制),这个函数包含三个参数:参数1:当前活动的session,它含有各变量 参数2:GraphDef 对象,它描述了计算网络 参数3:Graph图中需要输出的节点的名称的列表返回值:精简版的GraphDef 对象...原创 2018-10-15 20:08:22 · 4074 阅读 · 1 评论 -
关于 tf.get_variable()
参考 https://blog.csdn.net/u012436149/article/details/53696970/对同一个变量名使用get_variable()不止一次时必须放在 name_scope里面,并且要设定 reuse=tf.AUTO_REUSE,这样多次get_variable时采用的是同一个变量。import tensorflow as tf def fun():...原创 2018-10-18 14:05:12 · 1487 阅读 · 0 评论 -
Google提供的基于mnist 深度学习教程
代码 :https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/tutorials/mnist文档:http://www.tensorfly.cn/tfdoc/tutorials/mnist_tf.html原创 2018-10-12 12:00:37 · 223 阅读 · 0 评论 -
csv 读和添加记录,且判断是不是有列标题
csv.reader 是一个迭代器。直接上代码: import csvdef readCsv(): with open( 't.csv', 'r' ) as fr : rd = csv.reader( fr ) print( 'type:' , type( rd ) ) for next1 in rd : ...原创 2018-09-19 15:17:18 · 1898 阅读 · 0 评论 -
python 的zip函数
python 3 和 python 2 不一样,要显示 zip的话,需要用内置函数 list()转换,但是list转换之后,zip对象就变空了。a = [1,2,3]b = ['a','b','c']z = zip( a , b )type(z)d1 = list(z)d2 = list(z)print('d1',d1)print('d2',d2)输出:d1 [(1, 'a'), (...原创 2018-07-06 10:59:52 · 222 阅读 · 0 评论 -
spyder 的运行
spyder3原创 2018-07-05 15:34:07 · 8492 阅读 · 0 评论 -
鸢尾花分类问题
来自于 《python机器学习基础教程》[德] Andreas C. Muller [美] Sarah Guido 著 张亮(hysic)译 的 第一章。from sklearn.datasets import load_irisiris_dataset = load_iris()In [9]:print( (iris_dataset.keys()))dict_keys(['data', ...原创 2018-07-04 17:01:39 · 2695 阅读 · 0 评论 -
Tensorflow 实现迁移学习的例子
本文通过代码展示Tensorflow实现迁移学习。数据是使用程序产生的。该学习例子中,输入含两个分量,对应学生的单词量和阅读量,输出是英语分数。就是通过单词量、阅读量和英语分数的标注数据来学习一个模型,根据该模型从单词量和阅读量来预测英语分数。神经网络计算图如下,左分支是原始计算图,通过pb文件把该计算图算出来的网络参数和计算图保存,右边是迁移学习的计算图,它把左面学习出来的w1,b1读出来,以...原创 2018-10-17 13:42:17 · 2829 阅读 · 9 评论 -
python 字符串格式化
python 可以通过string.format() 函数产生一个格式化的字符串。string中含的 { 和 } 内部的东西是格式。大括号外面的字符原样进入format返回的字符串里,而大括号的语法是这样:{format内的参数位置:位宽及补足办法\}例子1 : str1 = 'string:{3:d} {0:s}' str2 = str1.format('teststring...原创 2018-10-19 11:31:35 · 748 阅读 · 0 评论 -
如何清空 Tensorflow 默认图
tf.reset_default_graph() 可以清空默认图里所有的节点。下面代码transferLearnRetrainLayer2()里是要迁移学习(重用)tensorflowMain()训练出来的模型,见https://blog.csdn.net/brooknew/article/details/83107491(Tensorflow 实现迁移学习的例子)。若不包含上面这句的话,在t...原创 2018-10-17 14:42:05 · 4769 阅读 · 0 评论 -
矩阵点乘在opencv和 numpy里的实现
import cv2import numpy as np>>> c = np.zeros( (2,2) )>>> a = np.array( [[1.0,2.0],[3.0,4.0] ])>>> b = np.array( [[0.0,1.0],[1.0,0.0] ])>>> d = cv2.gemm(a,b...原创 2019-06-20 09:26:50 · 1477 阅读 · 0 评论 -
关于串口
要安装pyserial:https://blog.csdn.net/absinjun/article/details/81407790使用python3实现操作串口详解:https://www.jb51.net/article/153839.htmlinux如何查看哪个串口是真实串口,哪个串口:https://blog.csdn.net/p09080016/article/details/...转载 2019-05-07 10:44:33 · 142 阅读 · 0 评论 -
python opencv 模板匹配
注意判断读取文件是否成功用 img is None 不是 img == None:import cv2def displayOneImage() : srcFile = "F:\\deep\data\\dataForStudyOpencv\\1_869307B00644_20190312_052816_410.bmp" img = cv2.imread( src...原创 2019-03-15 10:57:43 · 249 阅读 · 0 评论 -
sigmoid_cross_entropy_with_logits的计算方法
sigmoid_cross_entropy_with_logits 可以衡量已标注过数据预测的正确度。比如一个(x,y)数据项,x表示输入取值为实数,y表示标注取值0或1。根据x算出一个概率p=1/(1+e^(-x)) 。 可以看到,当x=0时p=0.5 ,标注为1或0的概率各50%;x>0 时,p>0.5, x越大p越接近于0;x < 0 时,p<0.5。所以 L=ylo...原创 2018-11-30 17:08:02 · 4543 阅读 · 0 评论 -
解卷积
import numpy as npimport tensorflow as tfdef convOne(): input = tf.Variable(tf.random_normal([1 ,3 ,3 ,5])) filter = tf.Variable(tf.random_normal([1 ,1 ,5 ,1])) op = tf.nn.conv2d(input...原创 2018-11-16 17:08:07 · 4883 阅读 · 0 评论 -
list 做成员的list 乘以一个数的机制
list 的list 乘以一个数,后面每个子list更新时都会复制,因为他们的id一样。见代码:def mk1() : a1 = [[]]*2 a2 = [[],[] ] print( 'a1' , a1 ) print( 'a2' , a2 ) print( 'id', id(a1[0]) , id(a1[1]) ) a1[0].append...原创 2018-11-07 17:10:37 · 3377 阅读 · 0 评论 -
深度学习神经网络收敛的经验
本人训练过一些深度学习神经网络的例子,既有单纯全连接网络,又有卷积神经网络加全连接网络,也有通过迁移学习来构建的网络。有时会发散,也就是说有关参数越来越大,产生Nan溢出。表现为激活值(也就是前向网络的输出)和代价函数(loss、cost)溢出。基本上可以通过修改超参数来避免。1 全连接网络的乘法因子矩阵不能初始化为零,要初始化为一个满足正态分布的随机数集,标准差不能太大。训练mnist识别卷...原创 2018-10-30 16:11:44 · 9679 阅读 · 0 评论 -
PIL 的详细用法
https://blog.csdn.net/zhangziju/article/details/79123275pip install --user pillow转载 2018-10-23 13:06:10 · 2021 阅读 · 1 评论 -
Jupyter 的安装和使用
安装: pip install --user jupyter打开: 在Git bash 里 输入:jupyter notebook$ jupyter notebook[I 09:13:55.621 NotebookApp] Serving notebooks from local directory: C:\Users\inc970015[I 09:13:55.621 NotebookApp] 0...原创 2018-07-04 10:34:49 · 442 阅读 · 0 评论 -
python 使用 threading 实现多线程的例子
使用 threading.Thread实例化一个线程对象,传给threading.Thread的三个实参分别是:线程函数target、线程名称name、线程函数的实参(将所有实参打包在元祖中。只有一个参数的话,后面要加个逗号)。使用 Thread.start()启动线程的运行。Thread.join 表示等待该线程结束才运行到下一条指令。这个例子包含三个线程,主线程启动两个子线程。主线程启动子线程...原创 2018-06-26 13:43:40 · 1312 阅读 · 0 评论 -
python 多线程
参考 多线程()https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143192823818768cd506abbc94eb5916192364506fa5d000)转载 2018-06-25 16:58:12 · 127 阅读 · 0 评论 -
安装 windows 上的 tensorflow
GPU 版安装:https://blog.csdn.net/zw__chen/article/details/79374467参考 https://tensorflow.google.cn/install/install_windows要安装 TensorFlow,请启动终端。然后在该终端中发出正确的 pip3 install 命令。要安装仅支持 CPU 的 TensorFlow 版本,请...原创 2018-05-13 09:37:30 · 422 阅读 · 0 评论 -
将mnist数据集按标签起文件名输出为一系列png文件
mnist 是手写识别样本库,包含0到9手写图像和标签。有三个数据集:训练集(55000个)、验证集(5000个)和测试集(10000个)。含在四个文件里:train-images-idx3-ubyte.gz ,train-labels-idx1-ubyte.gz , t10k-images-idx3-ubyte.gz 和 t10k-labels-idx1-ubyte.gz 。可以使用下面的代...原创 2018-05-18 14:07:39 · 2388 阅读 · 0 评论 -
利用Python调用百度地图服务的地点检索Web API爬取某一市(区)的外国语学校
接口url如下:http://api.map.baidu.com/place/v2/search?query=外国语学校&region=南京市建邺区&output=json&ak=你的Keyak获取的地方:http://lbsyun.baidu.com/apiconsole/key地点检索的说明网址: http://lbsyun.baidu.com/index.php?ti...原创 2018-05-11 14:59:25 · 3273 阅读 · 1 评论 -
如何申请百度API Key
https://blog.csdn.net/mrib/article/details/77897581点击打开链接转载 2018-05-11 11:52:06 · 24280 阅读 · 0 评论 -
模拟 Tensorflow 神经网络的训练
模拟一个Tensorflow 使用 平方差错误作为 loss 函数的例子,模拟的原始代码是基于https://github.com/cj0012/AI-Practice-Tensorflow-Notes/blob/master/tf.zip 的tf3_6.py值模拟第一轮的w1。import tensorflow as tfimport numpy as npdef forwardnn(xa, w...原创 2018-05-17 13:47:21 · 469 阅读 · 0 评论 -
python Web API 的使用
使用Python Web API 可以动态获取网站上的信息。《Python编程:从入门到实践》袁国忠译 , 第17章讲解了有关这方面的内容。首先要安装 requests 包:python -mpip install --user requests对于Github ,在运行书上的内容之前,需要获得一个 token。使用requests.get 等方法时把 token作为 headers加入实参。 #...原创 2018-05-10 16:55:58 · 3425 阅读 · 0 评论 -
matplotlib 设定坐标的上下限:matplotlib.pyplot.xlim
《Python编程:从入门到实践》袁国忠译 , 第16章 第318页运行该页的代码得到的图形和书上的图不一样。书上的图是这样:而直接运行该页程序得到的图是这样:这时候需要加上设定x轴范围的语句:plt.xlim(dates[0] , dates[-1] )。整个程序如下:import csvimport matplotlib.pyplot as pltfrom datetime import da...原创 2018-05-09 15:32:01 · 38168 阅读 · 1 评论 -
python next()函数
https://blog.csdn.net/bear_sun/article/details/78479449转载 2018-05-09 13:56:41 · 777 阅读 · 0 评论 -
修改python ide 自动补全的间隔时间
修改python ide 自动补全的间隔时间:改 Python\Python36\Lib\idlelib\ config-extensions.def 的[AutoComplete]popupwait= 2000为:[AutoComplete]popupwait= 500原创 2018-05-09 12:03:59 · 1195 阅读 · 0 评论 -
Tensorflow 1.8 训练两个输入预测一个输出的训练过程
基于https://github.com/cj0012/AI-Practice-Tensorflow-Notes/blob/master/tf.zip 的tf3_6.pytf3_6-v3.py:(只修改了print)#coding:utf-8#0导入模块,生成模拟数据集。import tensorflow as tfimport numpy as npBATCH_SIZE = 8SEED = 23...原创 2018-05-13 10:18:15 · 6632 阅读 · 0 评论 -
tensorflow 输出一个2x3 的矩阵
import tensorflow as tf#w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1))print("e2")with tf.Session() as sess : print( type( sess ) ) w1= tf.Variable([[1,2,3],[10,20,30]]) init_op =...原创 2018-05-13 11:09:58 · 3398 阅读 · 1 评论 -
基于python 和 matlab的矩阵奇异值分解
https://www.cnblogs.com/pinard/p/6251584.html 可参考。 一个 mxn的矩阵H可以分解为 U(mxm) ,S(mxn) , V(nxn) 三个矩阵的乘积,这就是奇异值分解。S是一个对角矩阵,一般从大到小排列,S的元素值称为奇异值。Matlab和python均提供奇异值分解的函数:Matlab:>> a = [1,2,3,4;2,3...原创 2018-06-18 18:54:30 · 1768 阅读 · 0 评论 -
使用 pyinstaller 创建可执行文件时的一个小麻烦
想使用pyinstaller 创建exe文件,首先安装 pyinstaller :pip install pyinstaller然后 对一个python 文件进行操作:pyinstaller -F hello.py 会在dist目录下产生 hello.exe 但是若你的源文件目录包含一个 operand.py 的文件的话,就会出来很多的bug,这是由于这个·operand.py和python内部的...原创 2018-06-18 15:55:36 · 3817 阅读 · 0 评论 -
pip 升级到10版时直接使用pip install就不行了, 以及解决方法
pip 升级到10版时直接使用 pip install就不行了:pip install --user pyinstaller 出现下面的错误:而使用这个是可以的:python -m pip install --user pyinstaller原创 2018-06-22 14:14:25 · 1188 阅读 · 0 评论 -
tensorflow 的 control_dependencies函数
tensorflow.control_dependencies( tasklist )可以把tasklist里的操作作为预定操作。一般是这样使用:with tensorflow.control_dependencies( tasklist ) : trainOp = tensorflow.no_op() 然后执行这个 trainOp (即Tensorflow.Session(...原创 2018-06-07 16:48:40 · 862 阅读 · 0 评论 -
python list嵌套的切片,规律难以理解
一维python list的切片没有问题。可是嵌套list也就是多维的切片,规律就难以理解,目前还没找到规律,请看下面的代码: def printm1m2(): print( m1 ) print( m2 )m1 = [[1,2,3,4],[21,22,23,24] , [31,32,33,34]]m2 = [[100,200,300,400] , [101,201,301...原创 2018-05-31 06:41:58 · 5728 阅读 · 2 评论