<jupyter_start><jupyter_text>Lab 10.01 : Convolutional layer - demo<jupyter_code>import torch
import torch.nn as nn<jupyter_output><empty_output><jupyter_text>Make a convolutional module* inputs:  2 channels* output:  5 activation maps * filters are 3x3* padding with one layer of zero to not shrink anything<jupyter_code>mod = nn.Conv2d( 2 , 5 ,  kernel_size=3,  padding=1 )<jupyter_output><empty_output><jupyter_text>Make an input 2 x 6 x 6  (two channels, each one has 6 x 6 pixels )<jupyter_code>bs=1

x=torch.rand(bs,2,6,6)

print(x)<jupyter_output>tensor([[[[0.1784, 0.3722, 0.3135, 0.8681, 0.5603, 0.2079],
          [0.9363, 0.8443, 0.8515, 0.2553, 0.5105, 0.8482],
          [0.1119, 0.7999, 0.9080, 0.2513, 0.6365, 0.7876],
          [0.0709, 0.1471, 0.6620, 0.6763, 0.0782, 0.4592],
          [0.0897, 0.0623, 0.9341, 0.7683, 0.7604, 0.8292],
          [0.0084, 0.7799, 0.2410, 0.6735, 0.8646, 0.4548]],

         [[0.4053, 0.4116, 0.5764, 0.2431, 0.8331, 0.6385],
          [0.6246, 0.2053, 0.7000, 0.4831, 0.2516, 0.5654],
          [0.2548, 0.8840, 0.6014, 0.0869, 0.1532, 0.2282],
          [0.3570, 0.6875, 0.6426, 0.3577, 0.2863, 0.9814],
          [0.5728, 0.9117, 0.4430, 0.7477, 0.3931, 0.3130],
          [0.0549, 0.2686, 0.3305, 0.5118, 0.3321, 0.7649]]]])<jupyter_text>Feed it to the convolutional layer: the output should have 5 channels (each one is 6x6)<jupyter_code>y=mod(x)

print(y)<jupyter_output>tensor([[[[ 0.1546,  0.1761,  0.3139,  0.3329,  0.2344,  0.2403],
          [ 0.4526,  0.7836,  0.4721,  0.4402,  0.5568,  0.3465],
          [ 0.4644,  0.5815,  0.8252,  0.5368,  0.5006,  0.6490],
          [ 0.2608,  0.6508,  0.6952,  0.4918,  0.3423,  0.2017],
          [ 0.0478,  0.3647,  0.6414,  0.6108,  0.5795,  0.6324],
          [ 0.1970,  0.3411,  0.4235,  0.5146,  0.4885,  0.3434]],

         [[-0.1756, -0.1892,  0.0342,  0.0636, -0.1037,  0.0879],
          [-0.4237,  0.2110,  0.0016, -0.0115, -0.1457, -0.0481],
          [-0.3072, -0.2332,  0.0658,  0.2021, -0.2678,  0.1540],
          [-0.3314, -0.2749,  0.0221, -0.1188, -0.0806, -0.1863],
          [-0.4099, -0.1695, -0.2206,  0.0867,  0.0872,  0.0715],
          [-0.0680, -0.3594,  0.0421, -0.2217, -0.0682, -0.0914]],

         [[-0.2504, -0.2301, -0.3474, -0.3336, -0.3999, -0.2530],
          [-0.5108, -0.5159, -0.4399, -0.3622, -0.1104, -0.3336],
          [-0.4865, -0.6728, -0.3808, -0.2202, -0.5820, -0.4804],
      [...]<jupyter_text>Lets look at the 5 filters.* Our filters are 2x3x3* Each of the filter has 2 channels because the inputs have two channels<jupyter_code>mod.weight<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19946605644546148, 'fraction_numerical': 0.32036613272311215, 'mean_word_length': 2.32446134347275, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '635885', 'license': 'MIT', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1297, 'n_words': 258, 'path': 'codes/labs_lecture10/lab01_conv_layer/conv_layer_demo.ipynb', 'repo_name': 'sanjaysaha1311/Deep_Learning_CS7454_2018_NTU', 'size': '2622'}