随笔分类 - 深度学习~pytorch
pytorch调用的一些代码解读
摘要:import time from options.train_options import TrainOptions from data import create_dataset from models import create_model from util.visualizer import
阅读全文
摘要:将1*(1024*128)降维为(1*1024),将(1*1024)降维为(1*512); 将(1*512)升维为(1*1024),将(1*1024)升维为1*(1024*128); self.fc = nn.Sequential( nn.Linear(1024*128, 1024), nn.Lin
阅读全文
摘要:将x4平铺成一维向量,得到x5; 将x5压缩成和x4shape一样,得到x6 x5 = x4.view(x4.size(0), -1) x6 = x5.detach().view_as(x4)
阅读全文
摘要:w_size = 512 h_size = 256 sub_input_label = torch.zeros([input_label.shape[0],input_label.shape[1],h_size,w_size], dtype=torch.float32,device=input_la
阅读全文
摘要:import torch # 正向传播时:开启自动求导的异常侦测 torch.autograd.set_detect_anomaly(True) # 反向传播时:在求导时开启侦测 with torch.autograd.detect_anomaly(): loss.backward()
阅读全文
摘要:错误: RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 32, 1, 1
阅读全文
摘要:def mutil_max_loss_two(self,R_loss,O_loss): if R_loss>O_loss: O_loss=R_loss return O_loss def mutil_max_loss_three(self,M_loss,glass_loss,O_loss): if
阅读全文
摘要:new_mask_image = torch.zeros([inst_map.shape[0],inst_map.shape[1],inst_map.shape[2],inst_map.shape[3]], dtype=torch.float32,device=inst_map.device) fo
阅读全文
摘要:def tensor2im(image_tensor, imtype=np.uint8, normalize=True): image_numpy = image_tensor.cpu().float().detach().numpy() if normalize: image_numpy = (i
阅读全文
摘要:def tensor2im(image_tensor, imtype=np.uint8, normalize=True): image_numpy = image_tensor.cpu().float().detach().numpy() if normalize: image_numpy = (i
阅读全文
摘要:一个输入: input_tensor = torch.randn([1, 3, 256, 512]) print ("Exporting to ONNX: ", onnx_save_name) torch_onnx_out = torch.onnx.export(model, input_tenso
阅读全文
摘要:打印pytorch每层参数。 采用的是直接在层中加入txt的写入。需要修改的文件位置:./site-packages/torch/nn/modules/ Conv2D v = F.conv2d(input, self.weight, self.bias, self.stride,self.paddi
阅读全文
摘要:下载地址为: https://download.pytorch.org/whl/torch_stable.html
阅读全文
摘要:def tensor2im(image_tensor, imtype=np.uint8, normalize=True): image_numpy = image_tensor.cpu().float().detach().numpy() if normalize: image_numpy = (i
阅读全文
摘要:报错: 修改: model.module.optimizer_G.zero_grad() loss_G.backward() model.module.optimizer_G.step() 为: model.module.optimizer_G.zero_grad() loss_G.backward
阅读全文
摘要:model_dict = torch.load(save_path) fp = open('model_parameter.bin', 'wb') weight_count = 0 num=1 for k, v in model_dict.items(): print(k,num) num=num+
阅读全文
摘要:pytorch+python 错误: 纠正: self.trace, _ = torch.jit.get_trace_graph(self.model, args=(self.x,)) 为: self.trace, _ = torch.jit._get_trace_graph(self.model,
阅读全文