Skip to content

Commit dfd5c56

Browse files
committed
LM
1 parent 4f6b955 commit dfd5c56

8 files changed

+955
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 1
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 1
6+
}

CNN Tensorflow.ipynb

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline\n",
12+
"import matplotlib.pyplot as plt\n",
13+
"import tensorflow as tf\n",
14+
"import numpy as np\n",
15+
"from sklearn.metrics import confusion_matrix\n",
16+
"import time\n",
17+
"from datetime import timedelta\n",
18+
"import math"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"metadata": {
25+
"collapsed": true
26+
},
27+
"outputs": [],
28+
"source": [
29+
"filter_size1 = 5\n",
30+
"num_filters1 = 16\n",
31+
"filter_size2 = 5\n",
32+
"num_filters2 = 36\n",
33+
"fc_size = 128\n",
34+
"train_batch_size = 64\n",
35+
"test_batch_size = 256\n",
36+
"total_iterations = 500"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 3,
42+
"metadata": {
43+
"collapsed": true
44+
},
45+
"outputs": [],
46+
"source": [
47+
"img_size = 28\n",
48+
"img_size_flat = img_size * img_size\n",
49+
"img_shape = (img_size, img_size)\n",
50+
"num_channels = 1\n",
51+
"num_classes = 10"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 4,
57+
"metadata": {
58+
"collapsed": false
59+
},
60+
"outputs": [
61+
{
62+
"name": "stdout",
63+
"output_type": "stream",
64+
"text": [
65+
"Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.\n",
66+
"Extracting data/MNIST/train-images-idx3-ubyte.gz\n",
67+
"Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.\n",
68+
"Extracting data/MNIST/train-labels-idx1-ubyte.gz\n",
69+
"Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.\n",
70+
"Extracting data/MNIST/t10k-images-idx3-ubyte.gz\n",
71+
"Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.\n",
72+
"Extracting data/MNIST/t10k-labels-idx1-ubyte.gz\n",
73+
"Size of:\n",
74+
"- Training-set:\t\t55000\n",
75+
"- Test-set:\t\t10000\n",
76+
"- Validation-set:\t5000\n"
77+
]
78+
}
79+
],
80+
"source": [
81+
"from tensorflow.examples.tutorials.mnist import input_data\n",
82+
"data = input_data.read_data_sets('data/MNIST/', one_hot=True)\n",
83+
"print(\"Size of:\")\n",
84+
"print(\"- Training-set:\\t\\t{}\".format(len(data.train.labels)))\n",
85+
"print(\"- Test-set:\\t\\t{}\".format(len(data.test.labels)))\n",
86+
"print(\"- Validation-set:\\t{}\".format(len(data.validation.labels)))"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 6,
92+
"metadata": {
93+
"collapsed": true
94+
},
95+
"outputs": [],
96+
"source": [
97+
"def plot_images(images, cls_true, cls_pred=None):\n",
98+
" assert len(images) == len(cls_true) == 9\n",
99+
" fig, axes = plt.subplots(3, 3)\n",
100+
" fig.subplots_adjust(hspace=0.3, wspace=0.3)\n",
101+
" for i, ax in enumerate(axes.flat):\n",
102+
" ax.imshow(images[i].reshape(img_shape), cmap='binary')\n",
103+
" if cls_pred is None:\n",
104+
" xlabel = \"True: {0}\".format(cls_true[i])\n",
105+
" else:\n",
106+
" xlabel = \"True: {0}, Pred: {1}\".format(cls_true[i], cls_pred[i])\n",
107+
" ax.set_xlabel(xlabel)\n",
108+
" ax.set_xticks([])\n",
109+
" ax.set_yticks([])\n",
110+
" plt.show()"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": 7,
116+
"metadata": {
117+
"collapsed": false
118+
},
119+
"outputs": [
120+
{
121+
"ename": "AttributeError",
122+
"evalue": "'DataSet' object has no attribute 'cls'",
123+
"output_type": "error",
124+
"traceback": [
125+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
126+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
127+
"\u001b[0;32m<ipython-input-7-39a5a64b8825>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mimages\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mimages\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m9\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mcls_true\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcls\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m9\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mplot_images\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimages\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mimages\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcls_true\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcls_true\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
128+
"\u001b[0;31mAttributeError\u001b[0m: 'DataSet' object has no attribute 'cls'"
129+
]
130+
}
131+
],
132+
"source": [
133+
"images = data.test.images[0:9]\n",
134+
"cls_true = data.test.cls[0:9]\n",
135+
"plot_images(images=images, cls_true=cls_true)"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": 8,
141+
"metadata": {
142+
"collapsed": true
143+
},
144+
"outputs": [],
145+
"source": [
146+
"def new_weights(shape):\n",
147+
" return tf.Variable(tf.truncated_normal(shape, stddev=0.05))"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {
154+
"collapsed": true
155+
},
156+
"outputs": [],
157+
"source": []
158+
}
159+
],
160+
"metadata": {
161+
"anaconda-cloud": {},
162+
"kernelspec": {
163+
"display_name": "Python [conda root]",
164+
"language": "python",
165+
"name": "conda-root-py"
166+
},
167+
"language_info": {
168+
"codemirror_mode": {
169+
"name": "ipython",
170+
"version": 3
171+
},
172+
"file_extension": ".py",
173+
"mimetype": "text/x-python",
174+
"name": "python",
175+
"nbconvert_exporter": "python",
176+
"pygments_lexer": "ipython3",
177+
"version": "3.5.2"
178+
}
179+
},
180+
"nbformat": 4,
181+
"nbformat_minor": 1
182+
}

Linear model.ipynb

Lines changed: 761 additions & 0 deletions
Large diffs are not rendered by default.

data/MNIST/t10k-images-idx3-ubyte.gz

1.57 MB
Binary file not shown.

data/MNIST/t10k-labels-idx1-ubyte.gz

4.44 KB
Binary file not shown.

data/MNIST/train-images-idx3-ubyte.gz

9.45 MB
Binary file not shown.

data/MNIST/train-labels-idx1-ubyte.gz

28.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)