Keras and Tensorflow with identical weights but different test accuracy -
i have trained tensorflow model , built equivalent keras model , loaded learned weights it. however, different test accuracy in keras (e.g. 98.5% in tensorflow compared 98%). have defined accuracy in tensorflow way:
accuracy = tf.cast(tf.equal(tf.argmax(input_labels, 1), tf.argmax(output, 1)), tf.float32)
in keras have used standard metric:
model.compile(optimizer=tf.train.adamoptimizer(), loss='categorical_crossentropy', metrics=['accuracy'])
accuracy = model.evaluate(x=test_images, y=test_labels, batch_size=batch_size)
i confused discrepancy comes from.
edit: since not convinced answer, spent couple of days more on code until discovered bug caused discrepancy, , after fixing it, both frameworks produce identical results same weights expected. writing edit prevent confusion other readers, stackoverflow not allow me delete question.
one possible reason: dropout layer in model.
according the source code, internal random logic implemented tf.random_uniform, randomly generate new value on each call sess.run()
.
Comments
Post a Comment