Skip to content

Commit

Permalink
fine tune on alexnet
Browse files Browse the repository at this point in the history
  • Loading branch information
panthersuper committed Dec 1, 2017
1 parent c755fb6 commit b728266
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
data/*
data/*
recon0/*
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@


# Dataset Parameters
load_size =128
fine_size = 113
load_size =256
fine_size = 224
data_mean = np.asarray([0,0,0,0])
batch_size = 3
batch_size = 8
voxel_size = 256

# Training Parameters
learning_rate = 0.01
learning_rate = 0.1
training_epoches = 10
step_display = 100
step_save = 2
Expand Down Expand Up @@ -113,6 +113,7 @@ def weights_init(m):
# inputs, labels = Variable(inputs), Variable(labels)
inputs, labels= Variable(inputs.cuda()), Variable(labels.cuda())


# zero the parameter gradients
optimizer.zero_grad()

Expand Down
Binary file added model/__pycache__/alexnet.cpython-36.pyc
Binary file not shown.
Binary file modified model/__pycache__/reconNet.cpython-36.pyc
Binary file not shown.
58 changes: 58 additions & 0 deletions model/alexnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import torch.nn as nn
import torch.utils.model_zoo as model_zoo


__all__ = ['AlexNet', 'alexnet']


model_urls = {
'alexnet': 'https://download.pytorch.org/models/alexnet-owt-4df8aa71.pth',
}


class AlexNet(nn.Module):

def __init__(self, num_classes=1000):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(64, 192, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(192, 384, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(384, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
)
self.classifier = nn.Sequential(
nn.Dropout(),
nn.Linear(256 * 6 * 6, 4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(4096, 4096),
nn.ReLU(inplace=True),
nn.Linear(4096, num_classes),
)

def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 256 * 6 * 6)
# x = self.classifier(x)
return x


def alex_net(pretrained=False, **kwargs):
r"""AlexNet model architecture from the
`"One weird trick..." <https://arxiv.org/abs/1404.5997>`_ paper.
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
"""
model = AlexNet(**kwargs)
if pretrained:
model.load_state_dict(model_zoo.load_url(model_urls['alexnet']))
return model
30 changes: 7 additions & 23 deletions model/reconNet.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
import torch.nn as nn

import sys, os
sys.path.append('model/')

from alexnet import alex_net

class ReconNet(nn.Module):

def __init__(self):
super(ReconNet, self).__init__()
self.features = nn.Sequential( # imput 113*113 image
# encoding process
nn.Conv2d(3, 64, kernel_size=5, stride=2, padding=2),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(64, 192, kernel_size=5, padding=2),
nn.BatchNorm2d(192),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(192, 384, kernel_size=3, padding=1),
nn.BatchNorm2d(384),
nn.ReLU(inplace=True),
nn.Conv2d(384, 256, kernel_size=3, padding=1),
nn.BatchNorm2d(256),
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1),
nn.BatchNorm2d(256),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
)

self.features = alex_net(pretrained=True)

self.latentV = nn.Sequential(
nn.Dropout(),
Expand Down Expand Up @@ -66,7 +50,7 @@ def __init__(self):

def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 256 * 6 * 6)
# x = x.view(x.size(0), 256 * 6 * 6)
x = self.latentV(x) # latent vector, size:4096
x = x.view(x.size(0),512,2,2,2) # reshape to 2 by 2 by 2 cube with 512 channels
x = self.decoding(x) # convert to 3D voxel distribution
Expand Down
98 changes: 98 additions & 0 deletions recon0/log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
PLACES TRAINING Epoch: 1 100 loss: 0.054
PLACES TRAINING Epoch: 1 200 loss: 0.049
PLACES TRAINING Epoch: 1 300 loss: 0.054
PLACES TRAINING Epoch: 1 400 loss: 0.052
PLACES TRAINING Epoch: 1 500 loss: 0.057
PLACES TRAINING Epoch: 1 600 loss: 0.052
PLACES TRAINING Epoch: 1 700 loss: 0.048
PLACES TRAINING Epoch: 1 800 loss: 0.049
PLACES TRAINING Epoch: 1 900 loss: 0.056
PLACES TRAINING Epoch: 1 1000 loss: 0.053
PLACES TRAINING Epoch: 1 1100 loss: 0.056
PLACES TRAINING Epoch: 1 1200 loss: 0.052
PLACES TRAINING Epoch: 1 1300 loss: 0.051
PLACES TRAINING Epoch: 1 1400 loss: 0.057
PLACES TRAINING Epoch: 1 1500 loss: 0.052
PLACES TRAINING Epoch: 1 1600 loss: 0.056
PLACES TRAINING Epoch: 1 1700 loss: 0.053
PLACES TRAINING Epoch: 1 1800 loss: 0.054
PLACES TRAINING Epoch: 1 1900 loss: 0.056
PLACES TRAINING Epoch: 1 2000 loss: 0.062
PLACES TRAINING Epoch: 1 2100 loss: 0.055
PLACES TRAINING Epoch: 1 2200 loss: 0.056
PLACES TRAINING Epoch: 1 2300 loss: 0.051
PLACES TRAINING Epoch: 1 2400 loss: 0.051
PLACES TRAINING Epoch: 1 2500 loss: 0.055
PLACES TRAINING Epoch: 1 2600 loss: 0.056
PLACES TRAINING Epoch: 1 2700 loss: 0.052
PLACES TRAINING Epoch: 1 2800 loss: 0.050
PLACES TRAINING Epoch: 1 2900 loss: 0.051
PLACES TRAINING Epoch: 1 3000 loss: 0.053
PLACES TRAINING Epoch: 1 3100 loss: 0.056
PLACES TRAINING Epoch: 1 3200 loss: 0.056
PLACES TRAINING Epoch: 1 3300 loss: 0.058
PLACES TRAINING Epoch: 1 3400 loss: 0.055
PLACES TRAINING Epoch: 1 3500 loss: 0.055
PLACES TRAINING Epoch: 1 3600 loss: 0.049
PLACES TRAINING Epoch: 1 3700 loss: 0.047
PLACES TRAINING Epoch: 1 3800 loss: 0.054
PLACES TRAINING Epoch: 1 3900 loss: 0.061
PLACES TRAINING Epoch: 1 4000 loss: 0.054
PLACES TRAINING Epoch: 2 100 loss: 0.053
PLACES TRAINING Epoch: 2 200 loss: 0.049
PLACES TRAINING Epoch: 2 300 loss: 0.054
PLACES TRAINING Epoch: 2 400 loss: 0.048
PLACES TRAINING Epoch: 2 500 loss: 0.060
PLACES TRAINING Epoch: 2 600 loss: 0.052
PLACES TRAINING Epoch: 2 700 loss: 0.054
PLACES TRAINING Epoch: 2 800 loss: 0.055
PLACES TRAINING Epoch: 2 900 loss: 0.052
PLACES TRAINING Epoch: 2 1000 loss: 0.053
PLACES TRAINING Epoch: 2 1100 loss: 0.056
PLACES TRAINING Epoch: 2 1200 loss: 0.057
PLACES TRAINING Epoch: 2 1300 loss: 0.049
PLACES TRAINING Epoch: 2 1400 loss: 0.049
PLACES TRAINING Epoch: 2 1500 loss: 0.050
PLACES TRAINING Epoch: 2 1600 loss: 0.053
PLACES TRAINING Epoch: 2 1700 loss: 0.056
PLACES TRAINING Epoch: 2 1800 loss: 0.049
PLACES TRAINING Epoch: 2 1900 loss: 0.054
PLACES TRAINING Epoch: 2 2000 loss: 0.054
PLACES TRAINING Epoch: 2 2100 loss: 0.064
PLACES TRAINING Epoch: 2 2200 loss: 0.064
PLACES TRAINING Epoch: 2 2300 loss: 0.060
PLACES TRAINING Epoch: 2 2400 loss: 0.058
PLACES TRAINING Epoch: 2 2500 loss: 0.057
PLACES TRAINING Epoch: 2 2600 loss: 0.060
PLACES TRAINING Epoch: 2 2700 loss: 0.053
PLACES TRAINING Epoch: 2 2800 loss: 0.062
PLACES TRAINING Epoch: 2 2900 loss: 0.048
PLACES TRAINING Epoch: 2 3000 loss: 0.055
PLACES TRAINING Epoch: 2 3100 loss: 0.057
PLACES TRAINING Epoch: 2 3200 loss: 0.051
PLACES TRAINING Epoch: 2 3300 loss: 0.063
PLACES TRAINING Epoch: 2 3400 loss: 0.060
PLACES TRAINING Epoch: 2 3500 loss: 0.049
PLACES TRAINING Epoch: 2 3600 loss: 0.053
PLACES TRAINING Epoch: 2 3700 loss: 0.054
PLACES TRAINING Epoch: 2 3800 loss: 0.049
PLACES TRAINING Epoch: 2 3900 loss: 0.051
PLACES TRAINING Epoch: 2 4000 loss: 0.054
PLACES TRAINING Epoch: 3 100 loss: 0.055
PLACES TRAINING Epoch: 3 200 loss: 0.054
PLACES TRAINING Epoch: 3 300 loss: 0.054
PLACES TRAINING Epoch: 3 400 loss: 0.054
PLACES TRAINING Epoch: 3 500 loss: 0.049
PLACES TRAINING Epoch: 3 600 loss: 0.052
PLACES TRAINING Epoch: 3 700 loss: 0.058
PLACES TRAINING Epoch: 3 800 loss: 0.052
PLACES TRAINING Epoch: 3 900 loss: 0.059
PLACES TRAINING Epoch: 3 1000 loss: 0.055
PLACES TRAINING Epoch: 3 1100 loss: 0.056
PLACES TRAINING Epoch: 3 1200 loss: 0.054
PLACES TRAINING Epoch: 3 1300 loss: 0.051
PLACES TRAINING Epoch: 3 1400 loss: 0.055
PLACES TRAINING Epoch: 3 1500 loss: 0.058
PLACES TRAINING Epoch: 3 1600 loss: 0.060
PLACES TRAINING Epoch: 3 1700 loss: 0.050
PLACES TRAINING Epoch: 3 1800 loss: 0.050

0 comments on commit b728266

Please sign in to comment.