PyTorch
LemonTree_Summer
这个作者很懒,什么都没留下…
展开
-
requires_grad 和 volatile 碎碎念整理
torch生成的tensor requires_grad默认为Falsedataloader生成的batch_data和batch_label默认为Falserequires_grad 和 volatile 的操作都相当于or,只要有一个为True,加和的结果也为Truevolatile=False 相当于 requires_grad=True,意味着需要梯度volatile=True 用于 inference模式,只要输入volatile=True,那么输出Variab..原创 2020-08-20 14:50:13 · 358 阅读 · 0 评论 -
matplotlib画图:如何一个图共用两个Y轴
import matplotlib.pyplot as pltfig = plt.figure() ax1 = fig.add_subplot(111) l1 = ax1.plot(int_epoch2, int_prec12, 'darkcyan', label='test accuracy of ResNet20') l2 = ax1.plot(int_epoch3,...原创 2019-10-29 10:18:42 · 3611 阅读 · 0 评论 -
如何计算模型的FLOPs
pip install thop先配置环境,如上。 from torchvision.models import resnet50 from thop import profile model = resnet50() input = torch.randn(1, 3, 224, 224) flops, params = profile(model...原创 2019-10-16 10:13:29 · 3393 阅读 · 1 评论 -
python-拷贝图片/移除图片
import numpy as npimport shutilimport osroot = '/root/……/datasets/face_newData'trainA_path = root + '/trainA'trainB_path = root + '/trainB'trainC_path = root + '/trainC'testA_path = root + '/t...原创 2018-07-04 16:01:30 · 1389 阅读 · 0 评论 -
画图函数
drawContours 画轮廓minAreaRect 计算最小面积的外接矩形contourArea计算轮廓内连通区域的面积pointPolygenTest判断一个点是否在一个多边形内mathShapes比较两个形状的相似性 待补充。。。。...原创 2018-07-24 21:39:40 · 858 阅读 · 0 评论 -
python-在固定点粘贴图片
from PIL import Imagefrom ...FaceRotate import FaceRotatefrom ...Morph import Morphimport cv2from numpy import *def merge(): source_path = '/root/Desktop/test.jpg' yuantu = cv2.imread(sou...原创 2018-07-16 10:13:11 · 896 阅读 · 0 评论 -
nn.ReflectionPad2d()
先举个例子:input = torch.randn(64, 3, 220, 220) # input size# 4-tuplepad = nn.ReflectionPad2d((3, 3, 5, 5)) # laft, right, top, bottomoutput = pad(input) # size(64, 3, 230, 226)# intpad = nn.Refl...原创 2018-08-05 18:13:58 · 10301 阅读 · 0 评论 -
np.clip()
首先cv2读的图片相加时会自动规约到(0, 255)path1 = ''path2 = ''img1 = cv2.imread(path1)img2 = cv2.imread(path2)img = img1 + img2.astype(int)img = np.clip(img/2, 0, 255).astype(np.unit8)cv2.imshow('1', img)c...原创 2018-08-06 15:53:33 · 1976 阅读 · 0 评论 -
ps算法操作
传送门ps混合模式公式:https://www.cnblogs.com/kex1n/p/3663533.html参考code: https://blog.csdn.net/matrix_space/article/details/72284090原创 2018-08-08 17:33:10 · 975 阅读 · 0 评论 -
softmax和log_softmax,CrossEntropyLoss()和NLLLoss()
1. Softmax:接收一个实数向量,返回一个概率分布。假设X是一个实数的向量(正数或者负数都可以),然后第i个softmax(x)的组成是 log_softmax: 在softmax的结果上再做一次log运算,数学上等价于lo...原创 2018-09-18 14:37:19 · 2864 阅读 · 4 评论 -
Pytorch常用函数整理
1.torch.numel() 返回tensor变量内所有元素的个数,也可以简单理解为矩阵内yu元素的个数 例如,a的size为([64, 3, 7, 7]),那么a.numel() 返回值为64*3*7*7=94082.torch.squeeze() 将输入张量形状中的1去除并返回,如果输入是形如(Ax1xBx1xCx1xD),那么输出形状就为(AxBxCxD)3.torch...原创 2018-10-26 17:47:42 · 3697 阅读 · 0 评论 -
python-extend vs append
原创 2018-11-30 15:47:04 · 217 阅读 · 0 评论 -
如何查看图片某一位置的像素值以及改变其值
import cv2root = '/root/group-dia/zxb/test.jpg'img = cv2.imread(root)print img.item(10, 10, 0)print img.item(10, 10, 1)print img.item(10, 10, 2)img.itemset((10, 10, 0), 0)img.itemset((10, 10, ...原创 2018-06-28 16:15:02 · 17383 阅读 · 0 评论 -
卷积网络中FeatureMap的height/width计算
Feature Map:Height: (input_height - kernel_size + 2*padding )/stride[0] + 1Width: (input_width - kernel_size + 2*padding )/stride[1] + 1原创 2018-06-25 19:26:47 · 447 阅读 · 0 评论 -
各种loss简介-待更新
1.nn.MSEloss: 均方误差,X和Y维度要一致(可以是向量或者矩阵),i是下标 loss(Xi, Yi) = (Xi - Yi)的平方2.nn.BCEloss: 二分类的交叉熵,用的时候在该层前面要+sigmoid函数loss(Xi, Yi) = -Wi[Yi logXi + (1-Yi)log(1-Xi)] X/Y可以是向量或者矩阵,i是下标,Xi表示第i个样本预测为正例的概率,Yi表示...原创 2018-06-25 20:00:57 · 3947 阅读 · 0 评论 -
Pytorch-图片融合
from PIL import Imageimg1 = Image.open( "bridge.png ")img1 = img1.convert('RGBA')img2 = Image.open( "birds.png ")img2 = img2.convert('RGBA') img = Image.blend(img1, img2, 0.3)img.show()img.save( "b...原创 2018-06-19 17:00:46 · 2349 阅读 · 0 评论 -
Python-基础
1.关于读图片img = Image.open('root')img.save('../test.jpg')cv2.imread('root')cv2.imwrite('root')2.字符分割string = '1_A.jpg'a = string.split('_')[0]b = string.split('_')[1]3.numpy <--> tensorA = n...原创 2018-06-19 16:59:32 · 175 阅读 · 0 评论 -
Python-图片同时横向纵向拼接
import osfrom PIL import ImageUNIT_SIZE = 220 # the size of imagesave_path = '/root/group-dia/zxb/Code-/lip-CycleGAN-and-pix2pix-master/checkpoints/lip_cyclegan_6.0/web/result/out'path = "/root/gr...原创 2018-07-02 14:14:00 · 1232 阅读 · 0 评论 -
python-判断文件/图片路径是否存在
我问问原创 2018-07-02 14:47:24 · 8768 阅读 · 0 评论 -
python-图片横向拼接
import osfrom PIL import ImageUNIT_SIZE = 220 # the size of imageTARGET_WIDTH = 6 * UNIT_SIZEsave_path = '/root/……cyclegan_6.0/web/result1/'path = "/root/……cyclegan_6.0/web/images"images = [] #...原创 2018-07-02 16:45:32 · 3524 阅读 · 0 评论 -
BatchNorm VS InstanceNorm
1.BatchNorm Batch_Norm是对一个☝️batch进行规整,是为了防止同一个batch间的梯度相互抵消。其将不同batch规整到同一个均值0和方差1,这就要两个参数来记录batch的均值e,方差c。其是对每一个神经元进行的,由于将均值方差规整到同一个数字,限制了特征的分布特性,因此会降低网络的表达能力,所以还要引入a1和a2来改变每一个特征维度的概率分布,从而增加网络的表达能力。训...原创 2018-06-27 14:48:39 · 8319 阅读 · 1 评论 -
python-图片纵向拼接
import osfrom PIL import ImageUNIT_SIZE = 220 # the size of imagesave_path = '/root/group-dia/zxb/Code-/lip-CycleGAN-and-pix2pix-master/checkpoints/lip_cyclegan_6.0/web/result3/'path = "/root/grou...原创 2018-07-02 17:06:40 · 1856 阅读 · 0 评论 -
Pytorch:Variable detach
举个栗子原创 2018-06-27 15:28:10 · 346 阅读 · 0 评论 -
python-关于改变图片的大小-resize
第一种:用Imageroot = ''pic = Image.open(root)pic = pic.resize((220, 220))第二种:用cv2root = ''crop_size = (320, 480)img = cv2.imread(root)img_new = cv2.resize(img, crop_size, interpolation = cv2.INTER_CU...原创 2018-07-16 10:24:51 · 61182 阅读 · 1 评论 -
np.concatenate() 和 torch.cat()
self._A = np.array(self.real_A)self._B = np.array(self.real_B)self._make = np.array(self.make_real)self.input_G = np.concatenate((self._A, self._B), axis=1) # Addself.input_G = torch.from_numpy(se...原创 2018-06-28 14:32:56 · 16442 阅读 · 0 评论 -
action='store_true'
关于parser.add_argument()记录一个特殊的情况:action栗子1:self.parser.add_argument('--lr_use', action='store_true', default=False, help='if or not use lr_loss')当在终端运行的时候,如果不加入--lr_use, 那么程序running的时候,lr_use的值为defaul...原创 2018-06-20 18:03:02 · 29904 阅读 · 12 评论