teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

タイトル変更

2019/11/28 06:36

投稿

sinugo
sinugo

スコア5

title CHANGED
@@ -1,1 +1,1 @@
1
- 各クラスごとの正解率を出力させたいです、!
1
+ cifar-10 各クラスごとの正解率を出力させる方法
body CHANGED
File without changes

3

説明の修正

2019/11/28 06:36

投稿

sinugo
sinugo

スコア5

title CHANGED
File without changes
body CHANGED
@@ -1,13 +1,20 @@
1
1
  # 各クラスごとの正解率を出力させ方を教えてください。
2
2
 
3
- ここに質問の内容を詳しく書いてください。
3
+
4
4
  今大学でtensorflowを使った雲画像の自動認識を勉強しています。
5
5
  3クラス用意して学習しているのですが、
6
6
  評価時に出力される正解率は全体のもののみなので、
7
7
  クラスごとの正解率をそれぞれ出力したいと考えています。
8
8
 
9
+ *現在の出力
10
+ epoch ●● duration = ●● sec, prediction = ●●
9
11
 
12
+ *実現したい出力
13
+ epoch ●● class : 0 duration = ●● sec, prediction = ●●
14
+ epoch ●● class : 1 duration = ●● sec, prediction = ●●
15
+ epoch ●● class : 2 duration = ●● sec, prediction = ●●
10
16
 
17
+
11
18
  ### 該当のソースコード
12
19
 
13
20
  ```python3

2

文の修正

2019/11/26 09:05

投稿

sinugo
sinugo

スコア5

title CHANGED
File without changes
body CHANGED
@@ -157,166 +157,15 @@
157
157
  if __name__ == '__main__':
158
158
  tf.app.run()
159
159
  ```
