Unit Iv (CNN)
Unit Iv (CNN)
1. Feature Extraction:
2. Hierarchical Learning:
3. Spatial Hierarchy:
4. Filter Learning:
1. Multichannel Input
• Input Channels:
2. Convolutional Filters
• Filter Dimensions:
Convolutional filters also have multiple channels. For instance, a 3x3 filter
applied to an RGB image will have a depth of 3, matching the number of
input channels.
• Filter Operation:
The filter is applied across all input channels. For each spatial position,
the filter computes a weighted sum of all channels, producing a single value
for that position in the output feature map.
3. Convolution Process
4. Example
Consider an RGB image with dimensions 32x32x3 (32x32 spatial resolution and
3 color channels) and a convolutional filter with dimensions 3x3x3:
• Filter Operation: The 3x3x3 filter slides over the 32x32 spatial
dimensions of the image. For each position, it multiplies its 3x3x3 weights
with the corresponding pixels in the input image’s 3 channels, summing
the results.
• Output: The result is a single value for each spatial location, producing a
2D feature map. If multiple such filters are used, the output consists of
multiple 2D feature maps, each representing different learned features.
1. Forward Pass:
o At each time step, the RNN takes an input and the previous hidden
state to produce a new hidden state.
o The hidden state is updated based on the current input and the
previous hidden state.
o The new hidden state is used to produce an output for the current
time step.
2. Backpropagation Through Time (BPTT):
o During training, RNNs use a variant of backpropagation called
BPTT to adjust weights based on errors. BPTT involves unfolding
the RNN through time and applying backpropagation to each step.
Applications of RNNs
4.6 PyTorch
Steps :
➢ Install PyTorch:
Ensure you have PyTorch and necessary libraries installed.
➢ Import Libraries:
Load PyTorch and torchvision libraries.
➢ Prepare Data:
Load and preprocess the dataset using torchvision.
➢ Define the CNN Model:
Create a CNN by defining convolutional and fully connected layers.
➢ Define Loss Function and Optimizer:
Choose a loss function and optimizer f or training.
➢ Train the Model:
Implement the training loop to optimize model parameters.
➢ Evaluate the Model:
Test the model on a separate test dataset to measure performance.
➢ Save and Load the Model:
Save the trained model and reload it as needed.