|
5 | 5 | import paddle.v2.fluid.layers as layers |
6 | 6 | import paddle.v2.fluid.nets as nets |
7 | 7 | import paddle.v2.fluid.evaluator as evaluator |
8 | | -from paddle.v2.fluid.io import get_inference_program |
9 | 8 | from paddle.v2.fluid.executor import Executor |
10 | 9 | from paddle.v2.fluid.initializer import XavierInitializer |
11 | 10 | from paddle.v2.fluid.optimizer import AdamOptimizer |
@@ -117,11 +116,9 @@ def conv_block(input, num_filter, groups, dropouts): |
117 | 116 |
|
118 | 117 | train_reader = paddle.batch( |
119 | 118 | paddle.reader.shuffle( |
120 | | - paddle.dataset.cifar.train10(), buf_size=BATCH_SIZE * 10), |
| 119 | + paddle.dataset.cifar.train10(), buf_size=128 * 10), |
121 | 120 | batch_size=BATCH_SIZE) |
122 | 121 |
|
123 | | -test_reader = paddle.batch(paddle.dataset.cifar.test10(), batch_size=BATCH_SIZE) |
124 | | - |
125 | 122 | place = core.CPUPlace() |
126 | 123 | exe = Executor(place) |
127 | 124 |
|
@@ -152,41 +149,10 @@ def conv_block(input, num_filter, groups, dropouts): |
152 | 149 | loss = np.array(outs[0]) |
153 | 150 | acc = np.array(outs[1]) |
154 | 151 | pass_acc = accuracy.eval(exe) |
155 | | - |
156 | | - batch_id = batch_id + 1 |
157 | | - |
158 | | - test_accuracy, test_acc_out = evaluator.accuracy( |
159 | | - input=predict, label=label) |
160 | | - |
161 | | - test_target = [avg_cost, test_acc_out] + test_accuracy.states().values() |
162 | | - inference_program = get_inference_program(test_target) |
163 | | - |
164 | | - test_accuracy.reset(exe) |
165 | | - |
166 | | - for data in test_reader(): |
167 | | - x_data = np.array(map(lambda x: x[0].reshape(data_shape), |
168 | | - data)).astype("float32") |
169 | | - y_data = np.array(map(lambda x: x[1], data)).astype("int64") |
170 | | - y_data = np.expand_dims(y_data, axis=1) |
171 | | - |
172 | | - tensor_x = core.LoDTensor() |
173 | | - tensor_x.set(x_data, place) |
174 | | - |
175 | | - tensor_y = core.LoDTensor() |
176 | | - tensor_y.set(y_data, place) |
177 | | - |
178 | | - outs = exe.run(inference_program, |
179 | | - feed={'pixel': tensor_x, |
180 | | - 'label': tensor_y}, |
181 | | - fetch_list=[avg_cost, test_acc_out]) |
182 | | - out = np.array(outs[0]) |
183 | | - acc = np.array(outs[1]) |
184 | | - |
185 | | - test_pass_acc = test_accuracy.eval(exe) |
186 | | - |
187 | 152 | print("pass_id:" + str(pass_id) + " batch_id:" + str(batch_id) + |
188 | 153 | " loss:" + str(loss) + " acc:" + str(acc) + " pass_acc:" + str( |
189 | | - pass_acc) + " test_pass_acc:" + str(test_pass_acc)) |
| 154 | + pass_acc)) |
| 155 | + batch_id = batch_id + 1 |
190 | 156 |
|
191 | 157 | if batch_id > 1: |
192 | 158 | # this model is slow, so if we can train two mini batch, we think it works properly. |
|
0 commit comments