Skip to content

Commit 8b6697b

Browse files
authored
Add files via upload
1 parent 1e992de commit 8b6697b

File tree

1 file changed

+193
-0
lines changed

1 file changed

+193
-0
lines changed

convolutional neural networks.ipynb

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Common imports\n",
10+
"import numpy as np\n",
11+
"import os\n",
12+
"\n",
13+
"# to make this notebook's output stable across runs\n",
14+
"def reset_graph(seed=42):\n",
15+
" tf.reset_default_graph()\n",
16+
" tf.set_random_seed(seed)\n",
17+
" np.random.seed(seed)\n",
18+
"\n",
19+
"# To plot pretty figures\n",
20+
"%matplotlib inline\n",
21+
"import matplotlib\n",
22+
"import matplotlib.pyplot as plt\n",
23+
"plt.rcParams['axes.labelsize'] = 14\n",
24+
"plt.rcParams['xtick.labelsize'] = 12\n",
25+
"plt.rcParams['ytick.labelsize'] = 12\n",
26+
"\n",
27+
"# Where to save the figures\n",
28+
"PROJECT_ROOT_DIR = \".\"\n",
29+
"CHAPTER_ID = \"cnn\"\n",
30+
"\n",
31+
"def save_fig(fig_id, tight_layout=True):\n",
32+
" path = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID, fig_id + \".png\")\n",
33+
" print(\"Saving figure\", fig_id)\n",
34+
" if tight_layout:\n",
35+
" plt.tight_layout()\n",
36+
" plt.savefig(path, format='png', dpi=300)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 3,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"def plot_image(image):\n",
46+
" plt.imshow(image, cmap=\"gray\", interpolation=\"nearest\")\n",
47+
" plt.axis(\"off\")\n",
48+
"\n",
49+
"def plot_color_image(image):\n",
50+
" plt.imshow(image.astype(np.uint8),interpolation=\"nearest\")\n",
51+
" plt.axis(\"off\")"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 4,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"import tensorflow as tf"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"metadata": {},
66+
"source": [
67+
"# Convolutional layer"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 7,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"ename": "ImportError",
77+
"evalue": "The Python Imaging Library (PIL) is required to load data from jpeg files",
78+
"output_type": "error",
79+
"traceback": [
80+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
81+
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
82+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 748\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 749\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 750\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
83+
"\u001b[1;31mImportError\u001b[0m: cannot import name 'imread'",
84+
"\nDuring handling of the above exception, another exception occurred:\n",
85+
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
86+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\scipy\\misc\\pilutil.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mPIL\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mImage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mImageFilter\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 20\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
87+
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'PIL'",
88+
"\nDuring handling of the above exception, another exception occurred:\n",
89+
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
90+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 750\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 751\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpilutil\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 752\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
91+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\scipy\\misc\\pilutil.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mImage\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mImageFilter\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
92+
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'Image'",
93+
"\nDuring handling of the above exception, another exception occurred:\n",
94+
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
95+
"\u001b[1;32m<ipython-input-7-ee76aeb5563a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdatasets\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mload_sample_image\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mchina\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mload_sample_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"china.jpg\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mflower\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mload_sample_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"flower.jpg\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mimage\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mchina\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m150\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m220\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m130\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m250\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mheight\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwidth\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchannels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mimage\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
96+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_image\u001b[1;34m(image_name)\u001b[0m\n\u001b[0;32m 795\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m427\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m640\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 796\u001b[0m \"\"\"\n\u001b[1;32m--> 797\u001b[1;33m \u001b[0mimages\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mload_sample_images\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 798\u001b[0m \u001b[0mindex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 799\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilename\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimages\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfilenames\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
97+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 751\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpilutil\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 752\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 753\u001b[1;33m raise ImportError(\"The Python Imaging Library (PIL) \"\n\u001b[0m\u001b[0;32m 754\u001b[0m \"is required to load data from jpeg files\")\n\u001b[0;32m 755\u001b[0m \u001b[0mmodule_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdirname\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m__file__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"images\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
98+
"\u001b[1;31mImportError\u001b[0m: The Python Imaging Library (PIL) is required to load data from jpeg files"
99+
]
100+
}
101+
],
102+
"source": [
103+
"from sklearn.datasets import load_sample_image\n",
104+
"china = load_sample_image(\"china.jpg\")\n",
105+
"flower = load_sample_image(\"flower.jpg\")\n",
106+
"image = china[150:220, 130:250]\n",
107+
"height, width, channels = image.shape\n",
108+
"image_grayscale = image.mean(axis=2).astype(np.float32)\n",
109+
"images = image_grayscale.reshape(1, height, width, 1)"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 5,
115+
"metadata": {},
116+
"outputs": [
117+
{
118+
"ename": "ImportError",
119+
"evalue": "The Python Imaging Library (PIL) is required to load data from jpeg files",
120+
"output_type": "error",
121+
"traceback": [
122+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
123+
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
124+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 748\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 749\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 750\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
125+
"\u001b[1;31mImportError\u001b[0m: cannot import name 'imread'",
126+
"\nDuring handling of the above exception, another exception occurred:\n",
127+
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
128+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\scipy\\misc\\pilutil.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mPIL\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mImage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mImageFilter\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 20\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
129+
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'PIL'",
130+
"\nDuring handling of the above exception, another exception occurred:\n",
131+
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
132+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 750\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 751\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpilutil\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 752\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
133+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\scipy\\misc\\pilutil.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mImage\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mImageFilter\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
134+
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'Image'",
135+
"\nDuring handling of the above exception, another exception occurred:\n",
136+
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
137+
"\u001b[1;32m<ipython-input-5-3397ea3700fa>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdatasets\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mload_sample_images\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mdataset\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mload_sample_images\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mimages\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheight\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwidth\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchannels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdataset\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
138+
"\u001b[1;32mc:\\users\\zhuowu\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\sklearn\\datasets\\base.py\u001b[0m in \u001b[0;36mload_sample_images\u001b[1;34m()\u001b[0m\n\u001b[0;32m 751\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmisc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpilutil\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimread\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 752\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mImportError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 753\u001b[1;33m raise ImportError(\"The Python Imaging Library (PIL) \"\n\u001b[0m\u001b[0;32m 754\u001b[0m \"is required to load data from jpeg files\")\n\u001b[0;32m 755\u001b[0m \u001b[0mmodule_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdirname\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m__file__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"images\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
139+
"\u001b[1;31mImportError\u001b[0m: The Python Imaging Library (PIL) is required to load data from jpeg files"
140+
]
141+
}
142+
],
143+
"source": [
144+
"import numpy as np\n",
145+
"from sklearn.datasets import load_sample_images\n",
146+
"\n",
147+
"dataset = np.array(load_sample_images().images, dtype=np.float32)\n",
148+
"batch_size, height, width, channels = dataset.shape\n",
149+
"\n",
150+
"filters_test = np.zeros(shape=(7, 7, channels, 2), dtype=np.float32)\n",
151+
"filters_test[:, 3, :, 0] = 1 #vertical lines\n",
152+
"filters_test[3, :, :, 1] = 1\n",
153+
"\n",
154+
"X = tf.placeholder(tf.float32, shape=(None, height, width, channels))\n",
155+
"convolution = tf.nn.conv2d(X, filters, strides=[1, 2, 2, 1], padding=\"SAME\")\n",
156+
"\n",
157+
"with tf.session() as sess:\n",
158+
" output = sess.run(convolution, feed_dict={X:dataset})\n",
159+
" \n",
160+
"plt.imshow(output[0, :, :, 1])\n",
161+
"plt.show()"
162+
]
163+
},
164+
{
165+
"cell_type": "code",
166+
"execution_count": null,
167+
"metadata": {},
168+
"outputs": [],
169+
"source": []
170+
}
171+
],
172+
"metadata": {
173+
"kernelspec": {
174+
"display_name": "Python 3",
175+
"language": "python",
176+
"name": "python3"
177+
},
178+
"language_info": {
179+
"codemirror_mode": {
180+
"name": "ipython",
181+
"version": 3
182+
},
183+
"file_extension": ".py",
184+
"mimetype": "text/x-python",
185+
"name": "python",
186+
"nbconvert_exporter": "python",
187+
"pygments_lexer": "ipython3",
188+
"version": "3.6.4"
189+
}
190+
},
191+
"nbformat": 4,
192+
"nbformat_minor": 2
193+
}

0 commit comments

Comments
 (0)