示例#1
0
class Model():
    def __init__(self, batch_size):
        self.conv1 = Conv2D([batch_size, 28, 28, 1], 12, 5, 1)
        self.relu1 = LRelu(self.conv1.output_shape, alpha=0.001)
        self.maxpool1 = MaxPooling2D(self.relu1.output_shape)
        self.conv2 = Conv2D(self.maxpool1.output_shape, 24, 3, 1)
        self.relu2 = LRelu(self.conv2.output_shape, alpha=0.001)
        self.maxpool2 = MaxPooling2D(self.relu2.output_shape)
        self.fc = Linear(self.maxpool2.output_shape, 10)
        self.out = CrossEntropyLoss(self.fc.output_shape)

    def forward(self, x, label):
        # x shape [batchsize, H, W, C]
        # label shape[batchsize,]
        conv1_out = self.relu1.forward(self.conv1.forward(x))
        pool1_out = self.maxpool1.forward(conv1_out)
        conv2_out = self.relu2.forward(self.conv2.forward(pool1_out))
        pool2_out = self.maxpool2.forward(conv2_out)
        fc_out = self.fc.forward(pool2_out)
        loss_out = self.out.forward(fc_out, label)
        return loss_out

    def SGD(self):
        error_out = self.out.SGD()
        self.conv1.SGD(
            self.relu1.SGD(
                self.maxpool1.SGD(
                    self.conv2.SGD(
                        self.relu2.SGD(
                            self.maxpool2.SGD(self.fc.SGD(error_out)))))))

    def backward(self, learning_rate):
        self.fc.backward(lr=learning_rate, weight_decay=0.0004)
        self.conv2.backward(lr=learning_rate, weight_decay=0.0004)
        self.conv1.backward(lr=learning_rate, weight_decay=0.0004)
示例#2
0
 def __init__(self, batch_size):
     self.conv1 = Conv2D([batch_size, 28, 28, 1], 12, 5, 1)
     self.relu1 = LRelu(self.conv1.output_shape, alpha=0.001)
     self.maxpool1 = MaxPooling2D(self.relu1.output_shape)
     self.conv2 = Conv2D(self.maxpool1.output_shape, 24, 3, 1)
     self.relu2 = LRelu(self.conv2.output_shape, alpha=0.001)
     self.maxpool2 = MaxPooling2D(self.relu2.output_shape)
     self.fc = Linear(self.maxpool2.output_shape, 10)
     self.out = CrossEntropyLoss(self.fc.output_shape)
 def __init__(self, batch_size):
     self.conv1 = MobileNet_CNN_5x12([batch_size, 28, 28, 1], 12, 5, 1)
     self.relu1 = Relu(self.conv1.output_shape)
     self.maxpool1 = MaxPooling2D(self.relu1.output_shape)
     self.conv2 = MobileNet_CNN_3x24(self.maxpool1.output_shape, 24, 3, 1)
     self.relu2 = Relu(self.conv2.output_shape)
     self.maxpool2 = MaxPooling2D(self.relu2.output_shape)
     self.fc = Linear(self.maxpool2.output_shape, 10)
     self.out = CrossEntropyLoss(self.fc.output_shape)
示例#4
0
 def __init__(self, batch_size):
     self.conv1 = Conv2D([batch_size, 28, 28, 1], 12, 5, 1)
     self.relu1 = Relu(self.conv1.output_shape)
     self.avgpool1 = AvgPooling2D(self.relu1.output_shape)
     self.conv2 = Conv2D(self.avgpool1.output_shape, 24, 3, 1)
     self.relu2 = Relu(self.conv2.output_shape)
     self.avgpool2 = AvgPooling2D(self.relu2.output_shape)
     self.fc = Linear(self.avgpool2.output_shape, 10)
     self.out = CrossEntropyLoss(self.fc.output_shape)
 def __init__(self, batch_size):
     self.conv1 = Conv2D([batch_size, 28, 28, 1], 12, 5, 1)
     self.relu1 = Relu(self.conv1.output_shape)
     self.maxpool1 = MaxPooling2D(self.relu1.output_shape)
     self.conv2 = Conv2D(self.maxpool1.output_shape, 24, 3, 1)
     self.relu2 = Relu(self.conv2.output_shape)
     self.maxpool2 = MaxPooling2D(self.relu2.output_shape)
     self.global_avg_pool = Global_Avg_Pooling(self.maxpool2.output_shape)
     self.fc = Linear(self.global_avg_pool.output_shape, 10)
     self.out = CrossEntropyLoss(self.fc.output_shape)