Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4_efficientdet] Raise KeyError during training in CPU #85

Open
SadiaAfrinPurba opened this issue Dec 10, 2020 · 1 comment
Open

[4_efficientdet] Raise KeyError during training in CPU #85

SadiaAfrinPurba opened this issue Dec 10, 2020 · 1 comment

Comments

@SadiaAfrinPurba
Copy link

SadiaAfrinPurba commented Dec 10, 2020

If I set use_gpu=false or CUDA is not available, then I got the following KeyError-

Traceback (most recent call last): File "D:\efficientdet\trainer.py", line 28, in train gtf.Train_Dataset(root_dir=self.dataset_root_dir, File "D:\train_detector.py", line 61, in Train_Dataset "batch_size": self.system_dict["params"]["batch_size"] * self.system_dict["local"]["num_gpus"], KeyError: 'num_gpus'

I tried to fix the problem by initializing these parameters in constructor- self.system_dict["local"]["num_gpus"], self.system_dict["local"]["device"]

class Detector():
    def __init__(self, verbose=1):
        self.system_dict = {}
        self.system_dict["verbose"] = verbose
        self.system_dict["local"] = {}
        self.system_dict["local"]["num_gpus"] = 1 <- set value as 1
        self.system_dict["local"]["device"] = 'cuda' if torch.cuda.is_available() else 'cpu' <- to avoid KeyError: 'device'`

train_detector.py

After that, I got the following errors-

Traceback (most recent call last):
  File "c:\users\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\train_detector.py", line 197, in Train
    cls_loss, reg_loss = self.system_dict["local"]["model"](
  File "D:\site-packages\torch\nn\modules\module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "model.py", line 258, in forward
    c3, c4, c5 = self.backbone_net(img_batch)
  File "D:\site-packages\torch\nn\modules\module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "model.py", line 187, in forward
    x = self.model._swish(self.model._bn0(self.model._conv_stem(x)))
  File "site-packages\torch\nn\modules\module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "site-packages\efficientnet_pytorch\utils.py", line 144, in forward
    x = F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups)
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

Is there any solution to train efficiendet-b0 model in CPU?

@abhi-kumar
Copy link
Contributor

Yes, I think updates to a few places might make it work. I will check it up in a couple of days and update you on the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants