Question

In: Computer Science

Subject: Neural network and Pattern recognition (Deep Learning) Given the following partial network definitioon: Input -...

Subject: Neural network and Pattern recognition (Deep Learning)

Given the following partial network definitioon:

Input - A 28 x 28 RGB image

First Layer - 7, 5 x 5 filters. Activation function: Sigmoid

Second Layer - 23, 3 x 3 filters. Activation function: RelU

Third Layer - 20, 3 x 3 filters. Activation function: RelU

You task is to do design(s) of the next part of the network (so that it uses the output of the third layer).

The purpose of the complete network will be to predict a probability distribution over 5 classes.

You are required to do two designs.

- In the first design you can use fully connected layers.

- In the second design you are cannot use fully connected layers but instead must use convolutional layers.

Your design definition should include

- Any operation you are performing (e.g. flattening, reshaping etc.)

- Any activation function you want to use

- The number of neurons (for fully connected layers)

- The number of filters, their kernel size, and response shape (for convolutional layers)

Solutions

Expert Solution

For the above problem using pytorch to solve the problem

load the requires packages

above mentioned the we can any number size of layers, so i choosed to 512

first i like to solve mlp and fully connected network using python

and the input size in fully connected layers include print so shapes of network will sure the final result

class ConvNet(nn.Module):
    def __init__(self):
        super(ConvNet, self).__init__()
        self.layer1 = nn.Sequential(
            nn.Conv2d(1, 7, kernel_size=5, stride=1, padding=2),
            nn.Sigmoid(),
            nn.MaxPool2d(kernel_size=2, stride=2))
        self.layer2 = nn.Sequential(
            nn.Conv2d(7, 23, kernel_size=5, stride=1, padding=2),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2))
        self.layer2 = nn.Sequential(
            nn.Conv2d(23, 20, kernel_size=5, stride=1, padding=2),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2))
        
        self.drop_out = nn.Dropout()
        self.fc1 = nn.Linear(784, 1000)
        self.fc2 = nn.Linear(1000, 10)
     def forward(self, x):
        out = self.layer1(x)
        out = self.layer2(out)
        out = self.layer3(out)
        out = out.reshape(out.size(0), -1)
        out = self.drop_out(out)
        out = self.fc1(out)
        out = self.fc2(out)
    return out
net = ConvNet()
print(net


import torch.nn as nn
import torch.nn.functional as F

# define the NN architecture
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        # number of hidden nodes in each layer (512)
        hidden_1 = 512
        hidden_2 = 512
        # linear layer (784 -> hidden_1)
        self.fc1 = nn.Linear(28 * 28, hidden_1)
        # linear layer (n_hidden -> hidden_2)
        self.fc2 = nn.Linear(hidden_1, hidden_2)
        # linear layer (n_hidden -> 10)
        self.fc3 = nn.Linear(hidden_2, 5)
        # dropout layer (p=0.2)
        # dropout prevents overfitting of data
        self.dropout = nn.Dropout(0.2)

    def forward(self, x):
        # flatten image input
        x = x.view(-1, 28 * 28)
        # add hidden layer, with relu activation function
        x = F.sigmoid(self.fc1(x))
        # add dropout layer
        x = self.dropout(x)
        # add hidden layer, with relu activation function
        x = F.relu(self.fc2(x))
        # add dropout layer
        x = self.dropout(x)
        # add output layer
        x = self.fc3(x)
        return x
network = Net()
print(network)

Related Solutions

Training a convolutional neural network for speech recognition, one finds that performance on the training set...
Training a convolutional neural network for speech recognition, one finds that performance on the training set is very good while the performance on the validation set is unacceptably low. A reasonable fix might be to: (Select the single best answer) And please give a explanation why they are true or false (A) Decrease the weight decay (B) Reduce the training set size (C) Reduce the number of layers and neurons (D) Increase the number of layers and neurons
Consider a Convolutional Neural Network which accepts a 120 x 120 CMYK image as input. The...
Consider a Convolutional Neural Network which accepts a 120 x 120 CMYK image as input. The network has a series of 5 convolutional layers, where the parameters in conv-layer 3 and conv-layer 5 are shared. Each conv-layer has 20 3x3 filters. The output of the last conv-layer is flattened and passed through a fully connected layer with 30 neurons, which is then passed through another fully connected layer of 10 neurons. Each neuron in the fully connected layers and each...
take your learning a step further by testing your critical thinking skills on this pattern recognition...
take your learning a step further by testing your critical thinking skills on this pattern recognition exercise. Post your responses here. When we progress to higher levels of cognitive functioning, we do not spend all our time at these higher levels. Piaget himself once observed that he spent only a fraction of each day in formal operational thought processes. This suggests that even as adults, we do not entirely leave preoperational thought behind. To help you understand preoperational thought processes...
Machine learning Neural Networks question: Which of the following statements is (are) true about neural networks?...
Machine learning Neural Networks question: Which of the following statements is (are) true about neural networks? There may be multiple correct statements, please give a reason why they are true or false (A) The training time depends on the size of the network as well as the training data. (B)The perceptron is a single layer recurrent neural network. (C) In image processing, compared with fully connected networks, usually convolutional networks are preferred. (D) Neural network cannot be used for solving...
Deep leraning/LSTM/Matlab There is a Matlab code that is doing the following steps for deep learning...
Deep leraning/LSTM/Matlab There is a Matlab code that is doing the following steps for deep learning and applying LSTM, I need to change first three steps to use our dataset to train this model and you don't need to change other. I need to apply that for .ogg audio files so Create and Use some audio files with .ogg format as sample data and give me the code. The following steps is for your information: Three classes of audio signals...
Neurons: Please construct a Neural Network for the following logic, NAND Truth table for NAND function...
Neurons: Please construct a Neural Network for the following logic, NAND Truth table for NAND function i1 i2 output 0 0 1 0 1 1 1 0 1 1 1 0
What will the expression pattern be for the following lac operon partial diploid? I- Oc Z+...
What will the expression pattern be for the following lac operon partial diploid? I- Oc Z+ Y- / I+ O+ Z- Y+ A) both genes inducible B) lacZ constitutive, lacY inducible C) lacZ inducible, lacY constitutive D) Both genes (lacZ and lacY) constitutive
1. Plantsville makes all sales on account, subject to the following collection pattern: 30% are collected...
1. Plantsville makes all sales on account, subject to the following collection pattern: 30% are collected in the month of sale; 60% are collected in the first month after sale; and 10% are collected in the second month after sale. If sales for October, November, and December were $79,000, $69,000, and $59,000, respectively, what was the budgeted receivables balance on December 31? Multiple Choice $67,000. $41,300. $48,200. $49,300. None of the answers is correct. 2.   Glastonbury Inc. began operations in...
Budgeting Vern's makes all sales on account, subject to the following collection pattern: 20% are collected...
Budgeting Vern's makes all sales on account, subject to the following collection pattern: 20% are collected in the month of sale; 70% are collected in the first month after sale; and 10% are collected in the second month after sale. Required: If sales for October, November and December were $171,662, $198,213, and $145,268, respectively, what was the budgeted receivables balance on December 31?
Given the following information, you are to determine the following Project network. Early, late and slack...
Given the following information, you are to determine the following Project network. Early, late and slack activity times. Project duration. Critical path Task Predecessor Duration A None 5 B A 8 C A 15 D A 10 E A 10 F B 10 G C, D 12 H E, 15 I G, H 7 J F,G,I 10 K J 12
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT