refinenet.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 Copyright (c) 2019-present NAVER Corp.
4 MIT License
5 """
6 
7 from __future__ import absolute_import
8 
9 import torch
10 import torch.nn as nn
11 
12 from craft.basenet.vgg16_bn import init_weights
13 
14 
15 class RefineNet(nn.Module):
16  def __init__(self):
17  super(RefineNet, self).__init__()
18 
19  self.last_conv = nn.Sequential(
20  nn.Conv2d(34, 64, kernel_size=3, padding=1), nn.BatchNorm2d(64),
21  nn.ReLU(inplace=True),
22  nn.Conv2d(64, 64, kernel_size=3, padding=1), nn.BatchNorm2d(64),
23  nn.ReLU(inplace=True),
24  nn.Conv2d(64, 64, kernel_size=3, padding=1), nn.BatchNorm2d(64),
25  nn.ReLU(inplace=True)
26  )
27 
28  self.aspp1 = nn.Sequential(
29  nn.Conv2d(64, 128, kernel_size=3, dilation=6, padding=6),
30  nn.BatchNorm2d(128), nn.ReLU(inplace=True),
31  nn.Conv2d(128, 128, kernel_size=1), nn.BatchNorm2d(128),
32  nn.ReLU(inplace=True),
33  nn.Conv2d(128, 1, kernel_size=1)
34  )
35 
36  self.aspp2 = nn.Sequential(
37  nn.Conv2d(64, 128, kernel_size=3, dilation=12, padding=12),
38  nn.BatchNorm2d(128), nn.ReLU(inplace=True),
39  nn.Conv2d(128, 128, kernel_size=1), nn.BatchNorm2d(128),
40  nn.ReLU(inplace=True),
41  nn.Conv2d(128, 1, kernel_size=1)
42  )
43 
44  self.aspp3 = nn.Sequential(
45  nn.Conv2d(64, 128, kernel_size=3, dilation=18, padding=18),
46  nn.BatchNorm2d(128), nn.ReLU(inplace=True),
47  nn.Conv2d(128, 128, kernel_size=1), nn.BatchNorm2d(128),
48  nn.ReLU(inplace=True),
49  nn.Conv2d(128, 1, kernel_size=1)
50  )
51 
52  self.aspp4 = nn.Sequential(
53  nn.Conv2d(64, 128, kernel_size=3, dilation=24, padding=24),
54  nn.BatchNorm2d(128), nn.ReLU(inplace=True),
55  nn.Conv2d(128, 128, kernel_size=1), nn.BatchNorm2d(128),
56  nn.ReLU(inplace=True),
57  nn.Conv2d(128, 1, kernel_size=1)
58  )
59 
60  init_weights(self.last_conv.modules())
61  init_weights(self.aspp1.modules())
62  init_weights(self.aspp2.modules())
63  init_weights(self.aspp3.modules())
64  init_weights(self.aspp4.modules())
65 
66  def forward(self, y, upconv4):
67  refine = torch.cat([y.permute(0, 3, 1, 2), upconv4], dim=1)
68  refine = self.last_conv(refine)
69 
70  aspp1 = self.aspp1(refine)
71  aspp2 = self.aspp2(refine)
72  aspp3 = self.aspp3(refine)
73  aspp4 = self.aspp4(refine)
74 
75  # out = torch.add([aspp1, aspp2, aspp3, aspp4], dim=1)
76  out = aspp1 + aspp2 + aspp3 + aspp4
77  return out.permute(0, 2, 3, 1) # , refine.permute(0,2,3,1)
node_scripts.craft.refinenet.RefineNet.aspp2
aspp2
Definition: refinenet.py:36
node_scripts.craft.refinenet.RefineNet.forward
def forward(self, y, upconv4)
Definition: refinenet.py:66
node_scripts.craft.refinenet.RefineNet.__init__
def __init__(self)
Definition: refinenet.py:16
node_scripts.craft.refinenet.RefineNet.aspp1
aspp1
Definition: refinenet.py:28
node_scripts.craft.refinenet.RefineNet.aspp4
aspp4
Definition: refinenet.py:52
node_scripts.craft.refinenet.RefineNet.last_conv
last_conv
Definition: refinenet.py:19
node_scripts.craft.refinenet.RefineNet.aspp3
aspp3
Definition: refinenet.py:44
node_scripts.craft.basenet.vgg16_bn.init_weights
def init_weights(modules)
Definition: vgg16_bn.py:10
node_scripts.craft.refinenet.RefineNet
Definition: refinenet.py:15


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17