
torch
_Raymond_
尽量不要私信,直接邮件联系我 <santa.cs@qq.com>
展开
-
torch的DataParallel保存的模型如何载入
使用DataParallel保存的模型在保存后载入的时候存在权重不匹配的问题,原因是每层的参数是会比原来多一个module的设置。import torchfrom collections import OrderedDict#python自带的库state_dict=torch.load(config.model_save_path+"_best")["model"]#我的权重存储在文件的model字段里面的'''state = { 'model': model原创 2021-12-10 10:45:39 · 629 阅读 · 0 评论 -
Object has no attribute ‘weight’
今天在进行torch模型的初始化的时候,发现报错:Object has no attribute ‘weight’回顾模型,发现在模型权重初始化函数,定义的带有conv的层的初始化是这样的。def weights_init(m): """init the weight for a network""" classname=m.__class__.__name__ # print(classname) if classname.find("conv")!=-1:原创 2021-03-16 15:20:37 · 13704 阅读 · 2 评论 -
cv2 写入图片成功 但是读取图片失败 int-float的坑
今天在读取png,在将png读入之后,想做一个/255并保存为.tif格式,出现大问题。写入图片import cv2 import numpy as npfrom google.colab.patches import cv2_imshowimg =cv2.imread("/content/drive/MyDrive/mathcup/B/t1/107.png",2)# 1彩色2灰度img=img/255cv2.imwrite("/content/t1.tif",img,[int(cv2原创 2021-01-20 02:43:05 · 900 阅读 · 5 评论 -
torch repeate 的用法
import torchimport torch.nn.functional as Fimport numpy as npa = torch.Tensor(128,1,512)B = a.repeat(1,5,1)print(B.shape[0])print(B.shape)128torch.Size([128, 5, 512])原创 2021-01-16 21:20:23 · 223 阅读 · 0 评论