acon icon indicating copy to clipboard operation
acon copied to clipboard

ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 16, 1, 1])

Open starsky68 opened this issue 3 years ago • 15 comments

ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 16, 1, 1]) 会在这一行,beta = self.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True)))))) 会莫名其妙出现这个错误,然后早dataloader中使用了drop_last=True仍然没用

starsky68 avatar Apr 22 '21 02:04 starsky68

巧了 我也出现这个错误了 不会是在yolov5上改的吧

xuhao-anhe avatar Apr 22 '21 04:04 xuhao-anhe

我是修改的一个conv,就这样了,

------------------ 原始邮件 ------------------ 发件人: "nmaac/acon" @.>; 发送时间: 2021年4月22日(星期四) 中午12:44 @.>; @.@.>; 主题: Re: [nmaac/acon] ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 16, 1, 1]) (#4)

巧了 我也出现这个错误了 不会是在yolov5上改的吧

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

starsky68 avatar Apr 22 '21 04:04 starsky68

一样的,我也改了drop_last也没用 找了半天找不到原因,希望博主能解答一下

xuhao-anhe avatar Apr 22 '21 05:04 xuhao-anhe

Hi @starsky68 @xuhao-anhe , seems the error is caused by the batch size value. If you set batch size = 1, please remove the bn layers: beta = self.sigmoid(self.fc2(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True))))

nmaac avatar Apr 22 '21 05:04 nmaac

Hi @starsky68 @xuhao-anhe , seems the error is caused by the batch size value. If you set batch size = 1, please remove the bn layers: beta = self.sigmoid(self.fc2(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True))))

感谢你的回复,我们设置的batchsize=8,bn层的除去,会对meta-aconc影响大嘛?

starsky68 avatar Apr 22 '21 05:04 starsky68

Hi @starsky68 @xuhao-anhe , seems the error is caused by the batch size value. If you set batch size = 1, please remove the bn layers: beta = self.sigmoid(self.fc2(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True))))

感谢你的回复,我们设置的batchsize=8,bn层的除去,会对meta-aconc影响大嘛?

  1. 这里指单卡batchsize,从 torch.Size([1, 16, 1, 1]) 报错信息可以看到 batchsize=1 造成 bn 报错;
  2. batchsize很小的情况下有无bn本身影响就不大。另外确认一下,你普通conv层后面有bn吗?

nmaac avatar Apr 22 '21 05:04 nmaac

Hi @starsky68 @xuhao-anhe , seems the error is caused by the batch size value. If you set batch size = 1, please remove the bn layers: beta = self.sigmoid(self.fc2(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True))))

感谢你的回复,我们设置的batchsize=8,bn层的除去,会对meta-aconc影响大嘛?

Hi @starsky68 @xuhao-anhe , seems the error is caused by the batch size value. If you set batch size = 1, please remove the bn layers: beta = self.sigmoid(self.fc2(self.fc1(x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True))))

感谢你的回复,我们设置的batchsize=8,bn层的除去,会对meta-aconc影响大嘛?

  1. 这里指单卡batchsize,从 torch.Size([1, 16, 1, 1]) 报错信息可以看到 batchsize=1 造成 bn 报错;
  2. batchsize很小的情况下有无bn本身影响就不大。另外确认一下,你普通conv层后面有bn吗?

普通的卷积后面是有bn的,然而,你的meta acon不是一个激活函数接口嘛,我就直接调用的,想acon一样,那个是没问题的,目前确实这里的bn是会导致上面的报错的

starsky68 avatar Apr 22 '21 05:04 starsky68

请问你解决了吗,解决的话,方便分享一下经验吗?

xuhao-anhe avatar Apr 22 '21 10:04 xuhao-anhe

请问你解决了吗,解决的话,方便分享一下经验吗?

直接去掉这两个bn

starsky68 avatar Apr 22 '21 10:04 starsky68

请问你解决了吗,解决的话,方便分享一下经验吗?

直接去掉这两个bn

去掉激活函数的归一化会不会造成梯度爆炸啊,还是只需要在激活函数之前弄一次归一化就可以了

xuhao-anhe avatar Apr 22 '21 10:04 xuhao-anhe

请问你解决了吗,解决的话,方便分享一下经验吗?

直接去掉这两个bn

去掉激活函数的归一化会不会造成梯度爆炸啊,还是只需要在激活函数之前弄一次归一化就可以了

去掉此处的两个bn不会造成梯度爆炸,前面有bn啊,

starsky68 avatar Apr 22 '21 10:04 starsky68

请问你解决了吗,解决的话,方便分享一下经验吗?

直接去掉这两个bn

去掉激活函数的归一化会不会造成梯度爆炸啊,还是只需要在激活函数之前弄一次归一化就可以了

去掉此处的两个bn不会造成梯度爆炸,前面有bn啊,

好嘞 感谢回复

xuhao-anhe avatar Apr 22 '21 10:04 xuhao-anhe

@nmaac I've implemented a bug patch for this in https://github.com/ultralytics/yolov5/pull/2901, but it's not a great solution, as any YOLOv5 model with MetaAconC() activations will not be able to run batch-size 1 inference properly.

glenn-jocher avatar Apr 22 '21 23:04 glenn-jocher

不能使用batchsize=1,yolov5里面的yolo.py改成m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(2, ch, s, s))]) # forward

dosemeion avatar Apr 24 '21 09:04 dosemeion

请问是直接修改的conv函数吗?YOLOv5修改后效果很差

songjiahao-wq avatar Mar 06 '22 03:03 songjiahao-wq