def __init__(self, num_in=0, num_h1=0, num_h2=0, num_out=0, dropout=1.0, weight_scale=1e-2): super(ThreeLayerNet, self).__init__() self.fc1 = nn.FC(num_in, num_h1, weight_scale=weight_scale) self.fc2 = nn.FC(num_h1, num_h2, weight_scale=weight_scale) self.fc3 = nn.FC(num_h2, num_out, weight_scale=weight_scale) self.relu = nn.ReLU() self.z1_cache = None self.z1 = None self.z2_cache = None self.z2 = None self.z3_cache = None self.use_dropout = dropout != 1.0 self.dropout_param = {} if self.use_dropout: self.dropout_param['mode'] = 'train' self.dropout_param['p'] = dropout self.dropout = nn.Dropout() self.U1 = None self.U2 = None self.params = self._get_params()
def __init__(self, in_channels=1, out_channels=10, dropout=1.0, weight_scale=1e-2): super(LeNet5, self).__init__() self.conv1 = nn.Conv2d2(in_channels, 5, 5, 6, stride=1, padding=0, weight_scale=weight_scale) self.conv2 = nn.Conv2d2(6, 5, 5, 16, stride=1, padding=0, weight_scale=weight_scale) self.conv3 = nn.Conv2d2(16, 5, 5, 120, stride=1, padding=0) self.maxPool1 = nn.MaxPool2(2, 2, 6, stride=2) self.maxPool2 = nn.MaxPool2(2, 2, 16, stride=2) self.fc1 = nn.FC(120, 84) self.fc2 = nn.FC(84, out_channels) self.relu = nn.ReLU() self.z1 = None self.z1_cache = None self.z2 = None self.z2_cache = None self.z3 = None self.z3_cache = None self.z4 = None self.z4_cache = None self.z5 = None self.z5_cache = None self.z6 = None self.z6_cache = None # self.z7 = None self.z7_cache = None self.use_dropout = dropout != 1.0 self.dropout_param = {} if self.use_dropout: self.dropout_param['mode'] = 'train' self.dropout_param['p'] = dropout self.dropout = nn.Dropout() self.U1 = None self.params = self._get_params()
def _get_fcs(self): fcs = list() if self.hidden_dims is None: fcs.append( nn.FC(self.input_dim, self.num_classes, weight_scale=self.weight_scale)) else: for i in range(self.num_layers): if i == 0: num_in = self.input_dim else: num_in = self.hidden_dims[i - 1] if i == (self.num_layers - 1): num_out = self.num_classes else: num_out = self.hidden_dims[i] fcs.append(nn.FC(num_in, num_out)) return fcs
def __init__(self, in_channels, out_channels, momentum=0, nesterov=False): super(AlexNet, self).__init__() self.conv1 = nn.Conv2d(in_channels, 11, 11, 96, stride=4, padding=0, momentum=momentum, nesterov=nesterov) self.conv2 = nn.Conv2d(96, 5, 5, 256, stride=1, padding=2, momentum=momentum, nesterov=nesterov) self.conv3 = nn.Conv2d(256, 3, 3, 384, stride=1, padding=1, momentum=momentum, nesterov=nesterov) self.conv4 = nn.Conv2d(384, 3, 3, 384, stride=1, padding=1, momentum=momentum, nesterov=nesterov) self.conv5 = nn.Conv2d(384, 3, 3, 256, stride=1, padding=1, momentum=momentum, nesterov=nesterov) self.maxPool1 = nn.MaxPool(3, 3, 96, stride=2) self.maxPool2 = nn.MaxPool(3, 3, 256, stride=2) self.maxPool3 = nn.MaxPool(3, 3, 256, stride=2) self.fc1 = nn.FC(9216, 4096, momentum=momentum, nesterov=nesterov) self.fc2 = nn.FC(4096, 4096, momentum=momentum, nesterov=nesterov) self.fc3 = nn.FC(4096, out_channels, momentum=momentum, nesterov=nesterov) self.relu1 = nn.ReLU() self.relu2 = nn.ReLU() self.relu3 = nn.ReLU() self.relu4 = nn.ReLU() self.relu5 = nn.ReLU() self.relu6 = nn.ReLU() self.relu7 = nn.ReLU() self.dropout = nn.Dropout() self.U1 = None self.U2 = None