Skip to content

Commit 222ec4d

Browse files
committed
Final class updates
1 parent 1c60fc3 commit 222ec4d

File tree

2 files changed

+309
-5
lines changed

2 files changed

+309
-5
lines changed

examples/keras-perf/cnn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
config.img_height = 28
1616
config.epochs = 4
1717

18-
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
18+
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.cifar10.load_data()
1919

2020
X_train = X_train.astype('float32')
2121
X_train /= 255.
2222
X_test = X_test.astype('float32')
2323
X_test /= 255.
2424

2525
# reshape input data
26-
X_train = X_train.reshape(
27-
X_train.shape[0], config.img_width, config.img_height, 1)
28-
X_test = X_test.reshape(
29-
X_test.shape[0], config.img_width, config.img_height, 1)
26+
# X_train = X_train.reshape(
27+
# X_train.shape[0], config.img_width, config.img_height, 1)
28+
# X_test = X_test.reshape(
29+
# X_test.shape[0], config.img_width, config.img_height, 1)
3030

3131
# one hot encode outputs
3232
y_train = tf.keras.utils.to_categorical(y_train)
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from tensorflow.keras.datasets import imdb\n",
10+
"(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=1000)"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 3,
16+
"metadata": {},
17+
"outputs": [
18+
{
19+
"data": {
20+
"text/plain": [
21+
"[1,\n",
22+
" 14,\n",
23+
" 22,\n",
24+
" 16,\n",
25+
" 43,\n",
26+
" 530,\n",
27+
" 973,\n",
28+
" 2,\n",
29+
" 2,\n",
30+
" 65,\n",
31+
" 458,\n",
32+
" 2,\n",
33+
" 66,\n",
34+
" 2,\n",
35+
" 4,\n",
36+
" 173,\n",
37+
" 36,\n",
38+
" 256,\n",
39+
" 5,\n",
40+
" 25,\n",
41+
" 100,\n",
42+
" 43,\n",
43+
" 838,\n",
44+
" 112,\n",
45+
" 50,\n",
46+
" 670,\n",
47+
" 2,\n",
48+
" 9,\n",
49+
" 35,\n",
50+
" 480,\n",
51+
" 284,\n",
52+
" 5,\n",
53+
" 150,\n",
54+
" 4,\n",
55+
" 172,\n",
56+
" 112,\n",
57+
" 167,\n",
58+
" 2,\n",
59+
" 336,\n",
60+
" 385,\n",
61+
" 39,\n",
62+
" 4,\n",
63+
" 172,\n",
64+
" 2,\n",
65+
" 2,\n",
66+
" 17,\n",
67+
" 546,\n",
68+
" 38,\n",
69+
" 13,\n",
70+
" 447,\n",
71+
" 4,\n",
72+
" 192,\n",
73+
" 50,\n",
74+
" 16,\n",
75+
" 6,\n",
76+
" 147,\n",
77+
" 2,\n",
78+
" 19,\n",
79+
" 14,\n",
80+
" 22,\n",
81+
" 4,\n",
82+
" 2,\n",
83+
" 2,\n",
84+
" 469,\n",
85+
" 4,\n",
86+
" 22,\n",
87+
" 71,\n",
88+
" 87,\n",
89+
" 12,\n",
90+
" 16,\n",
91+
" 43,\n",
92+
" 530,\n",
93+
" 38,\n",
94+
" 76,\n",
95+
" 15,\n",
96+
" 13,\n",
97+
" 2,\n",
98+
" 4,\n",
99+
" 22,\n",
100+
" 17,\n",
101+
" 515,\n",
102+
" 17,\n",
103+
" 12,\n",
104+
" 16,\n",
105+
" 626,\n",
106+
" 18,\n",
107+
" 2,\n",
108+
" 5,\n",
109+
" 62,\n",
110+
" 386,\n",
111+
" 12,\n",
112+
" 8,\n",
113+
" 316,\n",
114+
" 8,\n",
115+
" 106,\n",
116+
" 5,\n",
117+
" 4,\n",
118+
" 2,\n",
119+
" 2,\n",
120+
" 16,\n",
121+
" 480,\n",
122+
" 66,\n",
123+
" 2,\n",
124+
" 33,\n",
125+
" 4,\n",
126+
" 130,\n",
127+
" 12,\n",
128+
" 16,\n",
129+
" 38,\n",
130+
" 619,\n",
131+
" 5,\n",
132+
" 25,\n",
133+
" 124,\n",
134+
" 51,\n",
135+
" 36,\n",
136+
" 135,\n",
137+
" 48,\n",
138+
" 25,\n",
139+
" 2,\n",
140+
" 33,\n",
141+
" 6,\n",
142+
" 22,\n",
143+
" 12,\n",
144+
" 215,\n",
145+
" 28,\n",
146+
" 77,\n",
147+
" 52,\n",
148+
" 5,\n",
149+
" 14,\n",
150+
" 407,\n",
151+
" 16,\n",
152+
" 82,\n",
153+
" 2,\n",
154+
" 8,\n",
155+
" 4,\n",
156+
" 107,\n",
157+
" 117,\n",
158+
" 2,\n",
159+
" 15,\n",
160+
" 256,\n",
161+
" 4,\n",
162+
" 2,\n",
163+
" 7,\n",
164+
" 2,\n",
165+
" 5,\n",
166+
" 723,\n",
167+
" 36,\n",
168+
" 71,\n",
169+
" 43,\n",
170+
" 530,\n",
171+
" 476,\n",
172+
" 26,\n",
173+
" 400,\n",
174+
" 317,\n",
175+
" 46,\n",
176+
" 7,\n",
177+
" 4,\n",
178+
" 2,\n",
179+
" 2,\n",
180+
" 13,\n",
181+
" 104,\n",
182+
" 88,\n",
183+
" 4,\n",
184+
" 381,\n",
185+
" 15,\n",
186+
" 297,\n",
187+
" 98,\n",
188+
" 32,\n",
189+
" 2,\n",
190+
" 56,\n",
191+
" 26,\n",
192+
" 141,\n",
193+
" 6,\n",
194+
" 194,\n",
195+
" 2,\n",
196+
" 18,\n",
197+
" 4,\n",
198+
" 226,\n",
199+
" 22,\n",
200+
" 21,\n",
201+
" 134,\n",
202+
" 476,\n",
203+
" 26,\n",
204+
" 480,\n",
205+
" 5,\n",
206+
" 144,\n",
207+
" 30,\n",
208+
" 2,\n",
209+
" 18,\n",
210+
" 51,\n",
211+
" 36,\n",
212+
" 28,\n",
213+
" 224,\n",
214+
" 92,\n",
215+
" 25,\n",
216+
" 104,\n",
217+
" 4,\n",
218+
" 226,\n",
219+
" 65,\n",
220+
" 16,\n",
221+
" 38,\n",
222+
" 2,\n",
223+
" 88,\n",
224+
" 12,\n",
225+
" 16,\n",
226+
" 283,\n",
227+
" 5,\n",
228+
" 16,\n",
229+
" 2,\n",
230+
" 113,\n",
231+
" 103,\n",
232+
" 32,\n",
233+
" 15,\n",
234+
" 16,\n",
235+
" 2,\n",
236+
" 19,\n",
237+
" 178,\n",
238+
" 32]"
239+
]
240+
},
241+
"execution_count": 3,
242+
"metadata": {},
243+
"output_type": "execute_result"
244+
}
245+
],
246+
"source": [
247+
"X_train[0]"
248+
]
249+
},
250+
{
251+
"cell_type": "code",
252+
"execution_count": 6,
253+
"metadata": {},
254+
"outputs": [
255+
{
256+
"name": "stdout",
257+
"output_type": "stream",
258+
"text": [
259+
"<START> this film was just brilliant casting <UNK> <UNK> story direction <UNK> really <UNK> the part they played and you could just imagine being there robert <UNK> is an amazing actor and now the same being director <UNK> father came from the same <UNK> <UNK> as myself so i loved the fact there was a real <UNK> with this film the <UNK> <UNK> throughout the film were great it was just brilliant so much that i <UNK> the film as soon as it was released for <UNK> and would recommend it to everyone to watch and the <UNK> <UNK> was amazing really <UNK> at the end it was so sad and you know what they say if you <UNK> at a film it must have been good and this definitely was also <UNK> to the two little <UNK> that played the <UNK> of <UNK> and paul they were just brilliant children are often left out of the <UNK> <UNK> i think because the stars that play them all <UNK> up are such a big <UNK> for the whole film but these children are amazing and should be <UNK> for what they have done don't you think the whole story was so <UNK> because it was true and was <UNK> life after all that was <UNK> with us all\n"
260+
]
261+
}
262+
],
263+
"source": [
264+
"INDEX_FROM=3\n",
265+
"word_to_id = imdb.get_word_index()\n",
266+
"word_to_id = {k:(v+INDEX_FROM) for k,v in word_to_id.items()}\n",
267+
"word_to_id[\"<PAD>\"] = 0\n",
268+
"word_to_id[\"<START>\"] = 1\n",
269+
"word_to_id[\"<UNK>\"] = 2\n",
270+
"\n",
271+
"id_to_word = {value:key for key,value in word_to_id.items()}\n",
272+
"print(' '.join(id_to_word[id] for id in X_train[0] ))"
273+
]
274+
},
275+
{
276+
"cell_type": "code",
277+
"execution_count": null,
278+
"metadata": {},
279+
"outputs": [],
280+
"source": []
281+
}
282+
],
283+
"metadata": {
284+
"kernelspec": {
285+
"display_name": "Python 3",
286+
"language": "python",
287+
"name": "python3"
288+
},
289+
"language_info": {
290+
"codemirror_mode": {
291+
"name": "ipython",
292+
"version": 3
293+
},
294+
"file_extension": ".py",
295+
"mimetype": "text/x-python",
296+
"name": "python",
297+
"nbconvert_exporter": "python",
298+
"pygments_lexer": "ipython3",
299+
"version": "3.6.4"
300+
}
301+
},
302+
"nbformat": 4,
303+
"nbformat_minor": 4
304+
}

0 commit comments

Comments
 (0)