pytorch-stuff/CNN - MNIST.ipynb

490 lines
71 KiB
Plaintext
Raw Normal View History

2020-05-02 21:40:17 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import torch.nn as nn\n",
"import torchvision.transforms as transforms\n",
"import torchvision.datasets as datasets"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"mean_gray = 0.1307\n",
"stddev_gray = 0.3081\n",
"\n",
"# input[channel] = (input[channel]-meaan[channel]) / std[channel]\n",
"\n",
"transforms = transforms.Compose([transforms.ToTensor(),\n",
" transforms.Normalize((mean_gray,),(stddev_gray,))])\n",
"\n",
"train_dataset = datasets.MNIST(root='./data', \n",
" train=True, \n",
" transform=transforms, \n",
" download=True)\n",
"\n",
"test_dataset = datasets.MNIST(root='./data', \n",
" train=False, \n",
" transform=transforms)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7fd7823b2f10>"
2020-05-02 21:40:17 +00:00
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAANr0lEQVR4nO3db6xUdX7H8c9HujwRJFBSvLK0LqvGbGrKNjdYLTE2usTyBPeBm0VtaFy9mKzJqg0tUiMas2raWh+ZNazKotmy2UR2NdBk15JVW2OIV0MFvd31lqALuUIURFcfbJFvH9yDueA9Zy4zZ+YM9/t+JTczc74z53wz4cP5O+fniBCA6e+sphsA0BuEHUiCsANJEHYgCcIOJPEHvVyYbQ79A10WEZ5sekdrdtvX2P617VHb6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2H7S9tySzwzZHrY9/e7zA5xBpnxtvO1Zkl6U9P2I2Gp7gaT3JYWk+zW+qX9Ti3mwGQ90Wdlm/JTCbvtLkrZJ+kVE/Osk9fMlbYuIP20xH8IOdFnbP4SxbUlPSBqZGPTiwN0J35S0p9MmAXTPVI7GL5P0n5J2SzpeTF4vaZWkJRrfjN8naU1xMK9qXqzZgS7raDO+LoQd6D5+zw4kR9iBJAg7kARhB5Ig7EAShB1IgrADSRB2IAnCDiRB2IEkCDuQBGEHkiDsQBKEHUii5Q0na/a+pHcmvJ5fTOtH/dpbv/Yl0Vu76uztT8oKPf09+xcWbg9HxGBjDVTo1976tS+J3trVq97YjAeSIOxAEk2HfWPDy6/Sr731a18SvbW
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"random_img = train_dataset[20][0].numpy() * stddev_gray + mean_gray\n",
"plt.imshow(random_img.reshape(28,28), cmap='gray')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
2020-05-03 18:26:33 +00:00
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
2020-05-02 21:40:17 +00:00
}
],
"source": [
"print(train_dataset[20][1])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"batch_size = 100\n",
"\n",
"train_load = torch.utils.data.DataLoader(dataset=train_dataset,\n",
" batch_size=batch_size,\n",
" shuffle=True)\n",
"\n",
"test_load = torch.utils.data.DataLoader(dataset=test_dataset,\n",
" batch_size=batch_size,\n",
" shuffle=True)\n"
]
},
{
"cell_type": "code",
2020-05-03 18:26:33 +00:00
"execution_count": 6,
2020-05-02 21:40:17 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
2020-05-03 18:26:33 +00:00
"execution_count": 6,
2020-05-02 21:40:17 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(test_load)"
]
},
{
"cell_type": "code",
"execution_count": 7,
2020-05-02 21:40:17 +00:00
"metadata": {},
"outputs": [],
2020-05-03 18:26:33 +00:00
"source": [
"class CNN(nn.Module):\n",
" def __init__(self):\n",
" super(CNN,self).__init__()\n",
" # Same padding means that input_size = output_size\n",
" # same_padding = (filter_size - 1) / 2\n",
" self.cnn1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=(3,3), stride=1, padding=1)\n",
" # The output from this layer has size:\n",
" # [(input_size - filter_size + 2*(padding)) / stride] + 1\n",
" self.batchnorm1 = nn.BatchNorm2d(8)\n",
" self.relu = nn.ReLU()\n",
" self.maxpool = nn.MaxPool2d(kernel_size=(2,2))\n",
" # Pooling output size is 28/2 = 14 (downsampling)\n",
" # Same padding size is (5 - 1)/2 = 2\n",
" self.cnn2 = nn.Conv2d(in_channels=8, out_channels=32, kernel_size=(5,5), stride=1, padding=2)\n",
" self.batchnorm2 = nn.BatchNorm2d(32)\n",
" # Pooling output size is 14/2 = 7 (downsampling)\n",
" # We have to flatten the output channels 32*7*7 = 1568\n",
" self.fc1 = nn.Linear(1568,600)\n",
" self.dropout = nn.Dropout(p=0.5)\n",
" self.fc2 = nn.Linear(600,10)\n",
" \n",
" def forward(self,x):\n",
" out = self.cnn1(x)\n",
" out = self.batchnorm1(out)\n",
" out = self.relu(out)\n",
" out = self.maxpool(out)\n",
" out = self.cnn2(out)\n",
" out = self.batchnorm2(out)\n",
" out = self.relu(out)\n",
" out = self.maxpool(out)\n",
" # we have to flatten the 32 feature maps, output of our last maxpool (100, 1568)\n",
" out = out.view(-1, 1568) # <- setting the number of rows to -1 is important, because \n",
" out = self.fc1(out) # when we try to predict we would require to use a size 100 (batch size)\n",
" out = self.relu(out) # tensor but -1 infers the size.\n",
2020-05-03 18:26:33 +00:00
" out = self.dropout(out)\n",
" out = self.fc2(out)\n",
" \n",
" return out\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"model = CNN()\n",
"\n",
"CUDA = torch.cuda.is_available()\n",
"\n",
"if CUDA:\n",
" model = model.cuda()\n",
" \n",
"loss_fn = nn.CrossEntropyLoss()\n",
"optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"For one iteration this is what happens:\n",
"Input shape: torch.Size([100, 1, 28, 28])\n",
"Labels shape: torch.Size([100])\n",
"Output shape: torch.Size([100, 10])\n",
"Predicted shape: torch.Size([100, 1, 28, 28])\n",
"Predicted tensor: \n",
"tensor([7, 9, 6, 3, 4, 9, 7, 6, 9, 9, 3, 3, 3, 5, 4, 2, 3, 9, 9, 3, 4, 6, 4, 4,\n",
" 3, 2, 9, 2, 2, 4, 9, 6, 9, 2, 4, 3, 9, 2, 4, 5, 6, 4, 9, 2, 2, 9, 2, 9,\n",
" 7, 9, 9, 6, 9, 6, 2, 6, 3, 4, 4, 2, 6, 2, 4, 6, 4, 7, 7, 4, 9, 7, 8, 9,\n",
" 6, 6, 4, 4, 8, 6, 2, 4, 8, 2, 3, 6, 4, 3, 2, 2, 8, 9, 4, 9, 3, 4, 6, 4,\n",
" 3, 4, 3, 6])\n"
]
}
],
"source": [
"# Understand what is happening\n",
"iteration = 0\n",
"correct = 0\n",
"\n",
"for i,(inputs, labels) in enumerate(train_load):\n",
" \n",
" if CUDA:\n",
" inputs = inputs.cuda()\n",
" labels = labels.cuda()\n",
" \n",
" print('For one iteration this is what happens:')\n",
" print('Input shape: ', inputs.shape)\n",
" print('Labels shape: ', labels.shape)\n",
" output = model(inputs)\n",
" print('Output shape: ', output.shape)\n",
" _, predicted = torch.max(output, dim=1)\n",
" print('Predicted shape: ', inputs.shape)\n",
" print('Predicted tensor: ')\n",
" print(predicted)\n",
" correct += (predicted==labels).sum()\n",
" break\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/10, Training loss: 1.153, Training accuracy: 0.626, Testing loss: 6.920, Testing accuracy: 0.969\n",
"Epoch 2/10, Training loss: 0.341, Training accuracy: 0.885, Testing loss: 2.045, Testing accuracy: 0.981\n",
"Epoch 3/10, Training loss: 0.156, Training accuracy: 0.954, Testing loss: 0.937, Testing accuracy: 0.985\n",
"Epoch 4/10, Training loss: 0.106, Training accuracy: 0.970, Testing loss: 0.635, Testing accuracy: 0.987\n",
"Epoch 5/10, Training loss: 0.090, Training accuracy: 0.974, Testing loss: 0.539, Testing accuracy: 0.988\n",
"Epoch 6/10, Training loss: 0.077, Training accuracy: 0.978, Testing loss: 0.461, Testing accuracy: 0.989\n",
"Epoch 7/10, Training loss: 0.071, Training accuracy: 0.980, Testing loss: 0.428, Testing accuracy: 0.988\n",
"Epoch 8/10, Training loss: 0.068, Training accuracy: 0.980, Testing loss: 0.411, Testing accuracy: 0.990\n",
"Epoch 9/10, Training loss: 0.060, Training accuracy: 0.983, Testing loss: 0.361, Testing accuracy: 0.989\n",
"Epoch 10/10, Training loss: 0.062, Training accuracy: 0.982, Testing loss: 0.372, Testing accuracy: 0.990\n"
]
},
{
"data": {
"text/plain": [
"\"\\n\\n#Training the CNN\\nnum_epochs = 10\\n\\n#Define the lists to store the results of loss and accuracy\\ntrain_loss = []\\ntest_loss = []\\ntrain_accuracy = []\\ntest_accuracy = []\\n\\n#Training\\nfor epoch in range(num_epochs): \\n #Reset these below variables to 0 at the begining of every epoch\\n correct = 0\\n iterations = 0\\n iter_loss = 0.0\\n \\n model.train() # Put the network into training mode\\n \\n for i, (inputs, labels) in enumerate(train_load):\\n \\n if CUDA:\\n inputs = inputs.cuda()\\n labels = labels.cuda()\\n \\n outputs = model(inputs) \\n loss = loss_fn(outputs, labels) \\n iter_loss += loss.item() # Accumulate the loss\\n optimizer.zero_grad() # Clear off the gradient in (w = w - gradient)\\n loss.backward() # Backpropagation \\n optimizer.step() # Update the weights\\n \\n # Record the correct predictions for training data \\n _, predicted = torch.max(outputs, 1)\\n correct += (predicted == labels).sum()\\n iterations += 1\\n \\n # Record the training loss\\n train_loss.append(iter_loss/iterations)\\n # Record the training accuracy\\n train_accuracy.append((100 * correct / len(train_dataset)))\\n \\n #Testing\\n testing_loss = 0.0\\n correct = 0\\n iterations = 0\\n\\n model.eval() # Put the network into evaluation mode\\n \\n for i, (inputs, labels) in enumerate(test_load):\\n\\n if CUDA:\\n inputs = inputs.cuda()\\n labels = labels.cuda()\\n \\n outputs = model(inputs) \\n loss = loss_fn(outputs, labels) # Calculate the loss\\n testing_loss += loss.item()\\n # Record the correct predictions for training data\\n _, predicted = torch.max(outputs, 1)\\n correct += (predicted == labels).sum()\\n \\n iterations += 1\\n\\n # Record the Testing loss\\n test_loss.append(testing_loss/iterations)\\n # Record the Testing accuracy\\n test_accuracy.append((100 * correct / len(test_dataset)))\\n \\n print ('Epoch {}/{}, Training Loss: {:.3f}, Training Accuracy: {:.3f}, Testing Loss: {:.3f}, Testing Acc: {:.3f}'\\n .format(epoch+1, num_epochs, train_loss[-1], train_accuracy[-1], \\n test_loss[-1], test_accuracy[-1]))\\n\""
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Training of the CNN\n",
"num_epochs = 10\n",
"train_loss = list()\n",
"train_accuracy = list()\n",
"test_loss = list()\n",
"test_accuracy = list()\n",
"\n",
"\n",
"for epoch in range(num_epochs):\n",
" correct = 0\n",
" iterations = 0\n",
" iter_loss = 0.0\n",
" \n",
" # When batch normalization and dropout are used\n",
" # we have to specify our model that we are training\n",
" model.train()\n",
" \n",
" for i,(inputs, labels) in enumerate(train_load):\n",
" \n",
" if CUDA:\n",
" inputs = inputs.cuda()\n",
" labels = labels.cuda()\n",
" \n",
" outputs = model(inputs)\n",
" loss = loss_fn(outputs,labels)\n",
" iter_loss += loss.item()\n",
" \n",
" optimizer.zero_grad()\n",
" loss.backward()\n",
" optimizer.step()\n",
" \n",
" _, predicted = torch.max(outputs, dim=1)\n",
" correct += (predicted==labels).sum().item()\n",
" iterations += 1\n",
" \n",
" train_loss.append(iter_loss/iterations)\n",
" train_accuracy.append(correct/len(train_dataset))\n",
" \n",
" # Testing phase\n",
" testing_loss = 0.0\n",
" correct = 0\n",
" iterations = 0\n",
" \n",
" model.eval()\n",
" \n",
" for i,(inputs, labels) in enumerate(test_load):\n",
" \n",
" if CUDA:\n",
" inputs = inputs.cuda()\n",
" labels = labels.cuda()\n",
" \n",
" outputs = model(inputs)\n",
" loss = loss_fn(outputs,labels)\n",
" testing_loss += loss.item()\n",
" \n",
" _, predicted = torch.max(outputs, dim=1)\n",
" correct += (predicted==labels).sum().item()\n",
" iterations += 1\n",
" \n",
" test_loss.append(iter_loss/iterations)\n",
" test_accuracy.append(correct/len(test_dataset))\n",
" \n",
" print('Epoch {}/{}, Training loss: {:.3f}, Training accuracy: {:.3f}, Testing loss: {:.3f}, Testing accuracy: {:.3f}'.format(\n",
" epoch+1,num_epochs,train_loss[-1],train_accuracy[-1],test_loss[-1],test_accuracy[-1]))\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkkAAAI/CAYAAABj+03oAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3deZicVYH2//tUdfWS7iTdSZWEJGQhpCtkIyFNWKIYEBEGGCOKAwYElU0ZIjoOMHo5ojPvb3CG36j4ykBARlQGZARBEB0FQXDYspBACIkhC2QDOp2kl6SXWs77x1PV6e5Uuqu6q/rU8v1cV1+19FNVNyklN+c5zznGWisAAAD05nMdAAAAIB9RkgAAAFKgJAEAAKRASQIAAEiBkgQAAJACJQkAACCFsly8aTAYtFOmTMnFWwM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gDjMxk+h0Ubkny+aSxx0mNG1wnAQCgX5WVlWpqaqIoOWStVVNTkyorK9N+TeHOSZK8eUnvvOQ6BQAA/Zo4caJ27NihxsZG11FKWmVlpSZOTH+njsIuScGw9Pp/S51tUkWN6zQAAKQUCAQ0depU1zGQocI93SZ5G91KUtMmtzkAAEDRKeyS1L3RLZO3AQBAdhV2SRpzrGT8LAMAAACyrrBLUlm5V5TY6BYAAGRZYZckiY1uAQBAThRHSdq7RYpFXCcBAABFpPBLUjAsxaNeUQIAAMiSwi9
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Plotting the loss\n",
"\n",
"f = plt.figure(figsize=(10,10))\n",
"plt.plot(train_loss, label='Training loss')\n",
"plt.plot(test_loss, label='Testing loss')\n",
"plt.legend()\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlkAAAI/CAYAAABEVcwAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzde3ycdZ3//fcnM5nJOW1z6PnccihCT7EorFJEpIrK4iILq7dn0V3Rx+r6U1wRENbf7j5+ez9UdlUWbxH13l1W2BWrotycqigopAIuLYdOSrHpaabpIZkc5/C9/5hJMkmTZpJMcs3h9Xw85jHXXIeZT1LKvPu9Ptf3MuecAAAAkFtlXhcAAABQjAhZAAAAM4CQBQAAMAMIWQAAADOAkAUAADADCFkAAAAzwO91AaM1Nja6FStWeF0GAADAhHbu3HnUOdc01ra8C1krVqxQa2ur12UAAABMyMxeHW8bpwsBAABmACELAABgBhCyAAAAZgAhCwAAYAYQsgAAAGYAIQsAAGAGTBiyzOwuM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6mh6uas/fsrxZlJDdVBNtUE11wZ1xvxaNdUG1VQzvK6pNqjG2qBqAn6VlXHaCShVhCyvJJPSoWeGG9bbn5ZcUqqol1ZdnApVay5JNakDmFC0Pz5itCnS1XfKiFO4q18d0f4xe5Rqgv6hsHT2wjq98YxUWBp8DIaneVUBRpEAZIWQNZuiYant0VSoantU6umQZNKijdIbPpsKVos3M2EnkBZPJNXRPaBw58Sn7MbqafKXmRrTI0zz6yr0mkX1aq4
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Plotting the accuracy\n",
"\n",
"f = plt.figure(figsize=(10,10))\n",
"plt.plot(train_accuracy, label='Training accuracy')\n",
"plt.plot(test_accuracy, label='Testing accuracy')\n",
"plt.legend()\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prediction is: 1\n",
"Actual label is: 1\n"
]
}
],
"source": [
"img = test_dataset[31][0].resize_((1,1,28,28))\n",
"label = test_dataset[31][1]\n",
"\n",
"model.eval()\n",
"\n",
"if CUDA:\n",
" model = model.cuda()\n",
" img = img.cuda()\n",
" \n",
"output = model(img)\n",
"_, predicted = torch.max(output, dim=1)\n",
"print('Prediction is: {}'.format(predicted.item()))\n",
"print('Actual label is: {}'.format(label))\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7fd77db5b250>"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGli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Wo2tiNB5Ig7EASbYd9rOXPLzOstQ1rXRK19WsgtbV6zA5gcNoe2QEMCGEHkmgl7LZvtf2e7QO2H2yjhm5sH7T9ru2dba9PV6yhd8z27kltl9rebHt/cTvlGnst1bbW9uFi2+20vayl2ubafsv2Xtt7bN9ftLe67UrqGsh2G/gxu+0Zkt6XdLOkQ5K2S1oZEXsHWkgXtg9KWhQRrX8Bw/ZSSZ9Leu700lq2/yDpeEQ8VvxHOSsifjMkta3VWS7j3VBt3ZYZ/6Va3HZ1Ln/ejzZG9sWSDkTEBxHxpaQXJS1voY6hFxFbJR0/o3m5pPXF/fXq/GMZuC61DYWIOBIRO4r7JySdXma81W1XUtdAtBH2yyR9POnxIQ3Xeu8h6U3b79gebbuYKYxMWmbrE0kjbRYzhZ7LeA/SGcuMD82262f586o4QfdtSyJioaRfSLq32F0dStE5BhumudMnJV2lzhqARyQ93mYxxTLjL0t6ICI+m9zX5raboq6BbLc2wn5Y0txJjy8v2oZCRBwubo9J2qDOYccwOXp6Bd3i9ljL9XwtIo5GxEREnJK0Ti1uu2KZ8ZclPR8RrxTNrW+7qeoa1HZrI+zbJV1t+0rbF0q6U9KmFur4FtszixMnsj1T0i0
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"random_img = test_dataset[31][0].numpy() * stddev_gray + mean_gray\n",
"plt.imshow(random_img.reshape(28,28), cmap='gray')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
2020-05-02 21:40:17 +00:00
}
],
"metadata": {
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}