I was simplifying my model in order to see where the NaN error occurs and narrowed it down to my loss function:
import tensorflow as tf
from tensorflow.python import debug as tf_debug
def train_input_fn():
pass
def model_fn(features, labels, mode, params):
classes = 225
enc = tf.ones((1,20,1024), dtype=tf.float16)
labels = tf.ones((1,20), dtype=tf.int32)
logits = tf.layers.dense(enc, classes)
loss = tf.reduce_sum(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels)) / 20
train_op = tf.train.AdamOptimizer(learning_rate=0.00001, beta1=0.9, beta2=0.999).minimize(loss)
return tf.estimator.EstimatorSpec(mode, loss=loss, train_op=train_op)
if __name__ == '__main__':
model_directory = path/to/logdir
hooks = [tf_debug.LocalCLIDebugHook(ui_type="readline")]
classifier = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=model_directory,
params={},
)
classifier.train(input_fn=lambda: train_input_fn(), hooks = hooks)
After the third or fourth 'run' with the tensorflow debugger on a fresh model directory I get 'NaN loss during training.'. I already tried to set the learning rate very low, but nothing changed. I'm using tensorflow-gpu 1.8.