![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
我的Python学习
GAN_player
渣硕一枚
展开
-
Python记录日志——在终端输出并保存到本地文件
import loggingdef initLogging(logFilename): """Init for logging """ logging.basicConfig( level = logging.DEBUG, format='%(asctime)s-%(levelname)s-%(mes原创 2017-10-07 12:14:54 · 12395 阅读 · 0 评论 -
举例说明函数tf.train.exponential_decay用法
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt learning_rate = 0.1 decay_rate = 0.99 global_steps = 1000 decay_steps = 100 global_ = tf.Variable(tf.constant(0)) c转载 2017-08-09 13:32:50 · 1162 阅读 · 0 评论 -
collections.nametuple的用法
可将一个object的各种相关的属性当做类的属性来用import collectionsCircle = collections.namedtuple('Circle', 'x,y,r')c=Circle(1,1,4)print(c.x,c.y,c.r)原创 2017-09-02 20:54:11 · 443 阅读 · 0 评论 -
Python如何给文件按顺序重命名
思路:先遍历文件夹,因为遍历顺序可能不同,所以要把文件转换为整形,排序之后,在重命名.代码如下: 机器学习批量处理图片可能会用到import ospath='/home/no1/Desktop/python_program/rename_file'file_1=[file[:-4] for file in os.listdir(path) if file[-4:]=='.tif']for ind原创 2017-07-16 18:09:34 · 7465 阅读 · 0 评论 -
tf.where 和 tf.cond对比
import tensorflow as tfpred=tf.placeholder(dtype=tf.bool,name='bool')x=tf.constant(1)y = tf.cond(pred,lambda:x+1,lambda:x-1)z=tf.where(pred,x+1,x-1)with tf.Session() as sess: sess.run(tf.global_原创 2017-09-01 21:00:06 · 9217 阅读 · 0 评论 -
parser的可视化_get_kwargs的用法
import argparseparser=argparse.ArgumentParser()parser.add_argument('--batch_size',type=int,default=1,help='batch size, default: 1')parser.add_argument('--image_size',type=int,default=256,help='image原创 2017-09-01 20:45:27 · 2722 阅读 · 0 评论 -
Python制作一个简单的计算器
from tkinter import *from tkinter import ttkclass Calculator(): calc_value = 0.0 div_trigger = False mult_trigger = False add_trigger = False sub_trigger = False def button_pres原创 2017-09-25 19:17:03 · 4807 阅读 · 0 评论 -
tensorflow将训练好的模型freeze,即将权重固化到图里面,并使用该模型进行预测(tf.graph_util.convert_variables_to_constants函数)
我们很多时候需要保存tensorflow模型的pb文件,这时用tf.graph_util.convert_variables_to_constants函数会非常方便。 1.训练网络:fully_conected.pyimport argparseimport osimport timeimport tensorflow as tfimport datasets_mnist# Basic mo原创 2017-08-25 20:07:06 · 13244 阅读 · 3 评论 -
GAN经验总结
“` 一、GAN原理介绍 说到GAN第一篇要看的paper当然是Ian Goodfellow大牛的Generative Adversarial Networks,这篇paper算是这个领域的开山之作。GAN的基本原理其实非常简单,这里以生成图片为例进行说明。假设我们有两个网络,G(Generator)和D(Discriminator)。正如它的名字所暗示的那样,它们的功能分别是:G是一个生成图片转载 2017-09-15 18:00:36 · 932 阅读 · 0 评论 -
爬虫入门2——爬代理ip地址
import urllib.requestimport redef url_open(url): req=urllib.request.Request(url) req.add_header('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.原创 2017-09-23 17:57:30 · 503 阅读 · 0 评论 -
爬虫入门1——爬图
import urllib.requestimport osdef url_open(url): req=urllib.request.Request(url) req.add_header('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0原创 2017-09-22 17:32:47 · 1238 阅读 · 0 评论 -
爬虫入门0
import urllib.requestimport urllib.parseimport jsonimport timeimport random#下载图片def download(): response=urllib.request.urlopen('http://sv14.haoi23.net:8009/pic/21/1004_14_21213213BE9FA2LL6H.g原创 2017-09-22 15:52:35 · 497 阅读 · 0 评论 -
tf.image.crop_to_bounding_box的用法
import tensorflow as tfwith tf.gfile.FastGFile('5.jpg','rb') as f: img=f.read() img=tf.image.decode_jpeg(img,channels=3) img = tf.image.resize_images(img, size=(286, 286))rand=tf.random_u原创 2017-09-06 15:10:25 · 6208 阅读 · 1 评论 -
进度条小工具
import sysdef view_bar(message, num, total): rate = num / total rate_num = int(rate * 40) rate_nums = math.ceil(rate * 100) r = '\r%s:[%s%s]%d%%\t%d/%d' % (message, ">" * rate_num, " "原创 2017-10-08 12:03:37 · 850 阅读 · 0 评论 -
新技能,微信批量发送中秋节信息给好友~~
import itchatfrom time import sleepitchat.auto_login()friends=itchat.get_friends(update=True)[0:]m=0for i in friends: beizhu=i['RemarkName'] if len(beizhu)<5 and len(beizhu)>1:#备注名字在1到4个汉字原创 2017-10-09 11:37:07 · 2512 阅读 · 0 评论 -
Python如何生成自带信息的二维码
找一张女神作为验证码的中心import qrcodefrom qrcode.constants import ERROR_CORRECT_Hfrom PIL import Imagedef generateQRCode(data, imgFn): qr = qrcode.QRCode(version=20, error_correction=E原创 2017-10-11 10:04:51 · 3385 阅读 · 1 评论 -
如何计算fpr95
对于二分类问题,我们经常通过ROC曲线及FPR95来判断分类器的好坏。这里提供两种方法。一种是sklearn.metrics中的roc_curve包,可直接用于计算在不同阈值下,TPR和FPR对应的值,进而可以得出TPR=0.95时,FPR的值。"""label=1表示正样本,scores为预测概率,数值越大,越有可能是正样本"""from sklearn.metrics impor...原创 2018-12-20 10:44:46 · 6593 阅读 · 0 评论 -
如何彻底打乱一个数组
import numpy as npdef abs_shuffle(arr0): arr = arr0.copy() for i in np.arange(len(arr)-1,0,-1): idx = np.random.choice(range(i)) arr[i], arr[idx] = arr[idx], arr[i] return arrarr1 =...原创 2018-11-08 16:49:16 · 574 阅读 · 0 评论 -
python实现图像直方图均衡
def histeq(img,nbr_bins=256): """ Histogram equalization of a grayscale image. """ imhist, bins = np.histogram(img.flatten(), nbr_bins, normed = True) cdf = imhist.cumsum() # cumulative...原创 2018-08-08 17:26:22 · 3894 阅读 · 0 评论 -
python实现投影变换
def warp_perspective(src, M, width, height, origin_x, origin_y, flags=cv2.INTER_NEAREST, borderMode=cv2.BORDER_CONSTANT, borderValue=0, dst=None): """ Implementation in Py...原创 2018-08-08 17:25:17 · 4387 阅读 · 0 评论 -
Ubuntu14.04+opencv3.0.0+opencv_contrib3.0.0
最近在搭建caffe,需要用到opencv,所以在此写一个教程。步骤如下:###########################第一步 安装opencv######################################1.官网下载opencv。顺便下载一个很难下载的包,他的名字叫:ippicv_linux_20141027。这里可以用我上传的文件(opencv3.0 其他版本...原创 2017-05-08 19:09:08 · 1073 阅读 · 0 评论 -
tf.nn.conv1d
inputs=tf.ones((64,64,3)) w=tf.constant(1,tf.float32,(5,3,32)) tf.nn.conv1d(inputs,w,2,’SAME’) Out[38]:原创 2018-02-26 09:40:32 · 4554 阅读 · 0 评论 -
Python-matplotlib基本操作
废话不多说,直接来干货。 1.用matplotlib画函数图:import numpy as npfrom matplotlib import pyplot as pltx = np.arange(0, 3 * np.pi,0.1)siny=np.sin(x)cosy=np.cos(x)plt.plot(x,siny,label='sin')plt.plot(x,cosy,label=原创 2017-07-14 18:44:02 · 1217 阅读 · 0 评论 -
matplotlib调整子图间距,调整整体空白
fig.tight_layout()#调整整体空白 plt.subplots_adjust(wspace =0, hspace =0)#调整子图间距原创 2017-11-15 18:17:18 · 79560 阅读 · 1 评论 -
matplotlib如何不显示图片只保存图片
matplotlib迭代次数多了之后,如果每次都显示,会卡顿,因此下面这种方法可以不显示,直接保存import numpy as npimport matplotlibmatplotlib.use('Agg')from matplotlib.pyplot import plot,savefigx=np.linspace(-4,4,30)y=np.sin(x);plot(x,y,'--*b原创 2017-11-15 17:42:39 · 16200 阅读 · 5 评论 -
如何将gif动态图转化成每帧图片
from PIL import Imageimport osgifFileName = 'test.gif'#使用Image模块的open()方法打开gif动态图像时,默认是第一帧im = Image.open(gifFileName)pngDir = gifFileName[:-4]#创建存放每帧图片的文件夹os.mkdir(pngDir)try: while True:原创 2017-10-13 11:42:00 · 11349 阅读 · 0 评论 -
非极大值抑制——NMS实例
输入:左上角和右下角坐标 输出:留下的boxes的索引import numpy as npimport cv2import matplotlib.pyplot as pltimport randomdef py_cpu_nms(dets, thresh): """Pure Python NMS baseline.""" x1 = dets[:, 0] y1 = de原创 2017-10-11 16:14:14 · 775 阅读 · 0 评论 -
Python计算机视觉里的IOU计算
其中x1,y1;x2,y2分别表示两个矩形框的中心点def calcIOU(x1, y1, w1, h1, x2, y2, w2, h2): if((abs(x1 - x2) < ((w1 + w2)/ 2.0)) and (abs(y1-y2) < ((h1 + h2)/2.0))): left = max((x1 - (w1 / 2.0)), (x2 - (w2 / 2.原创 2017-10-11 11:06:39 · 5019 阅读 · 1 评论 -
旋转图片之opencv
import cv2import numpy as npimport osfile=os.listdir()pictures=[i for i in file if i[-4:]=='.jpg']name=1for per_img in pictures: img = cv2.imread(per_img) rows,cols,channel = img.shape原创 2017-08-28 21:38:25 · 415 阅读 · 0 评论 -
tf.identity()的理解
import tensorflow as tfx = tf.Variable(1.0)x_plus_1 = tf.assign_add(x, 1)with tf.control_dependencies([x_plus_1]): y = x z=tf.identity(x,name='x')init = tf.global_variables_initializer()wit原创 2017-08-23 20:43:47 · 11871 阅读 · 2 评论 -
tf.get_collection获取训练变量等效用法
# train_vars=tf.trainable_variables()# g_vars=[var for var in train_vars if var.name.startswith('generator')]# d_vars=[var for var in train_vars if var.name.startswith('discriminator')]原创 2017-08-23 11:22:54 · 8546 阅读 · 1 评论 -
ubuntu如何利用终端单步执行程序
python -m pdb [文件名] b [breakpoint position] c [回车] n[回车] 举个例子: python -m pdb ./tools/demo_rfcn1.py –net ResNet-101 –gpu 0原创 2017-07-17 21:25:57 · 1780 阅读 · 0 评论 -
python-numpy的各种函数的使用
本来想总结的,后来发现别人实在是总结的太好了,直接贴出来吧,方便以后查阅。 参考文献: http://blog.csdn.net/u010156024/article/details/50419338转载 2017-07-13 16:36:13 · 645 阅读 · 0 评论 -
tensorflow拟合曲线
单值法:import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt# Prepare train datatrain_X = np.linspace(0, np.pi, 100)train_Y=np.sin(train_X)# Define the modelX1 = tf.placeholder("f原创 2017-07-20 13:10:54 · 2121 阅读 · 0 评论 -
用tensorflow训练神经网络之手写体
input_data.py :from __future__ import absolute_importfrom __future__ import divisionfrom __future__ import print_functionimport gzipimport osimport tempfileimport numpyfrom six.moves import url原创 2017-07-19 11:49:04 · 744 阅读 · 0 评论 -
matplotlib如何写出汉字
from matplotlib.font_manager import FontProperties import numpy as npimport matplotlib.pyplot as plt font = FontProperties(fname="/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf", size=1原创 2017-07-16 15:13:52 · 1140 阅读 · 0 评论 -
去掉字符串中空格的四种方法
方法一:def remove_space(text): return ''.join([i for i in text if i!=' '])print(remove_space('hello my name is fang'))方法二:string='hello my name is fang'print(string.replace(' ',''))方法三:def remove_s原创 2017-07-16 10:16:17 · 2638 阅读 · 0 评论 -
cv2.destoryAllWindows()无效的解决方法
本小白在学习cv的时候,发cv2.imshow()之后,窗口关闭不了了,百度找不出来原因。最后谷歌到了两种解决方式: 原来的代码:import cv2from scipy.misc import imread, imsave, imresizeimport numpy as npfrom matplotlib import pyplot as pltimg = np.zeros((512,5原创 2017-07-14 10:31:05 · 33465 阅读 · 4 评论 -
Python对class的理解
我把class分为两类,一类是不带init 方法的类。具体给例子:class Greeter(): def greet(name): print( 'Hello, %s' % (name.upper() ) )g = Greeter # Construct an instance of the Greeter classg.greet('fred')原创 2017-07-13 10:28:44 · 1944 阅读 · 0 评论 -
Python关于from * import *的理解
首先必须保证主文件在最顶级。调用时,主函数不应该存在 from . import ** 的情况。但是被调用的各个模块可以有。from . import ** 表示从此程序所在路径,调用同属文件夹下的init.py 程序。from .* import * 表示从此程序所在路径,调用同属文件夹下的** 程序from .. import ** 表示调用上一层路径的模块原创 2017-07-13 09:52:23 · 2406 阅读 · 0 评论