From d285712b1c0a3e0785a4e5b17debdde650a7c26a Mon Sep 17 00:00:00 2001
From: natanielruiz <nataniel777@hotmail.com>
Date: 星期三, 13 九月 2017 21:34:38 +0800
Subject: [PATCH] Removed hourglass

---
 /dev/null                                                  |  194 ------------------------------------------------
 practice/.ipynb_checkpoints/smoothing_ypr-checkpoint.ipynb |   26 +++---
 practice/smoothing_ypr.ipynb                               |   10 +-
 3 files changed, 18 insertions(+), 212 deletions(-)

diff --git a/code/hg-hopenet.py b/code/hg-hopenet.py
deleted file mode 100644
index 12476cd..0000000
--- a/code/hg-hopenet.py
+++ /dev/null
@@ -1,194 +0,0 @@
-'''
-Modified from https://github.com/bearpaw/pytorch-pose
-'''
-
-import torch.nn as nn
-import torch.nn.functional as F
-import math
-# from .preresnet import BasicBlock, Bottleneck
-
-__all__ = ['HourglassNet', 'hg1', 'hg2', 'hg4', 'hg8']
-
-class Bottleneck(nn.Module):
-    expansion = 2
-
-    def __init__(self, inplanes, planes, stride=1, downsample=None):
-        super(Bottleneck, self).__init__()
-        self.bn1 = nn.BatchNorm2d(inplanes)
-        self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=True)
-        self.bn2 = nn.BatchNorm2d(planes)
-        self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
-                               padding=1, bias=True)
-        self.bn3 = nn.BatchNorm2d(planes)
-        self.conv3 = nn.Conv2d(planes, planes * 2, kernel_size=1, bias=True)
-        self.relu = nn.ReLU(inplace=True)
-        self.downsample = downsample
-        self.stride = stride
-
-    def forward(self, x):
-        residual = x
-
-        out = self.bn1(x)
-        out = self.relu(out)
-        out = self.conv1(out)
-
-        out = self.bn2(out)
-        out = self.relu(out)
-        out = self.conv2(out)
-
-        out = self.bn3(out)
-        out = self.relu(out)
-        out = self.conv3(out)
-
-        if self.downsample is not None:
-            residual = self.downsample(x)
-
-        out += residual
-
-        return out
-
-class Hourglass(nn.Module):
-    def __init__(self, block, num_blocks, planes, depth):
-        super(Hourglass, self).__init__()
-        self.depth = depth
-        self.block = block
-        self.upsample = nn.UpsamplingNearest2d(scale_factor=2)
-        self.hg = self._make_hour_glass(block, num_blocks, planes, depth)
-
-    def _make_residual(self, block, num_blocks, planes):
-        layers = []
-        for i in range(0, num_blocks):
-            layers.append(block(planes*block.expansion, planes))
-        # the splat * operator gives: [[1,2], [2]] -> ([1,2], [2])
-        return nn.Sequential(*layers)
-
-    def _make_hour_glass(self, block, num_blocks, planes, depth):
-        hg = []
-        for i in range(depth):
-            res = []
-            for j in range(3):
-                res.append(self._make_residual(block, num_blocks, planes))
-            if i == 0:
-                res.append(self._make_residual(block, num_blocks, planes))
-            # ModuleList acts like a list
-            hg.append(nn.ModuleList(res))
-        return nn.ModuleList(hg)
-
-
-    def _hour_glass_forward(self, n, x):
-        up1 = self.hg[n-1][0](x)
-        low1 = F.max_pool2d(x, 2, stride=2)
-        low1 = self.hg[n-1][1](low1)
-
-        if n > 1:
-            low2 = self._hour_glass_forward(n-1, low1)
-        else:
-            low2 = self.hg[n-1][3](low1)
-        low3 = self.hg[n-1][2](low2)
-        up2 = self.upsample(low3)
-        out = up1 + up2
-        return out
-
-    def forward(self, x):
-        return self._hour_glass_forward(self.depth, x)
-
-
-class HourglassNet(nn.Module):
-    '''Hourglass model from Newell et al ECCV 2016'''
-    def __init__(self, block, num_stacks=2, num_blocks=4, num_classes=16):
-        super(HourglassNet, self).__init__()
-
-        self.inplanes = 64
-        self.num_feats = 128
-        self.num_stacks = num_stacks
-        self.conv1 = nn.Conv2d(3, self.inplanes, kernel_size=7, stride=2, padding=3,
-                               bias=True)
-        self.bn1 = nn.BatchNorm2d(self.inplanes)
-        self.relu = nn.ReLU(inplace=True)
-        self.layer1 = self._make_residual(block, self.inplanes, 1)
-        self.layer2 = self._make_residual(block, self.inplanes, 1)
-        self.layer3 = self._make_residual(block, self.num_feats, 1)
-        self.maxpool = nn.MaxPool2d(2, stride=2)
-
-        # build hourglass modules
-        ch = self.num_feats*block.expansion
-        hg, res, fc, score, fc_, score_ = [], [], [], [], [], []
-        for i in range(num_stacks):
-            hg.append(Hourglass(block, num_blocks, self.num_feats, 4))
-            res.append(self._make_residual(block, self.num_feats, num_blocks))
-            fc.append(self._make_fc(ch, ch))
-            score.append(nn.Conv2d(ch, num_classes, kernel_size=1, bias=True))
-            if i < num_stacks-1:
-                fc_.append(nn.Conv2d(ch, ch, kernel_size=1, bias=True))
-                score_.append(nn.Conv2d(num_classes, ch, kernel_size=1, bias=True))
-        self.hg = nn.ModuleList(hg)
-        self.res = nn.ModuleList(res)
-        self.fc = nn.ModuleList(fc)
-        self.score = nn.ModuleList(score)
-        self.fc_ = nn.ModuleList(fc_)
-        self.score_ = nn.ModuleList(score_)
-
-    def _make_residual(self, block, planes, blocks, stride=1):
-        downsample = None
-        if stride != 1 or self.inplanes != planes * block.expansion:
-            downsample = nn.Sequential(
-                nn.Conv2d(self.inplanes, planes * block.expansion,
-                          kernel_size=1, stride=stride, bias=True),
-            )
-
-        layers = []
-        layers.append(block(self.inplanes, planes, stride, downsample))
-        self.inplanes = planes * block.expansion
-        for i in range(1, blocks):
-            layers.append(block(self.inplanes, planes))
-
-        return nn.Sequential(*layers)
-
-    def _make_fc(self, inplanes, outplanes):
-        bn = nn.BatchNorm2d(inplanes)
-        conv = nn.Conv2d(inplanes, outplanes, kernel_size=1, bias=True)
-        return nn.Sequential(
-                conv,
-                bn,
-                self.relu,
-            )
-
-    def forward(self, x):
-        out = []
-        x = self.conv1(x)
-        x = self.bn1(x)
-        x = self.relu(x)
-
-        x = self.layer1(x)
-        x = self.maxpool(x)
-        x = self.layer2(x)
-        x = self.layer3(x)
-
-        for i in range(self.num_stacks):
-            y = self.hg[i](x)
-            y = self.res[i](y)
-            y = self.fc[i](y)
-            score = self.score[i](y)
-            out.append(score)
-            if i < self.num_stacks-1:
-                fc_ = self.fc_[i](y)
-                score_ = self.score_[i](score)
-                x = x + fc_ + score_
-
-        return out
-
-def hg1(**kwargs):
-    model = HourglassNet(Bottleneck, num_stacks=1, num_blocks=8, **kwargs)
-    return model
-
-def hg2(**kwargs):
-    model = HourglassNet(Bottleneck, num_stacks=2, num_blocks=4, **kwargs)
-    return model
-
-def hg4(**kwargs):
-    model = HourglassNet(Bottleneck, num_stacks=4, num_blocks=2, **kwargs)
-    return model
-
-def hg8(**kwargs):
-    model = HourglassNet(Bottleneck, num_stacks=8, num_blocks=1, **kwargs)
-    return model
diff --git a/practice/.ipynb_checkpoints/smoothing_ypr-checkpoint.ipynb b/practice/.ipynb_checkpoints/smoothing_ypr-checkpoint.ipynb
index 8102abf..cd62e38 100644
--- a/practice/.ipynb_checkpoints/smoothing_ypr-checkpoint.ipynb
+++ b/practice/.ipynb_checkpoints/smoothing_ypr-checkpoint.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 187,
+   "execution_count": 1,
    "metadata": {
     "collapsed": false
    },
