Example #1
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        width, height, channels = input_shape
        self.conv1 = ConvolutionalLayer(in_channels=3,
                                        out_channels=3,
                                        filter_size=conv1_channels)
        self.relu1 = ReLULayer()
        self.maxpool1 = MaxPoolingLayer(4, 4)
        self.conv2 = ConvolutionalLayer(in_channels=3,
                                        out_channels=3,
                                        filter_size=conv2_channels)
        self.relu2 = ReLULayer()
        self.maxpool2 = MaxPoolingLayer(4, 4)
        self.flatten = Flattener()
        self.f_connected = FullyConnectedLayer(3, n_output_classes)
Example #2
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network
        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        width, height, channels = input_shape
        filter_size = 3
        padding = 1
        pool_size = 4
        pool_stride = 4

        self.Conv1 = ConvolutionalLayer(channels, conv1_channels, filter_size,
                                        padding)
        self.ReLU1 = ReLULayer()
        self.MaxPool1 = MaxPoolingLayer(pool_size, pool_stride)

        self.Conv2 = ConvolutionalLayer(conv1_channels, conv2_channels,
                                        filter_size, padding)
        self.ReLU2 = ReLULayer()
        self.MaxPool2 = MaxPoolingLayer(pool_size, pool_stride)

        left_width = width // pool_stride // pool_stride
        left_height = height // pool_stride // pool_stride

        self.Flat = Flattener()
        self.FullyConnected = FullyConnectedLayer(
            left_width * left_height * conv2_channels, n_output_classes)
Example #3
0
    def __init__(self, num_input, num_cells=50, num_output=1, lr=0.01, rho=0.95):
        X = T.matrix('x')
        Y = T.matrix('y')
        eta = T.scalar('eta')
        alpha = T.scalar('alpha')

        self.num_input = num_input
        self.num_output = num_output
        self.num_cells = num_cells
        self.eta = eta

        inputs = InputLayer(X, name="inputs")
        lstm = LSTMLayer(num_input, num_cells, input_layer=inputs, name="lstm")
        fc = FullyConnectedLayer(num_cells, num_output, input_layer=lstm)
        Y_hat = T.mean(fc.output(), axis=2)
        layer = inputs, lstm, fc
        self.params = get_params(layer)
        self.caches = make_caches(self.params)
        self.layers = layer
        mean_cost = T.mean((Y - Y_hat)**2)
        last_cost = T.mean((Y[-1] - Y_hat[-1])**2)
        self.cost = alpha*mean_cost + (1-alpha)*last_cost
        """"
        self.updates = momentum(self.cost, self.params, self.caches, self.eta, clip_at=3.0)
        """
        self.updates,_,_,_,_ = create_optimization_updates(self.cost, self.params, method="adadelta", lr= lr, rho=rho)
        self.train = theano.function([X, Y, alpha], [self.cost, last_cost] ,\
                updates=self.updates, allow_input_downcast=True)
        self.costfn = theano.function([X, Y, alpha], [self.cost, last_cost],\
                allow_input_downcast=True)
        self.predict = theano.function([X], [Y_hat], allow_input_downcast=True)
Example #4
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        self.input_shape = input_shape
        self.n_output_classes = n_output_classes

        self.layer1 = ConvolutionalLayer(3, conv1_channels, 3,
                                         1)  #32x32x3xconv1_channels
        self.layer2 = ReLULayer()
        self.layer3 = MaxPoolingLayer(4, 4)  #8x8x3xconv1_channels
        self.layer4 = ConvolutionalLayer(
            conv1_channels, conv2_channels, 3,
            1)  #8x8x3x conv1_channels x conv2_channels
        self.layer5 = ReLULayer()
        self.layer6 = MaxPoolingLayer(
            4, 4)  #2x2x3 conv1_channels x conv2_channels
        self.layer7 = Flattener()
        self.layer8 = FullyConnectedLayer(conv1_channels * conv2_channels * 2,
                                          n_output_classes)
