Skip to content

Commit

Permalink
dlv3 update with bilinear upsample
Browse files Browse the repository at this point in the history
Signed-off-by: Bharath Ramaswamy <quic_bharathr@quicinc.com>
  • Loading branch information
quic-bharathr committed Jan 25, 2021
1 parent 2163cd4 commit 2cacf5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ An original FP32 source model is quantized either using post-training quantizati
<td><a href="https://github.com/jfzhang95/pytorch-deeplab-xception">GitHub Repo</a></td>
<td><a href="https://drive.google.com/file/d/1G9mWafUAj09P4KvGSRVzIsV_U5OqFLdt/view">Pretrained Model</a></td>
<td><a href="/../../releases/download/DeepLabV3-Torch/dlv3+_qat_renamed.tar.gz">Quantized Model</a></td>
<td>(PascalVOC) mIOU <br>FP32: 72.32%<br> INT8: 72.08%</a></td>
<td>(PascalVOC) mIOU <br>FP32: 72.62%<br> INT8: 72.22%</a></td>
<td><a href="zoo_torch/Docs/DeepLabV3.md">DeepLabV3.md</a></td>
</tr>
<tr>
Expand Down
40 changes: 27 additions & 13 deletions zoo_torch/examples/pytorch-deeplab-xception-zoo.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
diff --git a/modeling/aspp.py b/modeling/aspp.py
index 5a97879..770e60f 100644
index 5a97879..e37ef0f 100644
--- a/modeling/aspp.py
+++ b/modeling/aspp.py
@@ -68,7 +68,7 @@ class ASPP(nn.Module):
@@ -68,7 +68,11 @@ class ASPP(nn.Module):
x3 = self.aspp3(x)
x4 = self.aspp4(x)
x5 = self.global_avg_pool(x)
- x5 = F.interpolate(x5, size=x4.size()[2:], mode='bilinear', align_corners=True)
+ x5 = F.interpolate(x5, size=x4.size()[2:], mode='nearest', align_corners=None)
+ # x5 = F.interpolate(x5, size=x4.size()[2:], mode='nearest', align_corners=None)
+ # x5 = F.interpolate(x5, size=x4.size()[2:], mode='bilinear', align_corners=True)
+ # x5 = F.upsample(x5, size=(33, 33), mode='nearest', align_corners=None)
+ x5 = F.upsample(x5, size=(33, 33), mode='bilinear', align_corners=None)
+
x = torch.cat((x1, x2, x3, x4, x5), dim=1)

x = self.conv1(x)
diff --git a/modeling/backbone/mobilenet.py b/modeling/backbone/mobilenet.py
index 6fff541..9edce54 100644
index 6fff541..4821d39 100644
--- a/modeling/backbone/mobilenet.py
+++ b/modeling/backbone/mobilenet.py
@@ -5,22 +5,21 @@ import math
Expand Down Expand Up @@ -124,11 +128,13 @@ index 6fff541..9edce54 100644
+ # self.features = nn.Sequential(*self.features)
self._initialize_weights()

- if pretrained:
- self._load_pretrained_model()
+
+ # self.low_level_features = self.features[0:4]
+ # self.high_level_features = self.features[4:]
if pretrained:
self._load_pretrained_model()
+ # if pretrained:
+ # self._load_pretrained_model()
+ self.low_level_features = nn.Sequential(*features[0:4])

- self.low_level_features = self.features[0:4]
Expand All @@ -149,28 +155,36 @@ index 6fff541..9edce54 100644
input = torch.rand(1, 3, 512, 512)
model = MobileNetV2(output_stride=16, BatchNorm=nn.BatchNorm2d)
diff --git a/modeling/decoder.py b/modeling/decoder.py
index 5ed41d0..ec4485e 100644
index 5ed41d0..32eb7a5 100644
--- a/modeling/decoder.py
+++ b/modeling/decoder.py
@@ -36,7 +36,7 @@ class Decoder(nn.Module):
@@ -36,7 +36,10 @@ class Decoder(nn.Module):
low_level_feat = self.bn1(low_level_feat)
low_level_feat = self.relu(low_level_feat)

- x = F.interpolate(x, size=low_level_feat.size()[2:], mode='bilinear', align_corners=True)
+ x = F.interpolate(x, size=low_level_feat.size()[2:], mode='nearest', align_corners=None)
+ # x = F.interpolate(x, size=low_level_feat.size()[2:], mode='nearest', align_corners=None)
+ # x = F.interpolate(x, size=low_level_feat.size()[2:], mode='bilinear', align_corners=True)
+ # x = F.upsample(x, size=(129, 129), mode='nearest', align_corners=None)
+ x = F.upsample(x, size=(129, 129), mode='bilinear', align_corners=None)
x = torch.cat((x, low_level_feat), dim=1)
x = self.last_conv(x)

diff --git a/modeling/deeplab.py b/modeling/deeplab.py
index 91907f8..8308934 100644
index 91907f8..cbf05a2 100644
--- a/modeling/deeplab.py
+++ b/modeling/deeplab.py
@@ -28,7 +28,7 @@ class DeepLab(nn.Module):
@@ -28,8 +28,11 @@ class DeepLab(nn.Module):
x, low_level_feat = self.backbone(input)
x = self.aspp(x)
x = self.decoder(x, low_level_feat)
- x = F.interpolate(x, size=input.size()[2:], mode='bilinear', align_corners=True)
+ x = F.interpolate(x, size=input.size()[2:], mode='nearest', align_corners=None)

-
+ # x = F.interpolate(x, size=input.size()[2:], mode='nearest', align_corners=None)
+ # x = F.interpolate(x, size=input.size()[2:], mode='bilinear', align_corners=True)
+
+ # x = F.upsample(x, size=(513, 513), mode='nearest', align_corners=None)
+ x = F.upsample(x, size=(513, 513), mode='bilinear', align_corners=None)
return x

def freeze_bn(self):

0 comments on commit 2cacf5c

Please sign in to comment.