def forward(self, pointcloud: torch.cuda.FloatTensor): xyz, features = self._break_up_pc(pointcloud) l_xyz, l_features = [xyz], [features] channel_out = None for i in range(len(self.SA_modules)): li_xyz, li_features = self.SA_modules[i][0](l_xyz[i], l_features[i]) l_xyz.append(li_xyz) l_features.append(li_features) l_features[i] = self.SA_modules[i][1](l_features[i]) #SelfAttention模块需要传入的参数为输入特征向量l_features[i] for i in range(-1, -(len(self.FP_modules) + 1), -1): l_features[i - 1] = self.FP_modules[i]( l_xyz[i - 1], l_xyz[i], l_features[i - 1], l_features[i] ) return l_xyz[0], l_features[0]为什么self.SA_modules[i][1](l_features[i])中的l_features[i]被提示为空
时间: 2023-06-27 15:07:51 浏览: 79
根据代码,`l_features`是一个列表,包含了每个SA模块的输出特征向量,而在`self.SA_modules[i][1](l_features[i])`中,`l_features[i]`所代表的是第i个SA模块的输出特征向量,但在循环的第一次迭代中,`l_features[i]`的值没有被更新,因此会提示为空。可以在循环开始前先将`l_features`的第一个元素设为`features`,即可避免这个问题,例如:
```
l_xyz, l_features = [xyz], [features]
channel_out = None
# 先将第一个特征向量加入列表
l_features.append(self.SA_modules[0][1](features))
for i in range(1, len(self.SA_modules)):
li_xyz, li_features = self.SA_modules[i][0](l_xyz[i-1], l_features[i-1])
l_xyz.append(li_xyz)
l_features.append(li_features)
l_features[i] = self.SA_modules[i][1](l_features[i])
for i in range(-1, -(len(self.FP_modules) + 1), -1):
l_features[i - 1] = self.FP_modules[i](
l_xyz[i - 1], l_xyz[i], l_features[i - 1], l_features[i]
)
return l_xyz[0], l_features[0]
```
阅读全文