一些bug小记(持续更新)

  1. pytorch的输入一般为batch,所以对于单独的输入(只有单个的输入!)来说,需要加上一维,具体操作为
    a = torch.from_numpy(a).unsqueeze(dim = 0)

    需要注意的是,此时可能会报网络结构的错误,error提示如下:
TypeError: conv2d() received an invalid combination of arguments - got (numpy.ndarray, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (!numpy.ndarray!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (!numpy.ndarray!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)

2.对于多分类任务采用损失函数:

loss_func = torch.nn.CrossEntropyLoss()
loss = loss_func(output,label)
#其中output为 softmax tensor[[0.1233,0.211,...],[],[]],label为输出类别的list=[2,3,4,1....]

3.NN进行训练时,输入loss的output必须是模型的直接输出,不要对这个输出做数值运算,否则会无法正常反向传播!我们应该让label去适应output,而不要改变output(但是类型转换是被允许的)。

4.图片的读取与存放应该是两个互逆过程,不要读取是用pil,而存放则用cv2.
给出简单实例:

#存放
im = Image.fromarray(obs)
im.save('imgs/' + str(step) + '.jpeg')
#读取
img = Image.open(path)
img = np.array(img)
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值