160
- ```python3
161
- model.py
162
160
 
163
- # coding: UTF-8
164
- from __future__ import absolute_import
165
- from __future__ import division
166
- from __future__ import print_function
167
161
 
168
- import tensorflow.compat.v1 as tf
169
- tf.disable_v2_behavior()
170
-
171
- NUM_CLASSES = 3
172
-
173
-
174
- def _get_weights(shape, stddev=1.0):
175
- var = tf.get_variable('weights', shape,
176
- initializer=tf.truncated_normal_initializer(stddev=stddev))
177
- return var
178
-
179
-
180
- def _get_biases(shape, value=0.0):
181
- var = tf.get_variable('biases', shape,
182
- initializer=tf.constant_initializer(value))
183
- return var
184
-
185
-
186
- def inference(image_node):
187
- # conv1
188
- with tf.variable_scope('conv1') as scope:
189
- weights = _get_weights(shape=[3, 3, 3, 64], stddev=0.05)
190
- conv = tf.nn.conv2d(image_node, weights, [1, 1, 1, 1], padding='SAME')
191
- biases = _get_biases([64], value=0.1)
192
- bias = tf.nn.bias_add(conv, biases)
193
- conv1 = tf.nn.relu(bias, name=scope.name)
194
-
195
- # pool1
196
- pool1 = tf.nn.max_pool(conv1, ksize=[1 ,2, 2, 1], strides=[1, 2, 2, 1],
197
- padding='SAME', name='pool1')
198
-
199
- # norm1
200
- norm1 = tf.nn.lrn(pool1, 4,
201
- bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm1')
202
-
203
- # conv2
204
- with tf.variable_scope('conv2') as scope:
205
- weights = _get_weights(shape=[3, 3, 64, 64], stddev=0.05)
206
- conv = tf.nn.conv2d(norm1, weights, [1, 1, 1, 1], padding='SAME')
207
- biases = _get_biases([64], value=0.1)
208
- bias = tf.nn.bias_add(conv, biases)
209
- conv2 = tf.nn.relu(bias, name=scope.name)
210
-
211
- # norm2
212
- norm2 = tf.nn.lrn(conv2, 4,
213
- bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm2')
214
-
215
- # pool2
216
- pool2 = tf.nn.max_pool(norm2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1],
217
- padding='SAME', name='pool2')
218
-
219
- # conv3
220
- with tf.variable_scope('conv3') as scope:
221
- weights = _get_weights(shape=[3, 3, 64, 128], stddev=0.05)
222
- conv = tf.nn.conv2d(pool2, weights, [1, 1, 1, 1], padding='SAME')
223
- biases = _get_biases([128], value=0.1)
224
- bias = tf.nn.bias_add(conv, biases)
225
- conv3 = tf.nn.relu(bias, name=scope.name)
226
-
227
- # pool3
228
- pool3 = tf.nn.max_pool(conv3, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1],
229
- padding='SAME', name='pool3')
230
-
231
- # norm3
232
- norm3 = tf.nn.lrn(pool3, 4,
233
- bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm3')
234
-
235
-
236
-
237
- reshape = tf.reshape(norm3, [1, -1])
238
- dim = reshape.get_shape()[1].value
239
-
240
- # fc3
241
- with tf.variable_scope('fc3') as scope:
242
- weights = _get_weights(shape=[dim, 256], stddev=0.05)
243
- biases = _get_biases([256], value=0.1)
244
- fc3 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)
245
-
246
- # fc4
247
- with tf.variable_scope('fc4') as scope:
248
- weights = _get_weights(shape=[256, 128], stddev=0.05)
249
- biases = _get_biases([128], value=0.1)
250
- fc4 = tf.nn.relu(tf.matmul(fc3, weights) + biases, name=scope.name)
251
-
252
- # output
253
- with tf.variable_scope('output') as scope:
254
- weights = _get_weights(shape=[128, NUM_CLASSES], stddev=1 / 128.0)
255
- biases = _get_biases([NUM_CLASSES], value=0.0)
256
- logits = tf.add(tf.matmul(fc4, weights), biases, name='logits')
257
-
258
- return logits
259
- ```
260
- ```python3
261
- reader.py
262
-
263
- # coding: UTF-8
264
- from __future__ import absolute_import
265
- from __future__ import division
266
- from __future__ import print_function
267
-
268
- import os
269
-
270
- import numpy as np
271
-
272
-
273
- class Cifar10Record(object):
274
- width = 32
275
- height = 32
276
- depth = 3
277
-
278
- def set_label(self, label_byte):
279
- self.label = np.frombuffer(label_byte, dtype=np.uint8)
280
-
281
- def set_image(self, image_bytes):
282
- byte_buffer = np.frombuffer(image_bytes, dtype=np.int8)
283
- reshaped_array = np.reshape(byte_buffer,
284
- [self.depth, self.height, self.width])
285
- self.byte_array = np.transpose(reshaped_array, [1, 2, 0])
286
- self.byte_array = self.byte_array.astype(np.float32)
287
-
288
- class Cifar10Reader(object):
289
- def __init__(self, filename):
290
- if not os.path.exists(filename):
291
- print(filename + ' is not exist')
292
- return
293
-
294
- self.bytestream = open(filename, mode="rb")
295
-
296
- def close(self):
297
- if not self.bytestream:
298
- self.bytestream.close()
299
-
300
- def read(self, index):
301
- result = Cifar10Record()
302
-
303
- label_bytes = 1
304
- image_bytes = result.height * result.width * result.depth
305
- record_bytes = label_bytes + image_bytes
306
-
307
- self.bytestream.seek(record_bytes * index, 0)
308
-
309
- result.set_label(self.bytestream.read(label_bytes))
310
- result.set_image(self.bytestream.read(image_bytes))
311
-
312
-
313
- return result
314
- ```
315
-
316
162
  ### 試したこと
163
+ _eval関数をもう1つ作って、
164
+ prediction = _eval(sess, top_k_op,
317
- いくつかサイトを調べて自分のプログラムに合うように調整してみたのですが、
165
+ train_placeholder, label_placeholder)
166
+ print('epoch %d duration = %d sec, prediction = %.3f'
167
+ % (epoch, duration, prediction))
318
- なかなかうまく出力できませんでした、、、
168
+ をfor文で回そとしたのですがうまくきませんでした
319
-
320
169
  ### 補足情報(FW/ツールのバージョンなど)
321
170
 
322
171
  プログラムは「TensorFlowはじめました ― 実践!最新Googleマシンラーニング」を参考にしています。

1

2019/11/22 08:38

投稿

sinugo
sinugo

スコア5

title CHANGED
@@ -1,1 +1,1 @@
1
- 各クラスごとの正解率を出力させたいです、
1
+ 各クラスごとの正解率を出力させたいです、!
body CHANGED
File without changes