File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/root/autodl-tmp/project/tools/../lib/net/pointnet2_msg.py", line 88, in forward b, c, n = x.size() AttributeError: 'NoneType' object has no attribute 'size'
时间: 2023-06-27 15:08:05 浏览: 492
这个错误发生在 PyTorch 的一个模块中,具体来说是在 PointNet2 的消息传递层(pointnet2_msg.py)的 forward 方法中出现了问题。根据错误信息,似乎是在输入 x 时出现了问题,导致 x 变成了 NoneType,而 NoneType 对象没有 size 属性。
可能的原因是在调用 forward 方法时传入了一个空的输入,或者是在数据处理过程中出现了问题导致输入数据为空。你可以检查一下输入数据是否正确,并且确保数据处理过程中没有出现问题。另外,你可以在代码中加入一些调试信息,以便更好地定位问题所在。
相关问题
TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/ConvNeXt/my_dataset.py", line 40, in __getitem__ img = self.transform(a) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 95, in __call__ img = t(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 952, in forward i, j, h, w = self.get_params(img, self.scale, self.ratio) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 913, in get_params width, height = F.get_image_size(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 76, in get_image_size return F_pil.get_image_size(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/functional_pil.py", line 27, in get_image_size raise TypeError(f"Unexpected type {type(img)}") TypeError: Unexpected type <class 'numpy.ndarray'>
这个错误是由于在 DataLoader 的 worker 进程中,数据集中的某个样本在进行 transform 时出现了错误。具体来说,是由于 get_image_size 函数期望的 PIL.Image 对象被传入了一个 numpy 数组。你可以检查一下数据集中的这个样本,看看是否正确加载,并且检查一下 transform 中是否使用了正确的数据类型。
raceback (most recent call last): File "train_rcnn.py", line 243, in <module> trainer.train( File "/root/autodl-tmp/project/tools/../tools/train_utils/train_utils.py", line 199, in train loss, tb_dict, disp_dict = self._train_it(batch) File "/root/autodl-tmp/project/tools/../tools/train_utils/train_utils.py", line 132, in _train_it loss, tb_dict, disp_dict = self.model_fn(self.model, batch) File "/root/autodl-tmp/project/tools/../lib/net/train_functions.py", line 35, in model_fn ret_dict = model(input_data) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/root/autodl-tmp/project/tools/../lib/net/point_rcnn.py", line 33, in forward rpn_output = self.rpn(input_data) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/root/autodl-tmp/project/tools/../lib/net/rpn.py", line 74, in forward backbone_xyz, backbone_features = self.backbone_net(pts_input) # (B, N, 3), (B, C, N) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/root/autodl-tmp/project/tools/../lib/net/pointnet2_msg.py", line 154, in forward li_xyz, li_features = self.SA_modules[i](l_xyz[i], l_features[i]) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) TypeError: forward() takes 2 positional arguments but 3 were given
这个错误是因为在调用 `forward()` 函数时给了 3 个参数,但是该函数只接受 2 个参数。可能是在调用 `self.SA_modules[i](l_xyz[i], l_features[i])` 时出现了问题。你可以检查一下该函数的定义,确保它只需要 2 个参数,并且检查一下你在调用 `forward()` 函数时是否传入了多余的参数。
阅读全文