Delete model
Browse files- model/RTFNet.py +0 -272
- model/__init__.py +0 -1
- model/image/IVF1.png +0 -3
- model/image/IVF2.png +0 -3
- model/image/MIF.png +0 -3
- model/image/MMDet.png +0 -3
- model/image/MMSeg.png +0 -3
- model/image/Quantitative_IVF.png +0 -3
- model/image/Quantitative_MIF.png +0 -3
- model/image/Workflow.png +0 -3
model/RTFNet.py
DELETED
|
@@ -1,272 +0,0 @@
|
|
| 1 |
-
# coding:utf-8
|
| 2 |
-
# By Yuxiang Sun, Aug. 2, 2019
|
| 3 |
-
# Email: sun.yuxiang@outlook.com
|
| 4 |
-
|
| 5 |
-
import torch
|
| 6 |
-
import torch.nn as nn
|
| 7 |
-
import torchvision.models as models
|
| 8 |
-
import cv2
|
| 9 |
-
import matplotlib.pyplot as plt
|
| 10 |
-
import numpy as np
|
| 11 |
-
from scipy.ndimage import gaussian_filter
|
| 12 |
-
class RTFNet(nn.Module):
|
| 13 |
-
|
| 14 |
-
def __init__(self, n_class):
|
| 15 |
-
super(RTFNet, self).__init__()
|
| 16 |
-
|
| 17 |
-
self.num_resnet_layers = 152
|
| 18 |
-
|
| 19 |
-
if self.num_resnet_layers == 18:
|
| 20 |
-
resnet_raw_model1 = models.resnet18(pretrained=True)
|
| 21 |
-
resnet_raw_model2 = models.resnet18(pretrained=True)
|
| 22 |
-
self.inplanes = 512
|
| 23 |
-
elif self.num_resnet_layers == 34:
|
| 24 |
-
resnet_raw_model1 = models.resnet34(pretrained=True)
|
| 25 |
-
resnet_raw_model2 = models.resnet34(pretrained=True)
|
| 26 |
-
self.inplanes = 512
|
| 27 |
-
elif self.num_resnet_layers == 50:
|
| 28 |
-
resnet_raw_model1 = models.resnet50(pretrained=True)
|
| 29 |
-
resnet_raw_model2 = models.resnet50(pretrained=True)
|
| 30 |
-
self.inplanes = 2048
|
| 31 |
-
elif self.num_resnet_layers == 101:
|
| 32 |
-
resnet_raw_model1 = models.resnet101(pretrained=True)
|
| 33 |
-
resnet_raw_model2 = models.resnet101(pretrained=True)
|
| 34 |
-
self.inplanes = 2048
|
| 35 |
-
elif self.num_resnet_layers == 152:
|
| 36 |
-
resnet_raw_model1 = models.resnet152(pretrained=True)
|
| 37 |
-
resnet_raw_model2 = models.resnet152(pretrained=True)
|
| 38 |
-
self.inplanes = 2048
|
| 39 |
-
|
| 40 |
-
######## Thermal ENCODER ########
|
| 41 |
-
|
| 42 |
-
self.encoder_thermal_conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False)
|
| 43 |
-
self.encoder_thermal_conv1.weight.data = torch.unsqueeze(torch.mean(resnet_raw_model1.conv1.weight.data, dim=1), dim=1)
|
| 44 |
-
self.encoder_thermal_bn1 = resnet_raw_model1.bn1
|
| 45 |
-
self.encoder_thermal_relu = resnet_raw_model1.relu
|
| 46 |
-
self.encoder_thermal_maxpool = resnet_raw_model1.maxpool
|
| 47 |
-
self.encoder_thermal_layer1 = resnet_raw_model1.layer1
|
| 48 |
-
self.encoder_thermal_layer2 = resnet_raw_model1.layer2
|
| 49 |
-
self.encoder_thermal_layer3 = resnet_raw_model1.layer3
|
| 50 |
-
self.encoder_thermal_layer4 = resnet_raw_model1.layer4
|
| 51 |
-
|
| 52 |
-
######## RGB ENCODER ########
|
| 53 |
-
|
| 54 |
-
self.encoder_rgb_conv1 = resnet_raw_model2.conv1
|
| 55 |
-
self.encoder_rgb_bn1 = resnet_raw_model2.bn1
|
| 56 |
-
self.encoder_rgb_relu = resnet_raw_model2.relu
|
| 57 |
-
self.encoder_rgb_maxpool = resnet_raw_model2.maxpool
|
| 58 |
-
self.encoder_rgb_layer1 = resnet_raw_model2.layer1
|
| 59 |
-
self.encoder_rgb_layer2 = resnet_raw_model2.layer2
|
| 60 |
-
self.encoder_rgb_layer3 = resnet_raw_model2.layer3
|
| 61 |
-
self.encoder_rgb_layer4 = resnet_raw_model2.layer4
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
######## DECODER ########
|
| 66 |
-
|
| 67 |
-
self.deconv1 = self._make_transpose_layer(TransBottleneck, self.inplanes//2, 2, stride=2) # using // for python 3.6
|
| 68 |
-
self.deconv2 = self._make_transpose_layer(TransBottleneck, self.inplanes//2, 2, stride=2) # using // for python 3.6
|
| 69 |
-
self.deconv3 = self._make_transpose_layer(TransBottleneck, self.inplanes//2, 2, stride=2) # using // for python 3.6
|
| 70 |
-
self.deconv4 = self._make_transpose_layer(TransBottleneck, self.inplanes//2, 2, stride=2) # using // for python 3.6
|
| 71 |
-
self.deconv5 = self._make_transpose_layer(TransBottleneck, n_class, 2, stride=2)
|
| 72 |
-
|
| 73 |
-
def _make_transpose_layer(self, block, planes, blocks, stride=1):
|
| 74 |
-
|
| 75 |
-
upsample = None
|
| 76 |
-
if stride != 1:
|
| 77 |
-
upsample = nn.Sequential(
|
| 78 |
-
nn.ConvTranspose2d(self.inplanes, planes, kernel_size=2, stride=stride, padding=0, bias=False),
|
| 79 |
-
nn.BatchNorm2d(planes),
|
| 80 |
-
)
|
| 81 |
-
elif self.inplanes != planes:
|
| 82 |
-
upsample = nn.Sequential(
|
| 83 |
-
nn.Conv2d(self.inplanes, planes, kernel_size=1, stride=stride, padding=0, bias=False),
|
| 84 |
-
nn.BatchNorm2d(planes),
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
for m in upsample.modules():
|
| 88 |
-
if isinstance(m, nn.ConvTranspose2d):
|
| 89 |
-
nn.init.xavier_uniform_(m.weight.data)
|
| 90 |
-
elif isinstance(m, nn.BatchNorm2d):
|
| 91 |
-
m.weight.data.fill_(1)
|
| 92 |
-
m.bias.data.zero_()
|
| 93 |
-
|
| 94 |
-
layers = []
|
| 95 |
-
|
| 96 |
-
for i in range(1, blocks):
|
| 97 |
-
layers.append(block(self.inplanes, self.inplanes))
|
| 98 |
-
|
| 99 |
-
layers.append(block(self.inplanes, planes, stride, upsample))
|
| 100 |
-
self.inplanes = planes
|
| 101 |
-
|
| 102 |
-
return nn.Sequential(*layers)
|
| 103 |
-
|
| 104 |
-
def forward(self, input):
|
| 105 |
-
|
| 106 |
-
rgb = input[:,:3]
|
| 107 |
-
thermal = input[:,3:]
|
| 108 |
-
|
| 109 |
-
verbose = False
|
| 110 |
-
|
| 111 |
-
# encoder
|
| 112 |
-
|
| 113 |
-
######################################################################
|
| 114 |
-
|
| 115 |
-
if verbose: print("rgb.size() original: ", rgb.size()) # (480, 640)
|
| 116 |
-
if verbose: print("thermal.size() original: ", thermal.size()) # (480, 640)
|
| 117 |
-
|
| 118 |
-
######################################################################
|
| 119 |
-
|
| 120 |
-
rgb = self.encoder_rgb_conv1(rgb)
|
| 121 |
-
if verbose: print("rgb.size() after conv1: ", rgb.size()) # (240, 320)
|
| 122 |
-
rgb = self.encoder_rgb_bn1(rgb)
|
| 123 |
-
if verbose: print("rgb.size() after bn1: ", rgb.size()) # (240, 320)
|
| 124 |
-
rgb = self.encoder_rgb_relu(rgb)
|
| 125 |
-
if verbose: print("rgb.size() after relu: ", rgb.size()) # (240, 320)
|
| 126 |
-
|
| 127 |
-
thermal = self.encoder_thermal_conv1(thermal)
|
| 128 |
-
if verbose: print("thermal.size() after conv1: ", thermal.size()) # (240, 320)
|
| 129 |
-
thermal = self.encoder_thermal_bn1(thermal)
|
| 130 |
-
if verbose: print("thermal.size() after bn1: ", thermal.size()) # (240, 320)
|
| 131 |
-
thermal = self.encoder_thermal_relu(thermal)
|
| 132 |
-
if verbose: print("thermal.size() after relu: ", thermal.size()) # (240, 320)
|
| 133 |
-
|
| 134 |
-
rgb = rgb + thermal
|
| 135 |
-
|
| 136 |
-
rgb = self.encoder_rgb_maxpool(rgb)
|
| 137 |
-
if verbose: print("rgb.size() after maxpool: ", rgb.size()) # (120, 160)
|
| 138 |
-
|
| 139 |
-
thermal = self.encoder_thermal_maxpool(thermal)
|
| 140 |
-
if verbose: print("thermal.size() after maxpool: ", thermal.size()) # (120, 160)
|
| 141 |
-
|
| 142 |
-
######################################################################
|
| 143 |
-
|
| 144 |
-
rgb = self.encoder_rgb_layer1(rgb)
|
| 145 |
-
if verbose: print("rgb.size() after layer1: ", rgb.size()) # (120, 160)
|
| 146 |
-
thermal = self.encoder_thermal_layer1(thermal)
|
| 147 |
-
if verbose: print("thermal.size() after layer1: ", thermal.size()) # (120, 160)
|
| 148 |
-
|
| 149 |
-
rgb = rgb + thermal
|
| 150 |
-
|
| 151 |
-
######################################################################
|
| 152 |
-
|
| 153 |
-
rgb = self.encoder_rgb_layer2(rgb)
|
| 154 |
-
if verbose: print("rgb.size() after layer2: ", rgb.size()) # (60, 80)
|
| 155 |
-
thermal = self.encoder_thermal_layer2(thermal)
|
| 156 |
-
if verbose: print("thermal.size() after layer2: ", thermal.size()) # (60, 80)
|
| 157 |
-
|
| 158 |
-
rgb = rgb + thermal
|
| 159 |
-
|
| 160 |
-
######################################################################
|
| 161 |
-
|
| 162 |
-
rgb = self.encoder_rgb_layer3(rgb)
|
| 163 |
-
if verbose: print("rgb.size() after layer3: ", rgb.size()) # (30, 40)
|
| 164 |
-
thermal = self.encoder_thermal_layer3(thermal)
|
| 165 |
-
if verbose: print("thermal.size() after layer3: ", thermal.size()) # (30, 40)
|
| 166 |
-
|
| 167 |
-
rgb = rgb + thermal
|
| 168 |
-
|
| 169 |
-
######################################################################
|
| 170 |
-
|
| 171 |
-
rgb = self.encoder_rgb_layer4(rgb)
|
| 172 |
-
if verbose: print("rgb.size() after layer4: ", rgb.size()) # (15, 20)
|
| 173 |
-
thermal = self.encoder_thermal_layer4(thermal)
|
| 174 |
-
if verbose: print("thermal.size() after layer4: ", thermal.size()) # (15, 20)
|
| 175 |
-
|
| 176 |
-
chenzeyang = thermal[0]
|
| 177 |
-
chenzeyang = torch.squeeze(chenzeyang)
|
| 178 |
-
att = chenzeyang.sum(axis=0).detach().cpu().numpy()
|
| 179 |
-
att = gaussian_filter(att, sigma=2)
|
| 180 |
-
att -= att.min()
|
| 181 |
-
att /= att.max()
|
| 182 |
-
# att1 = att.detach().cpu().numpy()
|
| 183 |
-
attmap = cv2.resize(att, (640, 480), interpolation=cv2.INTER_CUBIC)
|
| 184 |
-
attmap_uint8 = np.uint8(255 * attmap)
|
| 185 |
-
heatmap = cv2.applyColorMap(attmap_uint8, cv2.COLORMAP_JET)
|
| 186 |
-
plt.imshow(cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB))
|
| 187 |
-
# attmap = 255 - attmap.astype("uint8")
|
| 188 |
-
# plt.imshow(attmap)
|
| 189 |
-
plt.savefig("/opt/data/private/RTFNet/RTF_heatrgb_039.png")
|
| 190 |
-
plt.show()
|
| 191 |
-
#cv2.imwrite("/opt/data/private/czy/heatmap_00001D.png", heatmap)
|
| 192 |
-
chenbo = 1
|
| 193 |
-
fuse = rgb + thermal
|
| 194 |
-
|
| 195 |
-
######################################################################
|
| 196 |
-
|
| 197 |
-
# decoder
|
| 198 |
-
|
| 199 |
-
fuse = self.deconv1(fuse)
|
| 200 |
-
if verbose: print("fuse after deconv1: ", fuse.size()) # (30, 40)
|
| 201 |
-
fuse = self.deconv2(fuse)
|
| 202 |
-
if verbose: print("fuse after deconv2: ", fuse.size()) # (60, 80)
|
| 203 |
-
fuse = self.deconv3(fuse)
|
| 204 |
-
if verbose: print("fuse after deconv3: ", fuse.size()) # (120, 160)
|
| 205 |
-
fuse = self.deconv4(fuse)
|
| 206 |
-
if verbose: print("fuse after deconv4: ", fuse.size()) # (240, 320)
|
| 207 |
-
fuse = self.deconv5(fuse)
|
| 208 |
-
if verbose: print("fuse after deconv5: ", fuse.size()) # (480, 640)
|
| 209 |
-
|
| 210 |
-
return fuse
|
| 211 |
-
|
| 212 |
-
class TransBottleneck(nn.Module):
|
| 213 |
-
|
| 214 |
-
def __init__(self, inplanes, planes, stride=1, upsample=None):
|
| 215 |
-
super(TransBottleneck, self).__init__()
|
| 216 |
-
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
|
| 217 |
-
self.bn1 = nn.BatchNorm2d(planes)
|
| 218 |
-
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
|
| 219 |
-
self.bn2 = nn.BatchNorm2d(planes)
|
| 220 |
-
|
| 221 |
-
if upsample is not None and stride != 1:
|
| 222 |
-
self.conv3 = nn.ConvTranspose2d(planes, planes, kernel_size=2, stride=stride, padding=0, bias=False)
|
| 223 |
-
else:
|
| 224 |
-
self.conv3 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
|
| 225 |
-
|
| 226 |
-
self.bn3 = nn.BatchNorm2d(planes)
|
| 227 |
-
self.relu = nn.ReLU(inplace=True)
|
| 228 |
-
self.upsample = upsample
|
| 229 |
-
self.stride = stride
|
| 230 |
-
|
| 231 |
-
for m in self.modules():
|
| 232 |
-
if isinstance(m, nn.Conv2d):
|
| 233 |
-
nn.init.xavier_uniform_(m.weight.data)
|
| 234 |
-
elif isinstance(m, nn.ConvTranspose2d):
|
| 235 |
-
nn.init.xavier_uniform_(m.weight.data)
|
| 236 |
-
elif isinstance(m, nn.BatchNorm2d):
|
| 237 |
-
m.weight.data.fill_(1)
|
| 238 |
-
m.bias.data.zero_()
|
| 239 |
-
|
| 240 |
-
def forward(self, x):
|
| 241 |
-
residual = x
|
| 242 |
-
|
| 243 |
-
out = self.conv1(x)
|
| 244 |
-
out = self.bn1(out)
|
| 245 |
-
out = self.relu(out)
|
| 246 |
-
|
| 247 |
-
out = self.conv2(out)
|
| 248 |
-
out = self.bn2(out)
|
| 249 |
-
out = self.relu(out)
|
| 250 |
-
|
| 251 |
-
out = self.conv3(out)
|
| 252 |
-
out = self.bn3(out)
|
| 253 |
-
|
| 254 |
-
if self.upsample is not None:
|
| 255 |
-
residual = self.upsample(x)
|
| 256 |
-
|
| 257 |
-
out += residual
|
| 258 |
-
out = self.relu(out)
|
| 259 |
-
|
| 260 |
-
return out
|
| 261 |
-
|
| 262 |
-
def unit_test():
|
| 263 |
-
num_minibatch = 2
|
| 264 |
-
rgb = torch.randn(num_minibatch, 3, 480, 640).cuda(0)
|
| 265 |
-
thermal = torch.randn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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
from .RTFNet import RTFNet
|
|
|
|
|
|
model/image/IVF1.png
DELETED
Git LFS Details
|
model/image/IVF2.png
DELETED
Git LFS Details
|
model/image/MIF.png
DELETED
Git LFS Details
|
model/image/MMDet.png
DELETED
Git LFS Details
|
model/image/MMSeg.png
DELETED
Git LFS Details
|
model/image/Quantitative_IVF.png
DELETED
Git LFS Details
|
model/image/Quantitative_MIF.png
DELETED
Git LFS Details
|
model/image/Workflow.png
DELETED
Git LFS Details
|