tingsongyu / pytorch_tutorial Goto Github PK
View Code? Open in Web Editor NEW《Pytorch模型训练实用教程》中配套代码
《Pytorch模型训练实用教程》中配套代码
请问你们,第二章预训练的模型acc是60%吗?还是更高?
Traceback (most recent call last):
File "E:/王庆洲毕设/PyTorch_Tutorial-master/Code/main_training/main.py", line 38, in
writer = SummaryWriter(log_dir=log_dir)
File "D:\MiniConda3\envs\PyTorch_Tutorial-master\lib\site-packages\tensorboardX\writer.py", line 292, in init
from caffe2.python import workspace # workaround for pytorch/issue#10249
File "D:\MiniConda3\envs\PyTorch_Tutorial-master\lib\site-packages\caffe2\python_init_.py", line 2, in
from caffe2.proto import caffe2_pb2
File "D:\MiniConda3\envs\PyTorch_Tutorial-master\lib\site-packages\caffe2\proto_init_.py", line 11, in
from caffe2.proto import caffe2_pb2, metanet_pb2, torch_pb2
File "D:\MiniConda3\envs\PyTorch_Tutorial-master\lib\site-packages\caffe2\proto\caffe2_pb2.py", line 22, in
create_key=_descriptor._internal_create_key,
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'
0.0.4版本第26页处,您写道:
其实,在创建网络实例的过程中, 一旦调用 nn.Conv2d 的时候就会有对权值进行初始化
Conv2d 是继承_ConvNd,初始化赋值是在_ConvNd当中,这些值是创建一个 Tensor 时得到的,是一些很小的随机数。
实际上,并非如此,在pytorch源码中使用的是kaiming初始化,也就是说,pytorch的模型权值初始化不是很小的随机数。
为什么1_2_split_dataset.py 代码运行之后没有任何变化,代码也没有报错.正常按照你所说的应该在Data/下面有三个文件夹,但实际运行结果什么都没有这是什么原因呢?
Hello, i run the grad cam on my two projects, one is about face recognition, and the another is about video action recognition.
However, the result image of CAM focus on the corner of the image, it didn't make sense that the recognition foundation of two tasks is from the corner part of the image. Right?
I feel so puzzled about that and could someone response to me? Thanks very much~
split_dataset 的dirs不对
您好。我没有找到3.4学习率调整策略这个的对应代码 谢谢您
你好,在Code/4_viewer/6_hook_for_grad_cam.py中,第103行,出现了一个output,而函数中没有定义output,所以想请问一下这个output的含义,感谢
或者是将其归一化到均值为0,方差为1?如果按照源数据的平均值和标准差来归一化的话输入数据和原来的数据会有什么区别呢?
QQ群:671103375;入群密码修改了吗,现在进不去啊
There is no train.txt in Data
请问main.py的:
from utils.utils import MyDataset, validate, show_confMat
报错是怎么回事?utils下没有utils方法啊??
6_hook_for_grad_cam.py 完成119行的循环之后得到的cam 值全小于0怎么办
书写得很全面细致,关于detach,请教:网上很多地方都没有讲清楚detach,特别是将其值改变了之会怎么样,例如:
https://zhuanlan.zhihu.com/p/505445223 中的第一段代码,但是如果将其中“a = a0.tanh()”改为“a = a0.sin()”,如下,就可以正常运行了--没有报错,why?我的版本是2.3.0+cu121
import torch
a0 = torch.tensor([1.1, 2.2, 3.3], requires_grad = True)
a = a0.sin()
print('a=',a)
print('a.requires_grad=',a.requires_grad)
a_detach = a.detach()
print('a_detach=',a_detach)
print('a_detach.requires_grad=', a_detach.requires_grad)
a_detach.zero_()
print('a_detach=',a_detach)
print('a=',a)
print('a.requires_grad=',a.requires_grad) # 此时对原来的a求导
a.sum().backward()
print(a0.grad)
在_viewer/_visual_weights 中,不需要重写Net再加载net_params.pkl的state_dict啊,直接
pre_trained_dict = torch.load('../2_model/net_params.pkl')
就已经得到想要的state_dict了。
建议删除冗余的部分
源代码如下:
def comp_class_vec(ouput_vec, index=None):
if not index:
index = np.argmax(ouput_vec.cpu().data.numpy()) # int
else:
index = np.array(index)
index = index[np.newaxis, np.newaxis] # (1,1) ndarray
index = torch.from_numpy(index) # (1,1) Tensor
one_hot = torch.zeros(1, 1000).scatter_(1, index, 1) # 热编码 (1,1000) Tensor 全0和一个和1
one_hot.requires_grad = True
class_vec = torch.sum(one_hot * output) # 求损失
return class_vec
按照我对该Loss计算方法的理解,
比如5分类,ouput_vec最大最大概率为pos=3的类别,
ouput_vec=[0.1,0.1,0.6,0.1,0.1]
one_hot = [0,0,1,0,0]
计算torch.sum(one_hot * output)=0.6
如果pos=3类别的概率更高,计算出的torch.sum(one_hot * output)会越大。但是按直观来理解,网络判断正确的概率更高了,所以Loss应该更低才对啊?
pro_dir = os.getcwd()
train_txt_path = os.path.join(pro_dir, "Data", "train.txt")
这样更方便
在main.py里,第165行写了net.eval()
,为什么在评估完验证集结果后不需要写net.train()
把模式转换回去呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.