wogong
7 years ago
6 changed files with 66 additions and 59 deletions
@ -1,39 +0,0 @@ |
|||
"""Classifier for source domain""" |
|||
|
|||
import torch.nn as nn |
|||
|
|||
class Classifier(nn.Module): |
|||
|
|||
def __init__(self): |
|||
super(Classifier, self).__init__() |
|||
self.restored = False |
|||
|
|||
self.feature = nn.Sequential() |
|||
self.feature.add_module('f_conv1', nn.Conv2d(1, 64, kernel_size=5)) |
|||
self.feature.add_module('f_bn1', nn.BatchNorm2d(64)) |
|||
self.feature.add_module('f_pool1', nn.MaxPool2d(2)) |
|||
self.feature.add_module('f_relu1', nn.ReLU(True)) |
|||
self.feature.add_module('f_conv2', nn.Conv2d(64, 50, kernel_size=5)) |
|||
self.feature.add_module('f_bn2', nn.BatchNorm2d(50)) |
|||
self.feature.add_module('f_drop1', nn.Dropout2d()) |
|||
self.feature.add_module('f_pool2', nn.MaxPool2d(2)) |
|||
self.feature.add_module('f_relu2', nn.ReLU(True)) |
|||
|
|||
self.class_classifier = nn.Sequential() |
|||
self.class_classifier.add_module('c_fc1', nn.Linear(50 * 4 * 4, 100)) |
|||
self.class_classifier.add_module('c_bn1', nn.BatchNorm2d(100)) |
|||
self.class_classifier.add_module('c_relu1', nn.ReLU(True)) |
|||
self.class_classifier.add_module('c_drop1', nn.Dropout2d()) |
|||
self.class_classifier.add_module('c_fc2', nn.Linear(100, 100)) |
|||
self.class_classifier.add_module('c_bn2', nn.BatchNorm2d(100)) |
|||
self.class_classifier.add_module('c_relu2', nn.ReLU(True)) |
|||
self.class_classifier.add_module('c_fc3', nn.Linear(100, 10)) |
|||
self.class_classifier.add_module('c_softmax', nn.LogSoftmax(dim=1)) |
|||
|
|||
def forward(self, input_data): |
|||
input_data = input_data.expand(input_data.data.shape[0], 1, 28, 28) |
|||
feature = self.feature(input_data) |
|||
feature = feature.view(-1, 50 * 4 * 4) |
|||
class_output = self.class_classifier(feature) |
|||
|
|||
return class_output |
Loading…
Reference in new issue