I’m a newer to pytorch. I run a model by pytorch But I am getting error as ‘VoxResNet’ object has no attribute ‘to_gpu’
my model :
class VoxResNet(nn.Module):
DEPTH = 6
def __init__(self, n_classes=2):
super().__init__()
resnet = torchvision.models.resnet.resnet50(pretrained=True)
down_blocks = []
up_blocks = []
self.input_block = nn.Sequential(*list(resnet.children()))[:3]
self.input_pool = list(resnet.children())[3]
for bottleneck in list(resnet.children()):
if isinstance(bottleneck, nn.Sequential):
down_blocks.append(bottleneck)
self.down_blocks = nn.ModuleList(down_blocks)
self.bridge = Bridge(2048, 2048)
up_blocks.append(UpBlockForUNetWithResNet50(2048, 1024))
up_blocks.append(UpBlockForUNetWithResNet50(1024, 512))
up_blocks.append(UpBlockForUNetWithResNet50(512, 256))
up_blocks.append(UpBlockForUNetWithResNet50(in_channels=128 + 64, out_channels=128,
up_conv_in_channels=256, up_conv_out_channels=128))
up_blocks.append(UpBlockForUNetWithResNet50(in_channels=64 + 3, out_channels=64,
up_conv_in_channels=128, up_conv_out_channels=64))
self.up_blocks = nn.ModuleList(up_blocks)
self.out = nn.Conv2d(64, n_classes, kernel_size=1, stride=1)
def forward(self, x, with_output_feature_map=False):
pre_pools = dict()
pre_pools[f"layer_0"] = x
x = self.input_block(x)
pre_pools[f"layer_1"] = x
x = self.input_pool(x)
for i, block in enumerate(self.down_blocks, 2):
x = block(x)
if i == (VoxResNet.DEPTH - 1):
continue
pre_pools[f"layer_{i}"] = x
x = self.bridge(x)
for i, block in enumerate(self.up_blocks, 1):
key = f"layer_{VoxResNet.DEPTH - 1 - i}"
x = block(x, pre_pools[key])
output_feature_map = x
x = self.out(x)
del pre_pools
if with_output_feature_map:
return x, output_feature_map
else:
return x
model = VoxResNet().cuda()
inp = torch.rand((2, 3, 512, 512)).cuda()
out = model(inp)
error :
Traceback (most recent call last):
File "train.py", line 169, in <module>
main()
File "train.py", line 90, in main
vrn.to_gpu()
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 591, in __getattr__
type(self).__name__, name))
AttributeError: 'VoxResNet' object has no attribute 'to_gpu'