@@ -2,6 +2,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
+import numpy as np
from collections import OrderedDict
from .basic import _ConvBNReLU, SeparableConv2d, _ConvBN, _BNPReLU, _ConvBNPReLU
@@ -82,16 +83,34 @@ class _ASPP(nn.Module):
class PyramidPooling(nn.Module):
def __init__(self, in_channels, sizes=(1, 2, 3, 6), norm_layer=nn.BatchNorm2d, **kwargs):
super(PyramidPooling, self).__init__()
- out_channels = int(in_channels / 4)
self.avgpools = nn.ModuleList()
self.convs = nn.ModuleList()
+ self.out_channels = int(in_channels / 4)
+ self.in_channels = in_channels
+ self.sizes = sizes
+ self.norm_layer = norm_layer
+ out_channels = self.out_channels
for size in sizes:
- self.avgpools.append(nn.AdaptiveAvgPool2d(size))
+ # inputsz = np.array(input.shape[2:])
+ # outputsz = np.array([bin_size, bin_size])
+ # stridesz = np.floor(inputsz / outputsz).astype(np.int32)
+ # kernelsz = inputsz - (outputsz - 1) * stridesz
+ # self.avgpools.append(nn.AdaptiveAvgPool2d(size))
self.convs.append(_ConvBNReLU(in_channels, out_channels, 1, norm_layer=norm_layer, **kwargs))
def forward(self, x):
size = x.size()[2:]
feats = [x]
+ # out_channels = self.out_channels
+ # self.avgpools = nn.ModuleList()
+
+ for bin_size in self.sizes:
+ inputsz = np.array(x.shape[2:])
+ outputsz = np.array([bin_size, bin_size])
+ stridesz = np.floor(inputsz / outputsz).astype(np.int32)
+ kernelsz = inputsz - (outputsz - 1) * stridesz
+ self.avgpools.append(nn.AvgPool2d(kernel_size=list(kernelsz), stride=list(stridesz)))
+
for (avgpool, conv) in zip(self.avgpools, self.convs):
feats.append(F.interpolate(conv(avgpool(x)), size, mode='bilinear', align_corners=True))
return torch.cat(feats, dim=1)
@@ -21,9 +21,26 @@ def parse_args():
# for visual
parser.add_argument('--input-img', type=str, default='tools/demo_vis.png',
help='path to the input image or a directory of images')
+ parser.add_argument('--pth_path',type=str, help='path of pth model',
+ default='best_model.pth')
+ parser.add_argument('--batch_size', type=int, help='batchsize of pth model ',
+ default=1)
+ parser.add_argument('--onnx_name', type=str, default= 'fast_scnn_bs1',
+ help='name of onnx model')
# config options
parser.add_argument('opts', help='See config for all options',
default=None, nargs=argparse.REMAINDER)
+ parser.add_argument('--datasets_input_path', default='/opt/npu/datasets/cityscapes',
+ help='the path of the datasets to preprocess')
+ parser.add_argument('--datasets_output_path', default='/opt/npu/prep_datasets',
+ help='the path of the datasets after preprocess')
+ parser.add_argument('--result_bin_root', default='/home/user_dir/FastSCNN/result/bs1',
+ help='the path of the inference results')
+
+ parser.add_argument('--label_bin_root', default='/opt/npu/prep_datasets/gtFine/',
+ help='the path of the labels corresponding to the inference results')
+
+ parser.add_argument('--sort_log', default='/home/agc/FastSCNN/sort.log')
args = parser.parse_args()
return args
\ No newline at end of file
--
2.17.1