List of commits:
Subject Hash Author Date (UTC)
add model_context_aware_network.py 2a36025c001d85afc064c090f4d22987b328977b Thai Thien 2020-02-02 03:46:38
PACNN (TODO: test this) 44d5ae7ec57c760fb4f105dd3e3492148a0cc075 Thai Thien 2020-02-02 03:40:26
add data path 80134de767d0137a663f343e4606bafc57a1bc1f Thai Thien 2020-02-02 03:38:21
test if ShanghaiTech datapath is correct 97ee84944a4393ec3732879b24f614826f8e7798 Thai Thien 2020-02-01 03:57:31
refactor and test ShanghaiTech datapath 9542ebc00f257edc38690180b7a4353794be4019 Thai Thien 2020-02-01 03:53:49
fix the unzip flow b53c5989935335377eb6a88c942713d3eccc5df7 Thai Thien 2020-02-01 03:53:13
data_script run seem ok 67420c08fc1c10a66404d3698994865726a106cd Thai Thien 2020-02-01 03:33:18
add perspective 642d6fff8c9f31e510fda85a7fb631fb855d8a6d Thai Thien 2019-10-06 16:54:44
fix padding with p 86c2fa07822d956a34b3b37e14da485a4249f01b Thai Thien 2019-10-06 02:52:58
pacnn perspective loss fb673e38a5f24ae9004fe2b7b93c88991e0c2304 Thai Thien 2019-10-06 01:38:28
data_flow shanghaitech_pacnn_with_perspective seem working 91d350a06f358e03223966297d124daee94123d0 Thai Thien 2019-10-06 01:31:11
multiscale loss and final loss only mode c65dd0e74ad28503821e5c8651a3b47b4a0c7c64 Thai Thien 2019-10-05 15:58:19
wip : perspective map eac63f2671dc5b064753acc4f40bf0f9f216ad2a Thai Thien 2019-10-04 16:26:56
shell script f2106e700b6f6174d4dd276f25ec6f3d9ff239bb thient 2019-10-04 07:42:51
WIP 42c7c8e1d772fbbda61a4bdf9e329f74e1efb600 tthien 2019-10-03 17:52:47
add readme 580cf43d1edddd67b1f6a2c57fdd5cee3dba925c Thai Thien 2019-10-02 17:44:49
update script, debug ddb68b95389be1c1d398118677dd227a8bb2b70b Thai Thien 2019-10-02 15:52:31
add d (output density map) to loss function) a0c71bf4bf2ab7393d60b06a84db8dfbbfb1a6c2 tthien 2019-09-30 16:32:39
fix the args, add save interval for model, so we don't save them all 9fdf9daa2ac4bd12b7b62521d81e520db0debd01 tthien 2019-09-30 16:30:00
meow 1ad19a22a310992e27a26471feeb37375124d075 tthien 2019-09-29 18:25:43
Commit 2a36025c001d85afc064c090f4d22987b328977b - add model_context_aware_network.py
Author: Thai Thien
Author date (UTC): 2020-02-02 03:46
Committer name: Thai Thien
Committer date (UTC): 2020-02-02 03:46
Parent(s): 44d5ae7ec57c760fb4f105dd3e3492148a0cc075
Signing key:
Tree: 6bf6ba16fee7146ae37399a16639db30e6c2c2a5
File Lines added Lines deleted
models/model_context_aware_network.py 84 0
File models/model_context_aware_network.py added (mode: 100644) (index 0000000..23c2326)
1 import torch.nn as nn
2 import torch
3 from torch.nn import functional as F
4 from torchvision import models
5
6
7 class ContextualModule(nn.Module):
8 def __init__(self, features, out_features=512, sizes=(1, 2, 3, 6)):
9 super(ContextualModule, self).__init__()
10 self.scales = []
11 self.scales = nn.ModuleList([self._make_scale(features, size) for size in sizes])
12 self.bottleneck = nn.Conv2d(features * 2, out_features, kernel_size=1)
13 self.relu = nn.ReLU()
14 self.weight_net = nn.Conv2d(features,features,kernel_size=1)
15
16 def __make_weight(self,feature,scale_feature):
17 weight_feature = feature - scale_feature
18 return F.sigmoid(self.weight_net(weight_feature))
19
20 def _make_scale(self, features, size):
21 prior = nn.AdaptiveAvgPool2d(output_size=(size, size))
22 conv = nn.Conv2d(features, features, kernel_size=1, bias=False)
23 return nn.Sequential(prior, conv)
24
25 def forward(self, feats):
26 h, w = feats.size(2), feats.size(3)
27 multi_scales = [F.upsample(input=stage(feats), size=(h, w), mode='bilinear') for stage in self.scales]
28 weights = [self.__make_weight(feats,scale_feature) for scale_feature in multi_scales]
29 overall_features = [(multi_scales[0]*weights[0]+multi_scales[1]*weights[1]+multi_scales[2]*weights[2]+multi_scales[3]*weights[3])/(weights[0]+weights[1]+weights[2]+weights[3])]+ [feats]
30 bottle = self.bottleneck(torch.cat(overall_features, 1))
31 return self.relu(bottle)
32
33
34 class CANNet(nn.Module):
35 def __init__(self, load_weights=False):
36 super(CANNet, self).__init__()
37 self.seen = 0
38 self.context = ContextualModule(512, 512)
39 self.frontend_feat = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512]
40 self.backend_feat = [512, 512, 512,256,128,64]
41 self.frontend = make_layers(self.frontend_feat)
42 self.backend = make_layers(self.backend_feat,in_channels = 512,batch_norm=True, dilation = True)
43 self.output_layer = nn.Conv2d(64, 1, kernel_size=1)
44 if not load_weights:
45 mod = models.vgg16(pretrained = True)
46 self._initialize_weights()
47 for i in range(len(self.frontend.state_dict().items())):
48 list(self.frontend.state_dict().items())[i][1].data[:] = list(mod.state_dict().items())[i][1].data[:]
49
50 def forward(self,x):
51 x = self.frontend(x)
52 x = self.context(x)
53 x = self.backend(x)
54 x = self.output_layer(x)
55 return x
56
57 def _initialize_weights(self):
58 for m in self.modules():
59 if isinstance(m, nn.Conv2d):
60 nn.init.normal_(m.weight, std=0.01)
61 if m.bias is not None:
62 nn.init.constant_(m.bias, 0)
63 elif isinstance(m, nn.BatchNorm2d):
64 nn.init.constant_(m.weight, 1)
65 nn.init.constant_(m.bias, 0)
66
67
68 def make_layers(cfg, in_channels=3, batch_norm=False, dilation=False):
69 if dilation:
70 d_rate = 2
71 else:
72 d_rate = 1
73 layers = []
74 for v in cfg:
75 if v == 'M':
76 layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
77 else:
78 conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=d_rate,dilation = d_rate)
79 if batch_norm:
80 layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)]
81 else:
82 layers += [conv2d, nn.ReLU(inplace=True)]
83 in_channels = v
84 return nn.Sequential(*layers)
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/hahattpro/crowd_counting_framework

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/hahattpro/crowd_counting_framework

Clone this repository using git:
git clone git://git.rocketgit.com/user/hahattpro/crowd_counting_framework

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main