MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / test

Function test

tensorflow/examples/tf2_showcase/mnist.py:166–181  ·  view source on GitHub ↗

Perform an evaluation of `model` on the examples from `dataset`.

(model, dataset)

Source from the content-addressed store, hash-verified

164
165
166def test(model, dataset):
167 """Perform an evaluation of `model` on the examples from `dataset`."""
168 avg_loss = tfe.metrics.Mean('loss', dtype=tf.float32)
169 accuracy = tfe.metrics.Accuracy('accuracy', dtype=tf.float32)
170
171 for (images, labels) in dataset:
172 logits = model(images, training=False)
173 avg_loss(loss(logits, labels))
174 accuracy(
175 tf.argmax(logits, axis=1, output_type=tf.int64),
176 tf.cast(labels, tf.int64))
177 print('Test set: Average loss: %.4f, Accuracy: %4f%%\n' %
178 (avg_loss.result(), 100 * accuracy.result()))
179 with tf.contrib.summary.always_record_summaries():
180 tf.contrib.summary.scalar('loss', avg_loss.result())
181 tf.contrib.summary.scalar('accuracy', accuracy.result())
182
183
184def train_and_export(flags_obj):

Callers 1

train_and_exportFunction · 0.70

Calls 9

resultMethod · 0.95
modelFunction · 0.85
argmaxMethod · 0.80
lossFunction · 0.70
accuracyFunction · 0.50
MeanMethod · 0.45
castMethod · 0.45
resultMethod · 0.45
scalarMethod · 0.45

Tested by

no test coverage detected