From f415df3448622f30c3d1eb680596871672b38dac Mon Sep 17 00:00:00 2001
From: natanielruiz <nataniel777@hotmail.com>
Date: 星期四, 26 十月 2017 02:51:37 +0800
Subject: [PATCH] after fg

---
 code/hopenet.py |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/code/hopenet.py b/code/hopenet.py
index b2dd097..80160d9 100644
--- a/code/hopenet.py
+++ b/code/hopenet.py
@@ -339,13 +339,13 @@
         preangles = torch.cat([yaw, pitch, roll], 1)
         angles.append(preangles)
 
-        return pre_yaw, pre_pitch, pre_roll, angles, sr_output
+        return pre_yaw, pre_pitch, pre_roll, angles, sr_y
 
-class Hopenet_LSTM(nn.Module):
+class Hopenet_new(nn.Module):
     # This is just Hopenet with 3 output layers for yaw, pitch and roll.
     def __init__(self, block, layers, num_bins):
         self.inplanes = 64
-        super(Hopenet_LSTM, self).__init__()
+        super(Hopenet_new, self).__init__()
         self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                                bias=False)
         self.bn1 = nn.BatchNorm2d(64)
@@ -361,14 +361,11 @@
         self.fc_roll = nn.Linear(512 * block.expansion, num_bins)
 
         self.softmax = nn.Softmax()
-        self.fc_finetune = nn.Linear(512 * block.expansion + 3, 3)
+        self.fc_finetune_new = nn.Linear(512 * block.expansion + 256 * block.expansion + 3, 3)
+        self.conv1x1 = nn.Conv2d(1024, 64, kernel_size = 1, stride = 1, bias=False)
+        self.maxpool_interm = nn.MaxPool2d(kernel_size=5, stride=3, padding=1)
 
         self.idx_tensor = Variable(torch.FloatTensor(range(66))).cuda()
-
-        self.lstm = nn.LSTM(512 * block.expansion + 3, 256 * block.expansion, 2, batch_first=True)
-        self.fc_lstm = nn.Linear(256 * block.expansion, 3)
-
-        self.block_expansion = block.expansion
 
         for m in self.modules():
             if isinstance(m, nn.Conv2d):
@@ -396,7 +393,6 @@
         return nn.Sequential(*layers)
 
     def forward(self, x):
-
         x = self.conv1(x)
         x = self.bn1(x)
         x = self.relu(x)
@@ -405,6 +401,11 @@
         x = self.layer1(x)
         x = self.layer2(x)
         x = self.layer3(x)
+        x_interm = self.conv1x1(x)
+        x_interm = self.relu(x_interm)
+        x_interm = self.maxpool_interm(x_interm)
+        x_interm = x_interm.view(x_interm.size(0), -1)
+
         x = self.layer4(x)
 
         x = self.avgpool(x)
@@ -413,7 +414,6 @@
         pre_pitch = self.fc_pitch(x)
         pre_roll = self.fc_roll(x)
 
-        # Yaw, pitch, roll
         yaw = self.softmax(pre_yaw)
         yaw = Variable(torch.sum(yaw.data * self.idx_tensor.data, 1), requires_grad=True) * 3 - 99
         pitch = self.softmax(pre_pitch)
@@ -425,8 +425,8 @@
         roll = roll.view(roll.size(0), 1)
         preangles = torch.cat([yaw, pitch, roll], 1)
 
-        residuals, _ = self.lstm(torch.cat((preangles, x), 1), (h0, c0))
-        residuals = self.fc_lstm(residuals[:, -1, :])
+        # angles predicts the residual
+        residuals = self.fc_finetune_new(torch.cat((preangles, x_interm, x), 1))
         final_angles = preangles + residuals
 
         return pre_yaw, pre_pitch, pre_roll, preangles, final_angles

--
Gitblit v1.8.0