Datawhale 学CV--task2 模型理解

Baseline的理解:

1、取jason文件中的label

train_label = [train_json[x]['label'] for x in train_json]

2、不计算梯度,常用在测试

with torch.no_grad():

3、取模型结果

model_conv = nn.Sequential(*list(model_conv.children())[:-1])

4、图像预处理,常写在compose内,成为一组操作

transforms.Compose([... ])

5、因为model继承了nn.Module,所以必须写super

super(SVHN_Model1, self).__init__()

6. 梯度计算,梯度回传

optimizer.zero_grad()
loss.backward()

但optimizer.step()的作用是?

7、网络最后输出5个11类的概率

output = np.concatenate([ c0.data.numpy(), c1.data.numpy(),...] )

8.取val的label

val_label = [''.join(map(str, x)) for x in val_loader.dataset.img_label]

(为什么train_label不是这样取?train_label = [train_json[x]['label'] for x in train_json])

9.将概率转换为分类label

val_predict_label = np.vstack([ val_predict_label[:, :11].argmax(1),....])

分类label转换为str

val_label_pred.append(''.join(map(str, x[x!=10])))

10、test基本与val的过程相同,除了没有loss(需要提交)

11、注意看数据集的标注格式

问题:

1.num_workers 是做什么?

2.feat = feat.view(feat.shape[0], -1)是整理成[5, ?],一定要这样处理么?

为了适应FC的输入,self.fc1 = nn.Linear(512, 11),但这里是512的输入,11类的输出,feat.shape[0]=512,不是5?

3.loss是5层结果累加:

loss = criterion(c0, target[:, 0]) + criterion(c1, target[:, 1]) +。。。【target的内容是什么,target[0], target[1] 】

参考资料:

torch常用代码段:

https://bbs.cvmart.net/topics/1472

关于pytorch中使用pretrained的模型,对模型进行调整:

https://blog.csdn.net/chen_xinjia/article/details/80273592

super相关:

https://blog.csdn.net/zz2230633069/article/details/83539941

猜你喜欢

转载自www.cnblogs.com/haiyanli/p/12923016.html
今日推荐