@@ -17,22 +17,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 188,
+   "execution_count": 2,
    "metadata": {
     "collapsed": false
    },
    "outputs": [],
    "source": [
-    "video_path = '../data/video/SGT036_2016_07_25_pivothead_AVI.avi'\n",
-    "bbox_path = '../data/video/annotations/SGT036_childface.txt'\n",
+    "video_path = '../data/video/SWC016_2016_04_08_pivothead_AVI.avi'\n",
+    "bbox_path = '../data/video/annotations/SWC016_childface.txt'\n",
     "\n",
-    "annot_path = '../output/video/output-SGT036_resnet50_lowlr_epoch_20.txt'\n",
-    "output_string = 'SGT036_resnet50_lowlr_epoch_20_smoothed'"
+    "annot_path = '../output/video/output-SWC016_normal_1e-5_epoch_20.txt'\n",
+    "output_string = 'SWC016_normal_1e-5_epoch_20_smooth'"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 189,
+   "execution_count": 3,
    "metadata": {
     "collapsed": false
    },
@@ -41,9 +41,9 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[ 4.170376  0.790443 -0.178368 ..., -3.437805  0.396835 -1.276176]\n",
-      "(8508,)\n",
-      "(53464,)\n"
+      "[ -1.15884  -14.885593 -16.727406 ..., -57.590378 -56.963156 -58.641377]\n",
+      "(9322,)\n",
+      "(63691,)\n"
      ]
     }
    ],
