{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0b29241f-af29-4bca-709e-472194216479"},"outputs":[],"source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"cd6144e1-89df-ccb5-6938-67195a31bec4"},"outputs":[],"source":"import torch.nn as nn"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fe8f5cde-c8d5-f9fe-3a35-2b6dd5d126a1"},"outputs":[],"source":"import torch\nfrom torch.autograd import Variable\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass Net(nn.Module):\n\n    def __init__(self):\n        super(Net, self).__init__()\n        # 1 input image channel, 6 output channels, 5x5 square convolution\n        # kernel\n        self.conv1 = nn.Conv2d(1, 6, 5)\n        self.conv2 = nn.Conv2d(6, 16, 5)\n        # an affine operation: y = Wx + b\n        self.fc1 = nn.Linear(16 * 5 * 5, 120)\n        self.fc2 = nn.Linear(120, 84)\n        self.fc3 = nn.Linear(84, 10)\n\n    def forward(self, x):\n        # Max pooling over a (2, 2) window\n        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))\n        # If the size is a square you can only specify a single number\n        x = F.max_pool2d(F.relu(self.conv2(x)), 2)\n        x = x.view(-1, self.num_flat_features(x))\n        x = F.relu(self.fc1(x))\n        x = F.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n\n    def num_flat_features(self, x):\n        size = x.size()[1:]  # all dimensions except the batch dimension\n        num_features = 1\n        for s in size:\n            num_features *= s\n        return num_features"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b6e927f2-0bbd-9631-3504-2b3c08aadcfd"},"outputs":[],"source":"net = Net()\nprint(net)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"37995002-e2bf-941b-a8b0-d105c358d856"},"outputs":[],"source":"params = list(net.parameters())\nprint(len(params))\nprint(params[0].size())  # conv1's .weight"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"72db6c1a-ae60-0e67-0b4b-ec1167a1d6fe"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.0"}},"nbformat":4,"nbformat_minor":0}