Example #5
0
    def __init__(self, input_shape, n_output_classes, conv1_channels, conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        self.height = input_shape[0]
        self.width = input_shape[1]
        self.input_channels = input_shape[2]
        self.n_output_classes = n_output_classes
        self.conv1_channels = conv1_channels
        self.conv2_channels = conv2_channels

        self.conv1_layer = ConvolutionalLayer(self.input_channels, self.conv1_channels, 3, 1)
        self.relu1 = ReLULayer()
        self.maxpool1 = MaxPoolingLayer(4, 4)

        self.conv2_layer = ConvolutionalLayer(self.conv1_channels, self.conv2_channels, 3, 1)
        self.relu2 = ReLULayer()
        self.maxpool2 = MaxPoolingLayer(4, 4)

        self.flattener = Flattener()
        self.fc_layer = FullyConnectedLayer(2*2*self.conv2_channels, self.n_output_classes)
Example #6
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        width, height, n_channels = input_shape

        self.conv1 = ConvolutionalLayer(n_channels, conv1_channels, 3, 1)
        self.relu1 = ReLULayer()
        self.maxpool1 = MaxPoolingLayer(4, 4)
        self.conv2 = ConvolutionalLayer(conv1_channels, conv2_channels, 3, 1)
        self.relu2 = ReLULayer()
        self.maxpool2 = MaxPoolingLayer(4, 4)
        self.flatten = Flattener()

        self.fc = FullyConnectedLayer(
            (height // 4 // 4) * (width // 4 // 4) * conv2_channels,
            n_output_classes)

        self.conv1_params = self.conv1.params()
        self.conv2_params = self.conv2.params()
        self.fc_params = self.fc.params()
Example #7
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        input_width, input_height, input_channels = input_shape
        self.conv1 = ConvolutionalLayer(input_channels,
                                        conv1_channels,
                                        filter_size=3,
                                        padding=1)
        self.relu1 = ReLULayer()
        self.maxpool1 = MaxPoolingLayer(pool_size=4, stride=4)
        self.conv2 = ConvolutionalLayer(conv1_channels,
                                        conv2_channels,
                                        filter_size=3,
                                        padding=1)
        self.relu2 = ReLULayer()
        self.maxpool2 = MaxPoolingLayer(pool_size=4, stride=4)
        self.flattener = Flattener()
        self.fc = FullyConnectedLayer(
            input_width * input_height * conv2_channels // (4**4),
            n_output_classes)
Example #8
0
    def __init__(self, input_shape, n_output_classes, conv1_channels, conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO_ Create necessary layers
        # raise Exception("Not implemented!")

        weight, height, cannels = input_shape
        filter_size = 3
        pool_size = 4
        padding = 1
        stride = pool_size

        self.conv1 = ConvolutionalLayer(cannels, conv1_channels, filter_size, padding)
        self.relu1 = ReLULayer()
        self.maxpool1 = MaxPoolingLayer(pool_size, stride)
        self.conv2 = ConvolutionalLayer(conv1_channels, conv2_channels, filter_size, padding)
        self.relu2 = ReLULayer()
        self.maxpool2 = MaxPoolingLayer(pool_size, stride)
        self.flatten = Flattener()
        n_fc_input = int(height / pool_size / pool_size * weight / pool_size / pool_size * conv2_channels)
        self.fc = FullyConnectedLayer(n_fc_input, n_output_classes)
Example #9
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        #raise Exception("Not implemented!")

        image_width, image_height, n_channels = input_shape

        self.conv1 = ConvolutionalLayer(n_channels, conv1_channels, 3, 1)
        self.relu1 = ReLULayer()
        self.maxp1 = MaxPoolingLayer(4, 4)
        self.conv2 = ConvolutionalLayer(conv1_channels, conv2_channels, 3, 1)
        self.relu2 = ReLULayer()
        self.maxp2 = MaxPoolingLayer(4, 4)
        self.flatn = Flattener()

        fc_input = int(image_width * image_height * conv2_channels / pow(4, 4))
        self.fc = FullyConnectedLayer(fc_input, n_output_classes)
Example #10
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        
        # TODO Create necessary layers
        self.fully_layers = []
        self.relu_layers = []
        inp = n_input
        out = n_output
        for l in range(hidden_layer_size):
            #print ("inp = %, out = % ", inp, out)
            self.fully_layers.append(FullyConnectedLayer(inp, out))
            #inp, out = out, inp
            inp = 10
            self.relu_layers.append(ReLULayer())

        self.fully_layers.append(FullyConnectedLayer(inp, n_output))
        #raise Exception("Not implemented!")
        """
        self.reg = reg
        self.input_fc = FullyConnectedLayer(n_input, hidden_layer_size)
        self.input_re = ReLULayer()
        self.hidden_fc = FullyConnectedLayer(hidden_layer_size, n_output)
Example #11
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        filter_size = 3
        pool_size = 4
        self.conv1 = ConvolutionalLayer(input_shape[2],
                                        conv1_channels,
                                        filter_size,
                                        padding=1)
        self.relu1 = ReLULayer()
        self.max_pool1 = MaxPoolingLayer(pool_size, stride=pool_size)
        self.conv2 = ConvolutionalLayer(conv1_channels,
                                        conv2_channels,
                                        filter_size,
                                        padding=1)
        self.relu2 = ReLULayer()
        self.max_pool2 = MaxPoolingLayer(pool_size, stride=pool_size)
        self.flatten = Flattener()
        self.fc = FullyConnectedLayer(n_input=4 * conv2_channels,
                                      n_output=n_output_classes)
Example #12
0
 def __init__(self, n_input, n_output, hidden_layer_size, reg):
     self.layers = [
         FullyConnectedLayer(n_input, hidden_layer_size),
         ReLULayer(),
         FullyConnectedLayer(hidden_layer_size, n_output)
     ]
     self.reg = reg
Example #13
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
            Initializes the neural network

            Arguments:
            n_input, int - dimension of the model input
            n_output, int - number of classes to predict
            hidden_layer_size, int - number of neurons in the hidden layer
            reg, float - L2 regularization ngth
        """
        self.result = {}
        self.reg = reg
        self.n_input = n_input
        self.n_output = n_output
        self.hidden_layer_size = hidden_layer_size

        # # TODO Create necessary layers
        self.first_layer = FullyConnectedLayer(self.n_input,
                                               self.hidden_layer_size)
        self.first_relu = ReLULayer()

        self.second_layer = FullyConnectedLayer(self.hidden_layer_size,
                                                self.n_output)
        self.second_relu = ReLULayer()

        first_layer_param = self.first_layer.params()
        self.result['first_l_param_W'] = first_layer_param['W']
        self.result['first_l_param_B'] = first_layer_param['B']

        second_layer_param = self.second_layer.params()
        self.result['second_l_param_W'] = second_layer_param['W']
        self.result['second_l_param_B'] = second_layer_param['B']
Example #14
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers

        self.out_classes = n_output_classes
        image_width, image_height, in_channels = input_shape

        self.Conv1 = ConvolutionalLayer(in_channels, conv1_channels, 3, 1)
        self.ReLU1 = ReLULayer()
        self.MaxPool1 = MaxPoolingLayer(4, 4)
        self.Conv2 = ConvolutionalLayer(conv1_channels, conv2_channels, 3, 1)
        self.ReLU2 = ReLULayer()
        self.MaxPool2 = MaxPoolingLayer(4, 4)
        self.Flatten = Flattener()
        self.FC = FullyConnectedLayer(4 * conv2_channels, n_output_classes)
Example #15
0
 def ensure_layers(self):
     if self.layers is None:
         self.layers = [
             ("Input Layer",
              FullyConnectedLayer(self.n_input, self.hidden_layer_size)),
             ("ReLU Layer", ReLULayer()),
             ("Hidden Layer",
              FullyConnectedLayer(self.hidden_layer_size, self.n_output)),
         ]
Example #16
0
 def __init__(self, n_input, n_output, hidden_layer_size, reg):
     """
     Initializes the neural network
     :param n_input: int - dimension of the model input
     :param n_output: int - number of classes to predict
     :param hidden_layer_size: int - number of neurons in the hidden layer
     :param reg: float - L2 regularization strength
     """
     self.reg = reg
     self.layer_one = FullyConnectedLayer(n_input, hidden_layer_size)
     self.layer_ReLU = ReLULayer()
     self.layer_two = FullyConnectedLayer(hidden_layer_size, n_output)
Example #17
0
 def __init__(self, n_input, n_output, hidden_layer_size, reg):
     """
     Initializes the neural network
     Arguments:
     n_input, int - dimension of the model input
     n_output, int - number of classes to predict
     hidden_layer_size, int - number of neurons in the hidden layer
     reg, float - L2 regularization strength
     """
     self.reg = reg
     self.layer_1 = FullyConnectedLayer(n_input, hidden_layer_size)
     self.non_linier = ReLULayer()
     self.layer_2 = FullyConnectedLayer(hidden_layer_size, n_output)
Example #18
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.reg = reg
        # TODO Create necessary layers
        self.hidden_layer1 = FullyConnectedLayer(n_input, hidden_layer_size)
        self.hidden_layer2 = FullyConnectedLayer(hidden_layer_size, n_output)
        self.relu_layer1 = ReLULayer()
        self.relu_layer2 = ReLULayer()
Example #19
0
    def __init__(self, hidden_layer_size, i, o, reg):
        """
        Initializes the neural network

        Arguments:
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.reg = reg
        self.layers = []        
        for num_layer in range(1):
            self.layers.append(FullyConnectedLayer(i,hidden_layer_size))
            self.layers.append(ReLULayer())
        
        self.layers.append(FullyConnectedLayer(hidden_layer_size,o))
Example #20
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.reg = reg
        # TODO Create necessary layers
        self.first = FullyConnectedLayer(n_input, hidden_layer_size)
        self.relu = ReLULayer()
        self.second = FullyConnectedLayer(hidden_layer_size, n_output)
Example #21
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        self.layers = [
            ConvolutionalLayer(in_channels=input_shape[2],
                               out_channels=input_shape[2],
                               filter_size=conv1_channels,
                               padding=2),
            ReLULayer(),
            MaxPoolingLayer(pool_size=4, stride=2),  #2
            ConvolutionalLayer(in_channels=input_shape[2],
                               out_channels=input_shape[2],
                               filter_size=conv2_channels,
                               padding=2),
            ReLULayer(),
            MaxPoolingLayer(pool_size=4, stride=2),  #2
            Flattener(),
            FullyConnectedLayer(n_input=192, n_output=n_output_classes)
        ]  #192
Example #22
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        self.layers = [
            ConvolutionalLayer(input_shape[2], conv1_channels, 3, 0),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            ConvolutionalLayer(conv1_channels, conv2_channels, 3, 0),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            Flattener(),
            FullyConnectedLayer(
                int(input_shape[0] * input_shape[1] * conv2_channels / 256),
                n_output_classes)
        ]
Example #23
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        # TODO Create necessary layers
        # raise Exception("Not implemented!")

        self.out_classes = n_output_classes
        image_width, image_height, in_channels = input_shape

        self.layers = [
            ConvolutionalLayer(in_channels, conv1_channels, 3, 1),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            ConvolutionalLayer(conv1_channels, conv2_channels, 3, 1),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            Flattener(),
            FullyConnectedLayer(4 * conv2_channels, n_output_classes)
        ]
Example #24
0
    def __init__(self, input_shape, n_output_classes, conv1_channels,
                 conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        self.model = [
            ConvolutionalLayer(in_channels=input_shape[2],
                               out_channels=conv1_channels,
                               filter_size=3,
                               padding=1),
            ReLULayer(),
            MaxPoolingLayer(2, 2),
            ConvolutionalLayer(in_channels=conv1_channels,
                               out_channels=conv2_channels,
                               filter_size=3,
                               padding=1),
            ReLULayer(),
            MaxPoolingLayer(2, 2),
            Flattener(),
            FullyConnectedLayer(n_input=int(input_shape[0] / 4)**2 *
                                conv2_channels,
                                n_output=n_output_classes)
        ]
Example #25
0
    def __init__(self, input_shape, n_output_classes, conv1_channels, conv2_channels):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        width, height, n_channels = input_shape
        conv = 3
        pad = 1
        stride = 4
        pool = 4
        
        hidden_layer_size = (width // stride // stride) * (height // stride // stride) * conv2_channels
        
        self.layers = [
            ConvolutionalLayer(n_channels, conv1_channels, conv, pad),
            ReLULayer(),
            MaxPoolingLayer(pool, stride),
            ConvolutionalLayer(conv1_channels, conv2_channels, conv, pad),
            ReLULayer(),
            MaxPoolingLayer(pool, stride),
            Flattener(),
            FullyConnectedLayer(hidden_layer_size, n_output_classes)        
        ]
Example #26
0
    def __init__(self, n_input, n_output, conv1_size, conv2_size, reg):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        conv1_size, int - number of filters in the 1st conv layer
        conv2_size, int - number of filters in the 2nd conv layer
        reg, float - L2 regularization strength
        """
        self.reg = reg
        height, width, input_channels = n_input

        self.L = [
            ConvolutionalLayer(in_channels=input_channels,
                               out_channels=conv1_size,
                               filter_size=3,
                               padding=1),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            ConvolutionalLayer(in_channels=conv1_size,
                               out_channels=conv2_size,
                               filter_size=3,
                               padding=1),
            ReLULayer(),
            MaxPoolingLayer(4, 4),
            Flattener(),
            FullyConnectedLayer(8, n_output)
        ]
Example #27
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        hidden_layer_size, int - number of neurons in the hidden layer
        n_input, int - dimension of the model input
        reg, float - L2 regularization strength
        """
        self.reg = reg
        self.input_layer = FullyConnectedLayer(n_input, hidden_layer_size)
        self.relu = ReLULayer()
        self.output_layer = FullyConnectedLayer(hidden_layer_size, n_output)
        self.W_in = None
        self.W_out = None
        self.B_in = None
        self.B_out = None
Example #28
0
    def __init__(self,
                 input_shape,
                 n_output_classes,
                 conv1_channels,
                 conv2_channels,
                 filter_size=3):
        """
        Initializes the neural network

        Arguments:
        input_shape, tuple of 3 ints - image_width, image_height, n_channels
                                         Will be equal to (32, 32, 3)
        n_output_classes, int - number of classes to predict
        conv1_channels, int - number of filters in the 1st conv layer
        conv2_channels, int - number of filters in the 2nd conv layer
        """
        self.input_shape = input_shape
        self.n_output_classes = n_output_classes
        self.conv1_channels = conv1_channels
        self.conv2_channels = conv2_channels
        self.filter_size = filter_size
        self.padding = 1

        c1 = int(
            (input_shape[0] - self.filter_size + 2 * self.padding) / 1) + 1
        mp1 = int((c1 - 4) / 4) + 1
        c2 = int((mp1 - self.filter_size + 2 * self.padding) / 1) + 1
        self.size_after_2maxpool = int((c2 - 4) / 4) + 1

        self.RL1 = ReLULayer()
        self.RL2 = ReLULayer()
        self.MaxPool1 = MaxPoolingLayer(pool_size=4, stride=4)
        self.MaxPool2 = MaxPoolingLayer(pool_size=4, stride=4)
        self.Flatten = Flattener()
        self.Conv1 = ConvolutionalLayer(in_channels=self.input_shape[-1],
                                        out_channels=conv1_channels,
                                        filter_size=self.filter_size,
                                        padding=self.padding)
        self.Conv2 = ConvolutionalLayer(in_channels=conv1_channels,
                                        out_channels=conv2_channels,
                                        filter_size=self.filter_size,
                                        padding=self.padding)
        self.FC = FullyConnectedLayer(n_input=conv2_channels *
                                      self.size_after_2maxpool**2,
                                      n_output=self.n_output_classes)
Example #29
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.reg = reg

        # TODO_ Create necessary layers
        # raise Exception("Not implemented!")

        self.layer1 = FullyConnectedLayer(n_input, hidden_layer_size)
        self.relu_layer = ReLULayer()
        self.layer2 = FullyConnectedLayer(hidden_layer_size, n_output)
Example #30
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.fcl1 = FullyConnectedLayer(n_input, hidden_layer_size)
        self.fcl2 = FullyConnectedLayer(hidden_layer_size, n_output)
        self.relu = ReLULayer()
        self.reg = reg
        self.w1 = self.fcl1.params()['W']
        self.w2 = self.fcl2.params()['W']
        self.b1 = self.fcl1.params()['B']
        self.b2 = self.fcl1.params()['B']
Example #31
0
    def __init__(self, n_input, n_output, hidden_layer_size, reg=0):
        """
        Initializes the neural network

        Arguments:
        n_input, int - dimension of the model input
        n_output, int - number of classes to predict
        hidden_layer_size, int - number of neurons in the hidden layer
        reg, float - L2 regularization strength
        """
        self.reg = reg
        self.n_input = n_input
        self.n_output = n_output
        self.h_size = hidden_layer_size
        # TODO Create necessary layers
        self.RL = ReLULayer()
        self.FC1 = FullyConnectedLayer(n_input=self.n_input,
                                       n_output=self.h_size)
        self.FC2 = FullyConnectedLayer(self.h_size, self.n_output)