@@ -93,7 +93,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 190,
+   "execution_count": 4,
    "metadata": {
     "collapsed": false
    },
@@ -107,7 +107,7 @@
     }
    ],
    "source": [
-    "window_len = 5\n",
+    "window_len = 7\n",
     "pad = window_len / 2\n",
     "window = 'flat'\n",
     "window_2 = 'flat'\n",
@@ -159,7 +159,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 191,
+   "execution_count": 7,
    "metadata": {
     "collapsed": false
    },
diff --git a/practice/smoothing_ypr.ipynb b/practice/smoothing_ypr.ipynb
index 731b91f..cd62e38 100644
--- a/practice/smoothing_ypr.ipynb
+++ b/practice/smoothing_ypr.ipynb
@@ -26,8 +26,8 @@
     "video_path = '../data/video/SWC016_2016_04_08_pivothead_AVI.avi'\n",
     "bbox_path = '../data/video/annotations/SWC016_childface.txt'\n",
     "\n",
-    "annot_path = '../output/video/output-SWC016_resnet50_lowlr_epoch_20.txt'\n",
-    "output_string = 'SWC016_resnet50_lowlr_epoch_20_smoothed'"
+    "annot_path = '../output/video/output-SWC016_normal_1e-5_epoch_20.txt'\n",
+    "output_string = 'SWC016_normal_1e-5_epoch_20_smooth'"
    ]
   },
   {
@@ -41,8 +41,8 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[ 4.870468 -2.072102 -6.589153 ..., -4.716797 -2.319111 -3.147715]\n",
-      "(8967,)\n",
+      "[ -1.15884  -14.885593 -16.727406 ..., -57.590378 -56.963156 -58.641377]\n",
+      "(9322,)\n",
       "(63691,)\n"
      ]
     }
@@ -159,7 +159,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 7,
    "metadata": {
     "collapsed": false
    },

--
Gitblit v1.8.0