Can a trained ANN (tensorflow) model be made predictable?

Viewed 41

I'm new to ANN, but I've managed to train a convolutional model successfully (using some legacy tensorflow v1 code) up to ~90% accuracy or so on my data. But when I evaluate (test) it on any given batch, the result is somewhat random, even though it's 90% correct. I've tried to re-evaluate the data N times and averaging (using N's between 1 and 25), but still each evaluation differs from the others between 3% to 10% of the data points.

Is there any way to make the evaluation predictable, so that the evaluation of an input batch X always yield the exact same result Y every time I run it (once training is done)?

I'm not sure if it's relevant, but my layers are batch normalized like so:

inp = tf.identity(inp)
channels = inp.get_shape()[-1]
offset = tf.compat.v1.get_variable(
             'offset', [channels],
             dtype=tf.float32,
             initializer=tf.compat.v1.zeros_initializer())
scale = tf.compat.v1.get_variable(
            'scale', [channels],
            dtype=tf.float32,
            initializer=tf.compat.v1.random_normal_initializer(1.0, 0.02))
mean, variance = tf.nn.moments(x=inp, axes=[0, 1], keepdims=False)
variance_epsilon = 1e-5
normalized = tf.nn.batch_normalization(
                 inp, mean, variance, offset, scale, variance_epsilon=variance_epsilon)

The scale part is initialized with random data, but I assume that gets loaded when I do tf.compat.v1.train.Saver().restore(session, checkpoint_fname)?

1 Answers

I am assuming you are testing the model on your training batches?

You can't equate the accuracy of a portion of your total training dataset to the accuracy of the whole.

Think of it like a regression problem. If you only take a part of the dataset, there is no guarantee that it would average out close to the full dataset.

If you want consistent accuracy, evaluate on the full dataset.

Related