{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"06d1ce7704d62dc4c1c9b87b9adb966e0f8a263f"},"cell_type":"code","source":"import pickle\n\nwith open(\"../input/example-audio/hi2.pickle\", \"rb\") as f:\n    data = pickle.load(f)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"95d9cde51b45fe87a5a1bb94cae3096df5a98f56"},"cell_type":"code","source":"data.iloc[1000,:]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b62cfeaee11f95cdcb941e3b519e3eabfb2ccddc"},"cell_type":"code","source":"with open(\"../input/example-audio/hi3.pickle\", \"rb\") as f:\n    data2 = pickle.load(f)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c76f3b54d8280c49e5e2e4557f51ca7fd037430c"},"cell_type":"code","source":"data2.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d9227e612e8e417ec54c51d8342abee1d908663e"},"cell_type":"code","source":"temp = []\nfor i in range(4195):\n    try:\n        temp.append([data[(0+i*1001):(1001+i*1001)].values])\n    except:\n        temp.append([data[(0+i*1001):].values])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"70308126f8f32b6add97a999c32ae87bc6ce42f4"},"cell_type":"code","source":"del(data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"37281b90b6e992fdc33e80a9bd2de8118fab5d70"},"cell_type":"code","source":"import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.autograd import Variable as V\nfrom torch.utils.data import Dataset, DataLoader\nimport torchvision.transforms as transforms","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2960c07d0d4a5056130979378e647a7982e637b9"},"cell_type":"code","source":"class gym(Dataset):\n    def __init__(self, data, data2, transform=None):\n        self.len = len(data)\n        #temp = temp.reshape(-1, )\n        self.x_data = torch.from_numpy(np.array(data)).float()\n        self.y_data = torch.from_numpy(data2.values).float()\n        self.transform = transform\n        \n    def __getitem__(self, index):\n        x = self.x_data[index]\n        if self.transform:\n            x = self.transform(x)\n        y = self.y_data[index]\n        return x, y\n    \n    def __len__(self):\n        return self.len\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c0f39353697712bd94c426dd7195749cab0c2142"},"cell_type":"code","source":"transform = transforms.Compose([transforms.ToTensor(),\n                                transforms.Normalize((0.5,0.5), (0.5,0.5))])\ndat = gym(temp, data2)\ntrainloader = DataLoader(dataset = dat, batch_size = 32)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fe0c8e6fb74cc7f8ddb9c77c2c2f2a7a5a030179"},"cell_type":"code","source":"class cnnn(nn.Module):\n    def __init__(self):\n        super(cnnn, self).__init__()\n        self.conv1 = nn.Conv2d(1,6,5)\n        self.conv1bn = nn.BatchNorm2d(6)\n        self.conv2 = nn.Conv2d(6,8,5)\n        self.conv2bn = nn.BatchNorm2d(8)\n        self.fc1 = nn.Linear(67184, 120)\n        self.fc2 = nn.Linear(120, 1)\n        \n    def forward(self, x):\n        x = F.relu(self.conv1bn(F.max_pool2d(self.conv1(x), (2,2))))\n        x = F.relu(self.conv2bn(F.max_pool2d(self.conv2(x), 2)))\n        x = x.view(-1, self.num_flat_features(x))\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        return x\n    \n    def num_flat_features(self,x):\n        size = x.size()[1:]\n        num_features = 1\n        for s in size:\n            num_features *= s\n        return num_features\n    \nmodel = cnnn()\ncriteria = torch.nn.MSELoss(size_average=False)\noptimizer = torch.optim.Adam(model.parameters(), lr = 1e-4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2072235dd00fc4577e336cdaab1c3f3d7a7d4eac"},"cell_type":"code","source":"from tqdm import tqdm_notebook as tqdm\ngraph = []\nfor t in tqdm(range(3)):\n    for i, datas in enumerate(trainloader):\n        In, label = datas\n        #In = In.view(In.shape[0], 1, )\n        In, label = V(In), V(label)\n        y_pred = model(In)\n        loss = criteria(y_pred, label)\n        graph.append(loss.item())\n        optimizer.zero_grad()\n        loss.backward()\n        optimizer.step()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2faeef5a0242e65eb3404ea9ba91fa73663b9656"},"cell_type":"code","source":"%matplotlib inline\nimport matplotlib.pyplot as plt\nplt.plot(np.arange(len(graph)), graph)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fafe9322cb7ef15c0b84b401f3b502fb38e62cfa"},"cell_type":"code","source":"temp[4][0].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7d675058aa7046371320360feeddbc7cddbda235"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}