Skip to content

Commit 05d1a95

Browse files
author
redone17
committed
init mlp
1 parent a29ab43 commit 05d1a95

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
from .lenet import *
55
from .vgg import *
66
from .dcnn import *
7+
# from .mlp import *
78

models/dcnn.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'''
2+
mport torch
3+
import torch.nn as nn
4+
from torch.autograd import Variable
25
DCNN for one-dimensional signals in Pytorch.
36
'''
47

@@ -47,7 +50,7 @@ def _make_layers(self, cfg):
4750
return nn.Sequential(*layers)
4851

4952
'''
50-
net = Net('DCNN09',1,5)
53+
net = Net('DCNN08',1,5)
5154
x = torch.randn(10,1,2048)
5255
print(net(Variable(x)).size())
5356
'''

models/mlp.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
Multi-Layer Perceptron
3+
a baseline
4+
'''
5+
import torch
6+
import torch.nn as nn
7+
from torch.autograd import Variable
8+
9+
class Net(nn.Mudule):
10+
def __init__(self, in_features, n_class, n_hiddens=[500, 100], use_batchnorm=False, use_dropout=False):
11+
super(Net, self).__init__()
12+
self.name = vgg_name
13+
self.in_features = in_features
14+
self.use_batchnorm = use_batchnorm
15+
self.use_dropout = use_dropout
16+
self.n_layers = len(n_hiddens) + 1
17+
self.n_hiddens = n_hiddens
18+
self.mlp = self._make_layers(in_features, n_hiddens, n_class)
19+
20+
def _make_layers(in_features, n_hiddens, n_class):
21+
TODO
22+

run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
print( )
4141

4242
## make models
43-
model = dcnn.Net('DCNN11', 1, 5)
43+
model = dcnn.Net('DCNN13', 1, 5)
4444

4545
## train
4646
criterion = nn.CrossEntropyLoss()
47-
optimizer = optim.Adam(model.parameters(), weight_decay=0.0001)
47+
optimizer = optim.Adam(model.parameters(), weight_decay=0.001)
4848
best_model, loss_curve = iter_utils.train(model, train_loader, criterion, optimizer,
4949
init_lr=0.0001, decay_epoch=5, n_epoch=10)
5050

0 commit comments

Comments
 (0)