Skip to content

Commit b694e66

Browse files
committed
#7 Bug 수정
1 parent eaa5938 commit b694e66

File tree

1 file changed

+58
-76
lines changed

1 file changed

+58
-76
lines changed

lab-06-1-softmax_classifier-eager.ipynb

+58-76
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 56,
16-
"metadata": {
17-
"scrolled": true
18-
},
15+
"execution_count": 1,
16+
"metadata": {},
1917
"outputs": [],
2018
"source": [
2119
"import tensorflow as tf\n",
@@ -27,7 +25,7 @@
2725
},
2826
{
2927
"cell_type": "code",
30-
"execution_count": 57,
28+
"execution_count": 2,
3129
"metadata": {},
3230
"outputs": [],
3331
"source": [
@@ -55,7 +53,7 @@
5553
},
5654
{
5755
"cell_type": "code",
58-
"execution_count": 58,
56+
"execution_count": 3,
5957
"metadata": {},
6058
"outputs": [
6159
{
@@ -80,7 +78,7 @@
8078
},
8179
{
8280
"cell_type": "code",
83-
"execution_count": 59,
81+
"execution_count": 4,
8482
"metadata": {},
8583
"outputs": [
8684
{
@@ -106,7 +104,7 @@
106104
},
107105
{
108106
"cell_type": "code",
109-
"execution_count": 60,
107+
"execution_count": 5,
110108
"metadata": {},
111109
"outputs": [
112110
{
@@ -136,14 +134,14 @@
136134
},
137135
{
138136
"cell_type": "code",
139-
"execution_count": 14,
137+
"execution_count": 7,
140138
"metadata": {},
141139
"outputs": [
142140
{
143141
"name": "stdout",
144142
"output_type": "stream",
145143
"text": [
146-
"tf.Tensor([[8.78809988e-01 1.21101834e-01 8.81008382e-05]], shape=(1, 3), dtype=float32)\n"
144+
"tf.Tensor([[0.9302204 0.06200533 0.00777428]], shape=(1, 3), dtype=float32)\n"
147145
]
148146
}
149147
],
@@ -152,12 +150,12 @@
152150
"sample_db = [[8,2,1,4]]\n",
153151
"sample_db = np.asarray(sample_db, dtype=np.float32)\n",
154152
"\n",
155-
"print(softmax_regression(sample_db))"
153+
"print(hypothesis(sample_db))"
156154
]
157155
},
158156
{
159157
"cell_type": "code",
160-
"execution_count": 62,
158+
"execution_count": 8,
161159
"metadata": {},
162160
"outputs": [
163161
{
@@ -181,7 +179,7 @@
181179
},
182180
{
183181
"cell_type": "code",
184-
"execution_count": 63,
182+
"execution_count": 9,
185183
"metadata": {},
186184
"outputs": [
187185
{
@@ -203,18 +201,18 @@
203201
},
204202
{
205203
"cell_type": "code",
206-
"execution_count": 65,
204+
"execution_count": 10,
207205
"metadata": {},
208206
"outputs": [
209207
{
210208
"name": "stdout",
211209
"output_type": "stream",
212210
"text": [
213-
"[<tf.Tensor: id=107174, shape=(4, 3), dtype=float32, numpy=\n",
211+
"[<tf.Tensor: id=118, shape=(4, 3), dtype=float32, numpy=\n",
214212
"array([[ 0.06914616, -0.6509784 , 0.58183223],\n",
215213
" [-1.5221257 , -1.214863 , 2.7369888 ],\n",
216214
" [-1.2473826 , -1.7611003 , 3.008483 ],\n",
217-
" [-1.2014605 , -1.8659232 , 3.0673838 ]], dtype=float32)>, <tf.Tensor: id=107172, shape=(3,), dtype=float32, numpy=array([-0.15212911, -0.342192 , 0.49432108], dtype=float32)>]\n"
215+
" [-1.2014605 , -1.8659232 , 3.0673838 ]], dtype=float32)>, <tf.Tensor: id=116, shape=(3,), dtype=float32, numpy=array([-0.15212911, -0.342192 , 0.49432108], dtype=float32)>]\n"
218216
]
219217
}
220218
],
@@ -231,34 +229,34 @@
231229
},
232230
{
233231
"cell_type": "code",
234-
"execution_count": 89,
232+
"execution_count": 19,
235233
"metadata": {},
236234
"outputs": [
237235
{
238236
"name": "stdout",
239237
"output_type": "stream",
240238
"text": [
241-
"Loss at epoch 1: 0.120537\n",
242-
"Loss at epoch 100: 0.118783\n",
243-
"Loss at epoch 200: 0.117060\n",
244-
"Loss at epoch 300: 0.115383\n",
245-
"Loss at epoch 400: 0.113752\n",
246-
"Loss at epoch 500: 0.112164\n",
247-
"Loss at epoch 600: 0.110618\n",
248-
"Loss at epoch 700: 0.109112\n",
249-
"Loss at epoch 800: 0.107645\n",
250-
"Loss at epoch 900: 0.106214\n",
251-
"Loss at epoch 1000: 0.104820\n",
252-
"Loss at epoch 1100: 0.103461\n",
253-
"Loss at epoch 1200: 0.102135\n",
254-
"Loss at epoch 1300: 0.100841\n",
255-
"Loss at epoch 1400: 0.099578\n",
256-
"Loss at epoch 1500: 0.098345\n",
257-
"Loss at epoch 1600: 0.097141\n",
258-
"Loss at epoch 1700: 0.095966\n",
259-
"Loss at epoch 1800: 0.094817\n",
260-
"Loss at epoch 1900: 0.093694\n",
261-
"Loss at epoch 2000: 0.092597\n"
239+
"Loss at epoch 1: 0.126001\n",
240+
"Loss at epoch 100: 0.124082\n",
241+
"Loss at epoch 200: 0.122203\n",
242+
"Loss at epoch 300: 0.120380\n",
243+
"Loss at epoch 400: 0.118610\n",
244+
"Loss at epoch 500: 0.116891\n",
245+
"Loss at epoch 600: 0.115221\n",
246+
"Loss at epoch 700: 0.113598\n",
247+
"Loss at epoch 800: 0.112019\n",
248+
"Loss at epoch 900: 0.110482\n",
249+
"Loss at epoch 1000: 0.108987\n",
250+
"Loss at epoch 1100: 0.107531\n",
251+
"Loss at epoch 1200: 0.106112\n",
252+
"Loss at epoch 1300: 0.104730\n",
253+
"Loss at epoch 1400: 0.103382\n",
254+
"Loss at epoch 1500: 0.102067\n",
255+
"Loss at epoch 1600: 0.100785\n",
256+
"Loss at epoch 1700: 0.099534\n",
257+
"Loss at epoch 1800: 0.098313\n",
258+
"Loss at epoch 1900: 0.097120\n",
259+
"Loss at epoch 2000: 0.095956\n"
262260
]
263261
}
264262
],
@@ -284,22 +282,22 @@
284282
},
285283
{
286284
"cell_type": "code",
287-
"execution_count": 90,
285+
"execution_count": 20,
288286
"metadata": {},
289287
"outputs": [
290288
{
291289
"name": "stdout",
292290
"output_type": "stream",
293291
"text": [
294292
"tf.Tensor(\n",
295-
"[[0.00353154 0.0319833 0.96448517]\n",
296-
" [0.00868691 0.10975333 0.8815598 ]\n",
297-
" [0.00679857 0.13375703 0.8594444 ]\n",
298-
" [0.00680363 0.13399178 0.8592046 ]\n",
299-
" [0.01918449 0.05515586 0.9256596 ]\n",
300-
" [0.01832496 0.05755147 0.9241236 ]\n",
301-
" [0.01991962 0.05325432 0.92682606]\n",
302-
" [0.01994611 0.05318815 0.92686576]], shape=(8, 3), dtype=float32)\n",
293+
"[[0.00783868 0.08934675 0.90281457]\n",
294+
" [0.00837632 0.10334261 0.88828105]\n",
295+
" [0.00890698 0.11949147 0.8716016 ]\n",
296+
" [0.01300187 0.34645918 0.64053893]\n",
297+
" [0.01916472 0.3473155 0.6335198 ]\n",
298+
" [0.01627325 0.38224185 0.6014849 ]\n",
299+
" [0.03545809 0.24856271 0.7159792 ]\n",
300+
" [0.04392094 0.21500538 0.74107367]], shape=(8, 3), dtype=float32)\n",
303301
"tf.Tensor([2 2 2 2 2 2 2 2], shape=(8,), dtype=int64)\n"
304302
]
305303
}
@@ -316,22 +314,22 @@
316314
},
317315
{
318316
"cell_type": "code",
319-
"execution_count": 95,
317+
"execution_count": 21,
320318
"metadata": {},
321319
"outputs": [
322320
{
323321
"name": "stdout",
324322
"output_type": "stream",
325323
"text": [
326324
"tf.Tensor(\n",
327-
"[[8.8750041e-10 2.7697413e-06 9.9999726e-01]\n",
328-
" [2.9207354e-03 2.1559663e-02 9.7551960e-01]\n",
329-
" [3.2986515e-13 2.1821767e-02 9.7817820e-01]\n",
330-
" [6.4432254e-10 7.9563278e-01 2.0436718e-01]\n",
331-
" [1.7372852e-02 9.7724211e-01 5.3850519e-03]\n",
332-
" [8.0847805e-03 9.9191523e-01 3.9386168e-17]\n",
333-
" [8.6395258e-01 1.3604739e-01 1.9627089e-10]\n",
334-
" [9.7442448e-01 2.5575478e-02 1.9792436e-13]], shape=(8, 3), dtype=float32)\n",
325+
"[[1.17311458e-06 4.64814686e-04 9.99534011e-01]\n",
326+
" [8.37631337e-03 1.03342585e-01 8.88281107e-01]\n",
327+
" [1.04251918e-09 1.33687243e-01 8.66312802e-01]\n",
328+
" [5.01113000e-08 8.58640432e-01 1.41359538e-01]\n",
329+
" [1.16531663e-01 8.71398807e-01 1.20694786e-02]\n",
330+
" [5.55007122e-02 9.44499254e-01 7.49097243e-11]\n",
331+
" [8.76283109e-01 1.23716690e-01 2.13872141e-07]\n",
332+
" [9.74358737e-01 2.56412514e-02 1.90751481e-09]], shape=(8, 3), dtype=float32)\n",
335333
"tf.Tensor([2 2 2 1 1 1 0 0], shape=(8,), dtype=int64)\n",
336334
"tf.Tensor([2 2 2 1 1 1 0 0], shape=(8,), dtype=int64)\n"
337335
]
@@ -353,7 +351,7 @@
353351
},
354352
{
355353
"cell_type": "code",
356-
"execution_count": null,
354+
"execution_count": 14,
357355
"metadata": {},
358356
"outputs": [],
359357
"source": [
@@ -386,25 +384,9 @@
386384
" grads = self.grad_fn(X, Y)\n",
387385
" optimizer.apply_gradients(zip(grads, self.variables))\n",
388386
" if (i==0) | ((i+1)%verbose==0):\n",
389-
" print('Loss at epoch %d: %f' %(i+1, self.loss_fn(X, Y).numpy()))"
390-
]
391-
},
392-
{
393-
"cell_type": "code",
394-
"execution_count": null,
395-
"metadata": {},
396-
"outputs": [],
397-
"source": [
398-
"optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.1)\n",
399-
"model = softmax_classifer(nb_classes)"
400-
]
401-
},
402-
{
403-
"cell_type": "code",
404-
"execution_count": null,
405-
"metadata": {},
406-
"outputs": [],
407-
"source": [
387+
" print('Loss at epoch %d: %f' %(i+1, self.loss_fn(X, Y).numpy()))\n",
388+
" \n",
389+
"model = softmax_classifer(nb_classes)\n",
408390
"model.fit(x_data, y_data)"
409391
]
410392
}

0 commit comments

Comments
 (0)