<jupyter_start><jupyter_text>Lab 01 : Convolutional layer - demo<jupyter_code>import sys, os
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)

print(x.size())<jupyter_output>tensor([[[[0.1800, 0.4481, 0.0222, 0.5479, 0.9021, 0.0836],
          [0.9588, 0.5581, 0.4469, 0.6814, 0.0144, 0.1114],
          [0.7085, 0.2309, 0.2188, 0.4994, 0.2918, 0.8046],
          [0.2780, 0.1227, 0.8891, 0.0351, 0.6444, 0.7535],
          [0.5478, 0.5258, 0.9977, 0.0142, 0.7971, 0.7752],
          [0.3204, 0.0682, 0.7594, 0.8868, 0.0788, 0.4538]],

         [[0.3223, 0.2892, 0.8536, 0.7549, 0.5476, 0.3034],
          [0.9968, 0.3163, 0.0535, 0.4807, 0.7006, 0.4321],
          [0.8208, 0.1558, 0.0807, 0.4571, 0.5831, 0.6091],
          [0.1431, 0.6383, 0.5595, 0.5073, 0.3690, 0.1102],
          [0.2844, 0.4439, 0.1170, 0.5130, 0.1477, 0.1951],
          [0.1327, 0.7202, 0.6545, 0.4333, 0.1673, 0.1305]]]])
torch.Size([1, 2, 6, 6])<jupyter_text>Feed it to the convolutional layer: the output should have 5 channels (each one is 6 x 6)<jupyter_code>y = mod(x)

print(y)

print(y.size())<jupyter_output>tensor([[[[-5.0214e-02, -1.6885e-01, -1.9739e-02, -3.2235e-01, -1.4638e-01,
           -1.7938e-01],
          [-7.7634e-02, -5.3847e-01, -2.0822e-01, -1.1092e-01, -8.0369e-02,
           -2.0612e-01],
          [-3.0847e-01, -5.2911e-05, -3.3002e-01, -1.9820e-01, -8.7496e-02,
           -3.0322e-01],
          [-2.1641e-01,  7.4030e-02, -3.7966e-01, -8.3681e-02, -3.4827e-01,
           -3.2666e-01],
          [-3.8478e-01, -6.0934e-02, -3.4827e-01, -4.5648e-02, -3.8941e-01,
           -1.9282e-01],
          [-2.6823e-01, -4.3397e-02, -5.0612e-01,  2.0322e-02, -2.8528e-01,
           -2.4372e-01]],

         [[-1.6191e-01, -1.2152e-01,  5.5644e-03,  4.7570e-02,  2.4619e-01,
            5.4768e-02],
          [ 2.9460e-01,  7.0987e-02,  2.7971e-01,  4.5939e-01, -1.0503e-02,
           -2.1390e-01],
          [ 4.3717e-01, -1.8726e-01, -1.0233e-01,  1.1599e-01,  2.3424e-03,
            1.3349e-01],
          [ 2.8979e-02, -2.5080e-01,  1.3288e-01, -3.9837e-02, -4.7513e-02,
           -1[...]<jupyter_text>Let's look at the 5 filters- Our filters are 2x3x3- Each of the filter has 2 channels because the inputs have two channels<jupyter_code>print(mod.weight)

print(mod.weight.size())<jupyter_output>Parameter containing:
tensor([[[[ 0.1501, -0.1803,  0.0879],
          [ 0.1463, -0.0292, -0.1119],
          [ 0.0211, -0.0780,  0.1634]],

         [[-0.0016,  0.0037, -0.1901],
          [-0.1811,  0.1516,  0.1060],
          [-0.1344,  0.1357, -0.0447]]],


        [[[-0.1410, -0.2192,  0.0304],
          [ 0.0738,  0.1770, -0.1051],
          [-0.0656, -0.2150, -0.1832]],

         [[ 0.0678,  0.2014,  0.2044],
          [-0.1493,  0.2258,  0.0168],
          [-0.0076, -0.0038,  0.2195]]],


        [[[ 0.1619,  0.0322, -0.0492],
          [-0.0293,  0.1560, -0.1539],
          [ 0.0092, -0.0233,  0.0960]],

         [[ 0.0538,  0.0075,  0.1085],
          [-0.0267,  0.2116, -0.0580],
          [-0.2115,  0.2208,  0.2294]]],


        [[[-0.0446, -0.1556, -0.2076],
          [-0.0482,  0.0441,  0.1045],
          [ 0.0030, -0.0671,  0.1662]],

         [[ 0.1336,  0.0812, -0.2059],
          [ 0.1348,  0.0542, -0.0422],
          [ 0.0877, -0.1957,  0.2332]]],


        [[[-0.1899[...]
{'fraction_non_alphanumeric': 0.2139209889814566, 'fraction_numerical': 0.3147003493684493, 'mean_word_length': 1.865280985373364, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '144240', 'license': 'MIT', 'n_tokens_mistral': 2431, 'n_tokens_neox': 1831, 'n_words': 318, 'path': 'codes/labs_lecture08/lab01_conv_layer/conv_layer_demo_alan.ipynb', 'repo_name': 'alanwuha/CE7454_2019', 'size': '3721'}