"We will scale these values to a range of 0 to 1 before feeding to the neural network model. For this, cast the datatype of the image components from and integer to a float, and divide by 255. Here's the function to preprocess the images:"
"We will scale these values to a range of 0 to 1 before feeding to the neural network model. For this, cast the datatype of the image components from and integer to a float, and divide by 255. Here's the function to preprocess the images:"
]
]
},
},
{
"metadata": {
"id": "DSD9qKcqCaWs",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"def preprocess(images):\n",
" images = images.astype(np.float32)\n",
" images = images / 255\n",
" return images"
],
"execution_count": 0,
"outputs": []
},
{
{
"metadata": {
"metadata": {
"id": "3jCZdQNNCaWv",
"id": "3jCZdQNNCaWv",
...
@@ -453,13 +496,18 @@
...
@@ -453,13 +496,18 @@
"metadata": {
"metadata": {
"id": "bW5WzIPlCaWv",
"id": "bW5WzIPlCaWv",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
"train_images = preprocess(train_images)\n",
"train_images = train_images / 255.0\n",
"\n",
"\n",
"test_images = preprocess(test_images)"
"test_images = test_images / 255.0"
],
],
"execution_count": 0,
"execution_count": 0,
"outputs": []
"outputs": []
...
@@ -478,7 +526,12 @@
...
@@ -478,7 +526,12 @@
"metadata": {
"metadata": {
"id": "oZTImqg_CaW1",
"id": "oZTImqg_CaW1",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -527,7 +580,12 @@
...
@@ -527,7 +580,12 @@
"metadata": {
"metadata": {
"id": "9ODch-OFCaW4",
"id": "9ODch-OFCaW4",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -564,7 +622,12 @@
...
@@ -564,7 +622,12 @@
"metadata": {
"metadata": {
"id": "Lhan11blCaW7",
"id": "Lhan11blCaW7",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -597,7 +660,12 @@
...
@@ -597,7 +660,12 @@
"metadata": {
"metadata": {
"id": "xvwvpA64CaW_",
"id": "xvwvpA64CaW_",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -632,7 +700,12 @@
...
@@ -632,7 +700,12 @@
"metadata": {
"metadata": {
"id": "VflXLEeECaXC",
"id": "VflXLEeECaXC",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -669,7 +742,12 @@
...
@@ -669,7 +742,12 @@
"metadata": {
"metadata": {
"id": "Gl91RPhdCaXI",
"id": "Gl91RPhdCaXI",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -692,7 +770,12 @@
...
@@ -692,7 +770,12 @@
"metadata": {
"metadata": {
"id": "3DmJEUinCaXK",
"id": "3DmJEUinCaXK",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -715,7 +798,12 @@
...
@@ -715,7 +798,12 @@
"metadata": {
"metadata": {
"id": "qsqenuPnCaXO",
"id": "qsqenuPnCaXO",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -738,7 +826,12 @@
...
@@ -738,7 +826,12 @@
"metadata": {
"metadata": {
"id": "Sd7Pgsu6CaXP",
"id": "Sd7Pgsu6CaXP",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -761,7 +854,12 @@
...
@@ -761,7 +854,12 @@
"metadata": {
"metadata": {
"id": "YGBDAiziCaXR",
"id": "YGBDAiziCaXR",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -802,7 +900,12 @@
...
@@ -802,7 +900,12 @@
"metadata": {
"metadata": {
"id": "yRJ7JU7JCaXT",
"id": "yRJ7JU7JCaXT",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -828,7 +931,12 @@
...
@@ -828,7 +931,12 @@
"metadata": {
"metadata": {
"id": "lDFh5yF_CaXW",
"id": "lDFh5yF_CaXW",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -854,7 +962,12 @@
...
@@ -854,7 +962,12 @@
"metadata": {
"metadata": {
"id": "o_rzNSdrCaXY",
"id": "o_rzNSdrCaXY",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -879,7 +992,12 @@
...
@@ -879,7 +992,12 @@
"metadata": {
"metadata": {
"id": "2tRmdq_8CaXb",
"id": "2tRmdq_8CaXb",
"colab_type": "code",
"colab_type": "code",
"colab": {}
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
},
"cell_type": "code",
"cell_type": "code",
"source": [
"source": [
...
@@ -899,19 +1017,6 @@
...
@@ -899,19 +1017,6 @@
"source": [
"source": [
"And, as before, the model predicts a label of 9."
"And, as before, the model predicts a label of 9."