![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
GIS--段小楼
这个作者很懒,什么都没留下…
展开
-
pytorch bn 如何冻结 以及train 和val下区别
如何冻结一般要冻结特征提取层(pretrain layer)的bn 还有一些自己定义的bn不应该冻结 因此在自己的model里重写train#示例程序 在自己写的model里添加 def train(self, mode=True): """ Override the default train() to freeze the BN parameters """ super(fintuneNet, self).train(m原创 2022-08-09 16:37:28 · 863 阅读 · 0 评论 -
pytorch load_state_dict 保存的register_buffer的问题
pytorch load_state_dict buffer原创 2022-01-20 14:57:24 · 1028 阅读 · 0 评论 -
BN GN在卷积网络上不同
大部分讲解都是讲解的全连接的原理,我想知道一下在卷积神经网络上如何利用 找到了这个文章添加链https://www.cnblogs.com/dengshunge/p/12513712.html转载 2021-12-08 15:56:37 · 95 阅读 · 0 评论 -
numpy高维数组中 轴内交换顺序(交换列)
需求:在一个轴上交换位置 如 列之间交换[[1 2 3] [4 5 6] [7 8 9]]输出[[2 1 3] [5 4 6] [8 7 9]]方法 :采用神奇索引import numpy as npa= np.empty((9,3))for i in range(9): a[i]=ia=a.reshape((3,3,3))print(a)a[[1,0,2],...]...原创 2021-11-21 00:35:52 · 1677 阅读 · 0 评论 -
pytorch求范数norm
torch.norm官网上说不再更新 ,不保证会出现错误新的norm分在了 torch.linalg.norm(),or torch.linalg.vector_norm() when computing vector normsand torch.linalg.matrix_norm()torch.linalg.matrix_norm()测试了与一下vector的功能 符合想要的各元素平方再开根号 其余的还未测试 Net=P4ConvZ2(3, plans, kernel_s原创 2021-11-20 10:29:07 · 1384 阅读 · 0 评论 -
torch 固定旋转影像
参考import torchimport torch.nn.functional as Fimport numpy as npimport matplotlib.pyplot as pltdef get_rot_mat(theta): theta = torch.tensor(theta) return torch.tensor([[torch.cos(theta), -torch.sin(theta), 0], [torch.s原创 2021-11-08 16:51:25 · 956 阅读 · 0 评论 -
pip速度慢换清华源
pip install scipy==1.7.0 -i https://pypi.tuna.tsinghua.edu.cn/simple原创 2021-11-01 21:49:46 · 305 阅读 · 0 评论 -
register_buffer更新
pytorch 不支持在forward里更新和注册 register_buffer解决办法是吧register放在init里但是有时会遇到forward后更新buffer的操作,用上边的方法会出错Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!内部原理不清楚 但是分析一下 pytroch的cuda 和cpu类型是不同的类型 所以直接tensor赋值 会导致‘原创 2021-11-01 17:35:25 · 410 阅读 · 0 评论 -
transforms.ToTensor() 与transforms.PILToTensor()
img = PilImage.open(path) img = np.array(img) print(img) #不改变像素值大小[0~255] print(transforms.ToTensor()(img )) #改变像素值大小原创 2021-10-26 23:49:18 · 1568 阅读 · 0 评论 -
获取相对路径
import os absfile =os.path.join(dir, imname) relfile = absfile.replace(rootdir ,'') print(relfile) files.append(relfile)原创 2021-10-26 16:33:01 · 64 阅读 · 0 评论 -
随机打乱数据集和对应标签
def shuffle_list(files,labels): import random data = list(zip(files, labels)) random.shuffle(data) files[:], labels[:] = zip(*data)原创 2021-10-20 21:00:19 · 654 阅读 · 2 评论 -
pytorch 指定参数进行权重衰减
def add_weight_decay(net, l2_value, skip_list=()): decay, no_decay = [], [] for name, param in net.named_parameters(): if not param.requires_grad: continue # frozen weights if len(param.shape) == 1 or name.endswith(".bias") or name in skip_list: no_.原创 2021-10-19 20:13:48 · 1354 阅读 · 2 评论 -
pilimage 转numpy 和pytorch通道c所在位置
a= PilImage.new('RGB',(100,200))print(a.size)b=transforms.ToTensor()(a)print(b.shape)c= np. array(a)print(c.shape)输出(100, 200)torch.Size([3, 200, 100])(200, 100, 3)pilimage 输入时先宽后高(w,h),numpy在读取的时候转换为(h,w,c) pytorch转化为(c,h,w)...原创 2021-10-11 22:18:27 · 98 阅读 · 0 评论 -
numpy返回符合特定条件的索引方法
利用np.nonzero函数 按照轴顺序输出a = np.array([[1 , 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])print(a>=5)print( np.nonzero(a>=5))[[False False False False] [ True True True True] [ True True True True]](array([1, 1, 1, 1, 2, 2, 2, 2]), array([0,原创 2021-08-12 15:09:20 · 1143 阅读 · 0 评论 -
Numpy Indexing with Boolean Arrays numpy索引是bool矩阵时
布尔索索引的方法是明确选择我们想要的数组中的哪些项>>> a = np.arange(12).reshape(3, 4)>>> b = a > 4>>> b # `b` is a boolean with `a`'s shapearray([[False, False, False, False],[False, True, True, True],[ True, True, True, True]])>>>.原创 2021-08-12 14:33:58 · 340 阅读 · 0 评论 -
geopandas 与pandas
geopandas是基于pandas的逻辑开发的能够处理矢量数据的python库(是否能够处理栅格不太确定)那他与pandas的关系如何呢 用一个例子测试一下1 载入测试数据import geopandas as gpd import matplotlib.pyplot as plticosa =gpd.read_file('./icosa.shp')icosa1 =gpd.read_file('./icosaPoint.shp')2 测试geopandas的merge.与pand.原创 2021-08-06 16:49:29 · 976 阅读 · 0 评论