回答編集履歴
5
変数sizeの変更
test
CHANGED
@@ -178,7 +178,7 @@
|
|
178
178
|
|
179
179
|
# 7 * 7 * 64 から不定のsizeに変更 画像sizeを変更しても修正がいらない
|
180
180
|
|
181
|
-
size = tf.size(h_pool2)
|
181
|
+
size = tf.size(h_pool2[0])
|
182
182
|
|
183
183
|
W_fc1 = weight_variable([size, 1024])
|
184
184
|
|
4
NUM_CLASSESの値の変更
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
NUM_CLASSES = 2
|
43
|
+
NUM_CLASSES = 12
|
44
44
|
|
45
45
|
IMAGE_SIZE = 56
|
46
46
|
|
3
修正
test
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
ネットワークの部分だけ修正(見落としがある可能性があります)
|
24
|
+
|
23
25
|
```python
|
24
26
|
|
25
27
|
#!/usr/bin/env python
|
2
コード追加
test
CHANGED
@@ -17,3 +17,187 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
このネットワークには28 * 28 * 3 に変換可能なサイズを渡しましょう。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```python
|
24
|
+
|
25
|
+
#!/usr/bin/env python
|
26
|
+
|
27
|
+
# -*- coding: utf-8 -*-
|
28
|
+
|
29
|
+
import sys
|
30
|
+
|
31
|
+
import cv2
|
32
|
+
|
33
|
+
import numpy as np
|
34
|
+
|
35
|
+
import tensorflow as tf
|
36
|
+
|
37
|
+
import tensorflow.python.platform
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
NUM_CLASSES = 2
|
42
|
+
|
43
|
+
IMAGE_SIZE = 56
|
44
|
+
|
45
|
+
IMAGE_PIXELS = IMAGE_SIZE*IMAGE_SIZE*3
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
flags = tf.app.flags
|
50
|
+
|
51
|
+
FLAGS = flags.FLAGS
|
52
|
+
|
53
|
+
flags.DEFINE_string('train', 'train.txt', 'File name of train data')
|
54
|
+
|
55
|
+
flags.DEFINE_string('test', 'test.txt', 'File name of train data')
|
56
|
+
|
57
|
+
flags.DEFINE_string('train_dir', '/tmp/data', 'Directory to put the training data.')
|
58
|
+
|
59
|
+
flags.DEFINE_integer('max_steps', 200, 'Number of steps to run trainer.')
|
60
|
+
|
61
|
+
flags.DEFINE_integer('batch_size', 10, 'Batch size'
|
62
|
+
|
63
|
+
'Must divide evenly into the dataset sizes.')
|
64
|
+
|
65
|
+
flags.DEFINE_float('learning_rate', 1e-4, 'Initial learning rate.')
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
def inference(images_placeholder, keep_prob):
|
70
|
+
|
71
|
+
""" 予測モデルを作成する関数
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
引数:
|
76
|
+
|
77
|
+
images_placeholder: 画像のplaceholder
|
78
|
+
|
79
|
+
keep_prob: dropout率のplace_holder
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
返り値:
|
84
|
+
|
85
|
+
y_conv: 各クラスの確率(のようなもの)
|
86
|
+
|
87
|
+
"""
|
88
|
+
|
89
|
+
# 重みを標準偏差0.1の正規分布で初期化
|
90
|
+
|
91
|
+
def weight_variable(shape):
|
92
|
+
|
93
|
+
initial = tf.truncated_normal(shape, stddev=0.1)
|
94
|
+
|
95
|
+
return tf.Variable(initial)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
# バイアスを標準偏差0.1の正規分布で初期化
|
100
|
+
|
101
|
+
def bias_variable(shape):
|
102
|
+
|
103
|
+
initial = tf.constant(0.1, shape=shape)
|
104
|
+
|
105
|
+
return tf.Variable(initial)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
# 畳み込み層の作成
|
110
|
+
|
111
|
+
def conv2d(x, W):
|
112
|
+
|
113
|
+
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# プーリング層の作成
|
118
|
+
|
119
|
+
def max_pool_2x2(x):
|
120
|
+
|
121
|
+
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
|
122
|
+
|
123
|
+
strides=[1, 2, 2, 1], padding='SAME')
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# 入力を28x28x3に変形
|
128
|
+
|
129
|
+
x_image = tf.reshape(images_placeholder, [-1, 56, 56, 3])
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
# 畳み込み層1の作成
|
134
|
+
|
135
|
+
with tf.name_scope('conv1') as scope:
|
136
|
+
|
137
|
+
W_conv1 = weight_variable([5, 5, 3, 32])
|
138
|
+
|
139
|
+
b_conv1 = bias_variable([32])
|
140
|
+
|
141
|
+
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# プーリング層1の作成
|
146
|
+
|
147
|
+
with tf.name_scope('pool1') as scope:
|
148
|
+
|
149
|
+
h_pool1 = max_pool_2x2(h_conv1)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# 畳み込み層2の作成
|
154
|
+
|
155
|
+
with tf.name_scope('conv2') as scope:
|
156
|
+
|
157
|
+
W_conv2 = weight_variable([5, 5, 32, 64])
|
158
|
+
|
159
|
+
b_conv2 = bias_variable([64])
|
160
|
+
|
161
|
+
h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
# プーリング層2の作成
|
166
|
+
|
167
|
+
with tf.name_scope('pool2') as scope:
|
168
|
+
|
169
|
+
h_pool2 = max_pool_2x2(h_conv2)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
# 全結合層1の作成
|
174
|
+
|
175
|
+
with tf.name_scope('fc1') as scope:
|
176
|
+
|
177
|
+
# 7 * 7 * 64 から不定のsizeに変更 画像sizeを変更しても修正がいらない
|
178
|
+
|
179
|
+
size = tf.size(h_pool2)
|
180
|
+
|
181
|
+
W_fc1 = weight_variable([size, 1024])
|
182
|
+
|
183
|
+
b_fc1 = bias_variable([1024])
|
184
|
+
|
185
|
+
h_pool2_flat = tf.reshape(h_pool2, [-1, size])
|
186
|
+
|
187
|
+
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
|
188
|
+
|
189
|
+
# dropoutの設定
|
190
|
+
|
191
|
+
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
# 全結合層2の作成
|
196
|
+
|
197
|
+
with tf.name_scope('fc2') as scope:
|
198
|
+
|
199
|
+
W_fc2 = weight_variable([1024, NUM_CLASSES])
|
200
|
+
|
201
|
+
b_fc2 = bias_variable([NUM_CLASSES])
|
202
|
+
|
203
|
+
```
|
1
訂正
test
CHANGED
@@ -16,4 +16,4 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
このネットワークには28 * 28 * 3 を
|
19
|
+
このネットワークには28 * 28 * 3 に変換可能なサイズを渡しましょう。
|