python
生成滞涨网络~
Intel(R) Core(TM) i9-10900X CPU @ 3.70GHz
展开
-
GPU利用率(gpu-util)低下的可能原因
本文章分享一下自身遇到的一个问题,参考很多其他文章对GPU利用率低的解答发现自己都解决了,可是利用率还是一会儿10%一会儿90%。我的原因是使用了VGG模块用于计算感知损失。for epoch in range(start_epoch , opt.nEpochs): for iteration, batch in enumerate(training_data_loader, 1): ... vgg = Vgg19(requires_grad=False).to('cuda') ...原创 2022-01-08 08:50:47 · 3409 阅读 · 0 评论 -
如果要对tensor维度变换尽量使用tf.tanspose()而不是tf.reshape()
如果要对tensor维度变换尽量使用tf.tanspose()而不是tf.reshape()原创 2021-12-18 22:37:32 · 207 阅读 · 0 评论 -
AttributeError: ‘Tensor‘ object has no attribute ‘numpy‘
这是由于tensorflow版本过高所致,为了兼容之前版本的运算,加入语句:tf.enable_eager_execution()import tensorflow as tftf.enable_eager_execution() # 关键原创 2021-12-14 10:26:33 · 3264 阅读 · 0 评论 -
关于python维度扩充
如果扩充一个维度可以考虑tf.expand_dims,但是扩充多个维度就显得吃力了。直接上代码:grid_x = torch.tensor([-1, 0, 1, 0.5], dtype=torch.float)grid_x = grid_x[None, None, :, None] # 扩充维度至[1,1,4,1]原创 2021-12-03 23:38:08 · 790 阅读 · 0 评论 -
关于conv2d的参数
X【batch_size, in_channels, height_1, width_1】batch_size:一个batch中样本的数量in_channels:通道数,取决于样本的通道,比如RGB图像的通道数是3height_1:图片的高width_1:图片的宽Conv2d的参数【channels, number, height_2, width_2】channels:通道数,要与输入的通道数保持一致,channels=in_channels.number:卷积核的数量height_2转载 2021-09-13 14:28:03 · 580 阅读 · 0 评论 -
使用在train中指定CUDA_VISIBLE_DEVICES=1无效
我的train文件:import torchimport osimport torchvisionfrom helpers import get_rays, sample_pdf, to8b, to_disp_img, img2mse, mse2psnros.environ["CUDA_VISIBLE_DEVICES"]="1"def train(): return 0 train()但是实际上发现训练还是在0卡上训的,后来查阅相关资料发现,我需要进行两步设置。把 impo原创 2021-09-10 14:15:24 · 4361 阅读 · 0 评论 -
关于tensor维度的实验
dataset.get_styles() #{Tensor:(100,64)}all_style_inds #{Tensor:(4800,)}dataset.get_styles()[all_style_inds] #{Tensor:(4800,64)}可以发现[]相当于在dataset.get_styles()第一个维度上对每一个all_style_inds的数值。原创 2021-08-23 16:11:58 · 64 阅读 · 0 评论 -
关于列表赋值的效率问题
import timedef main(): t1=time.time() count1={} count2={} for i in range(1000000): count1[i]=[] count1[i].append(i) t2=time.time() count2=count1 t3=time.time()原创 2021-08-21 19:53:09 · 45 阅读 · 0 评论 -
view和reshape的区别
因为历史上view方法已经约定了共享底层数据内存,返回的Tensor底层数据不会使用新的内存,如果在view中调用了contiguous方法,则可能在返回Tensor底层数据中使用了新的内存,这样打破了之前的约定,破坏了对之前的代码兼容性。为了解决用户使用便捷性问题,PyTorch在0.4版本以后提供了reshape方法,实现了类似于 tensor.contigous().view(*args)的功能,如果不关心底层数据是否使用了新的内存,则使用reshape方法更方便。...转载 2021-08-19 10:51:00 · 347 阅读 · 0 评论 -
torch.gather以及torch,searchsorted使用示例
**torch.gather使用**import torchtensor_0 = torch.arange(3, 12).view(3, 3)print(tensor_0)#tensor([[ 3, 4, 5],# [ 6, 7, 8],# [ 9, 10, 11]])index = torch.tensor([[2, 1, 0]]).t()tensor_1 = tensor_0.gather(1, index)print(tensor_1)原创 2021-08-18 10:46:47 · 2212 阅读 · 0 评论 -
AttributeError: Can‘t get attribute ‘guess_gender‘ on <module ‘__main__‘ (built-in)>
问题描述:AttributeError: Can’t get attribute ‘guess_gender’ on <module ‘main’ (built-in)>原始代码:import sysimport gender_guesser.detector as genderimport multiprocessingimport timed = gender.Detector()def guess_gender (name): n = name.title(转载 2021-08-17 09:40:13 · 567 阅读 · 0 评论 -
GlobalAveragePooling中x.mean([2,3])的理解
class GlobalAveragePooling(nn.Module): def __init__(self): super().__init__() def forward(self, x): return x.mean([2, 3])在GlobalAveragePooling2D有如下代码:def call(self, inputs): if self.data_format == 'channels_last': retur原创 2021-08-16 16:23:30 · 1351 阅读 · 0 评论 -
关于top-k的使用
k=1时topk与max一致import torchpred = torch.randn((4, 5))print(pred)values, indices = pred.topk(1, dim=1, largest=True, sorted=True)print(indices)# 用max得到的结果,设置keepdim为True,避免降维。因为topk函数返回的index不降维,shape和输入一致。_, indices_max = pred.max(dim=1, keepdim=Tru转载 2021-08-15 21:49:57 · 368 阅读 · 0 评论 -
f‘{i:0>4}‘用法总结
学了这么长时间python居然没看过0>4的写法,后来写了下面几行验证一下1. 当要使输出靠右,左边补足0,总共4位时:def main(): for i in range(100): print(f'{i:0>4}')输出如下:0001......009800992. 当要使输出靠左,左边补足0,总共5位时:def main(): for i in range(100): print(f'{i:0<4}')输.原创 2021-08-14 21:44:51 · 853 阅读 · 0 评论 -
state_dict()用法示例
torch.nn.Module模块中的state_dict变量存放训练过程中需要学习的权重和偏执系数.torch.optim模块中的Optimizer优化器对象也存在一个state_dict对象,此处的state_dict字典对象包含state和param_groups的字典对象,而param_groups key对应的value也是一个由学习率,动量等参数组成的一个字典对象。#encoding:utf-8 import torchimport torch.nn as nnimport torc转载 2021-08-14 19:46:44 · 2674 阅读 · 0 评论 -
python如果存在路径便删除重建
import os if os.path.exists(opt.output_dir) and os.path.isdir(opt.output_dir): shutil.rmtree(opt.output_dir) os.makedirs(opt.output_dir, exist_ok=False)exist_ok=False意味着不能存在该路径,若存在则报错原创 2021-08-14 19:21:53 · 296 阅读 · 0 评论 -
torch.nn.functional.grid_sample实验
# -*- coding: utf-8 -*-# @Author: H.Yang# @Date: 2021-08-14 11:58:04# @Last Modified by: H.Yang# @Last Modified time: 2021-08-14 11:59:27import torchimport torch.nn as nntest = torch.rand(1,1,3,3)test[0][0][0][0]=1test[0][0][0][1]=2test[0][0原创 2021-08-14 12:12:14 · 255 阅读 · 0 评论 -
RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment
问题:RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero.解决办法:sudo apt-get install nvidia-modprobe...原创 2021-08-12 19:53:49 · 431 阅读 · 0 评论 -
python项目中同级目录下包导入仍旧 No module named ‘’
同级python文件在导入时使用import a 仍旧No module named a如图所示,我运行train.py时会调用loader.py包,然后loader.py包又导入了同级目录下的datasets.py。可是编译器一直报错no module named ‘datasets’。解决方案:虽然是同级目录,然是其却找不到,采用import stereomag.datasets as datasets便可以解决问题。(暂时不知道原因)...原创 2021-06-26 16:31:11 · 5029 阅读 · 0 评论 -
使用tensorflow时cuda报错Could not load dynamic library ‘libcudart.so.11.0‘; dlerror: libcudart.so.11.0:
dlerror: libcudart.so.11.0:问题解决首先找到你的电脑路径/usr/local/cuda/lib64查看自己的cuda版本根据上图发现我的电脑的cuda版本为10.0,因此运行时会报错,这时有两种解决方案。方案一强制把本机的cuda环境指定为运行的cuda环境,有可能出现问题,我没试过。cd /usr/local/cuda/lib64/sudo ln -sf libcudart.so.10.0 libcudart.so.11.0方案二在conda环境中安装动态原创 2021-06-26 12:00:49 · 3162 阅读 · 0 评论 -
python划分数据集
python划分数据集http://www.javashuo.com/article/p-rrubrucl-mw.html转载 2021-03-17 21:30:36 · 181 阅读 · 0 评论 -
python安装成功后,cmd运行python指令提示“不是内部命令”终极解决办法!!!
如果你已经设置好了这样。结果cmd输入python还是报错,那么兄弟。重启计算机!!!cmd重新输入python命令就Ok了。原创 2020-11-08 21:30:39 · 1118 阅读 · 0 评论