Skip to content

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

Open

Description

@starsky68

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仍然没用

Activity

  1. xuhao-anhe commented on Apr 22, 2021

    @xuhao-anhe

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

  2. starsky68 commented on Apr 22, 2021

    @starsky68
    Author
  3. xuhao-anhe commented on Apr 22, 2021

    @xuhao-anhe

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

  4. nmaac commented on Apr 22, 2021

    @nmaac
    Owner

    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))))

  5. starsky68 commented on Apr 22, 2021

    @starsky68
    Author

    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影响大嘛?

  6. nmaac commented on Apr 22, 2021

    @nmaac
    Owner

    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吗?
  7. starsky68 commented on Apr 22, 2021

    @starsky68
    Author

    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是会导致上面的报错的

  8. xuhao-anhe commented on Apr 22, 2021

    @xuhao-anhe

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

  9. starsky68 commented on Apr 22, 2021

    @starsky68
    Author

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

    直接去掉这两个bn

  10. xuhao-anhe commented on Apr 22, 2021

    @xuhao-anhe

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

    直接去掉这两个bn

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

  11. starsky68 commented on Apr 22, 2021

    @starsky68
    Author

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

    直接去掉这两个bn

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

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

  12. xuhao-anhe commented on Apr 22, 2021

    @xuhao-anhe

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

    直接去掉这两个bn

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

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

    好嘞 感谢回复

  13. glenn-jocher commented on Apr 22, 2021

    @glenn-jocher
    Contributor

    @nmaac I've implemented a bug patch for this in ultralytics/yolov5#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.

  14. dosemeion commented on Apr 24, 2021

    @dosemeion

    不能使用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

  15. songjiahao-wq commented on Mar 6, 2022

    @songjiahao-wq

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions