The difference between Train accuracy and Test accuracy

My Train Code
My Inference Code

Question

I try to classify the Mnist dataset. The models train accuracy is 90% and valid accuracy approach 80%. But the test accuracy is 50%. I think my model is overfitting. So I made a chart about train acc and valid acc.(batch size 16, epoch 100)

[Train acc]
image

[Valid acc]
image

Why there is a difference between Train accuracy and Test accuracy?

Things I tried

  1. Drop out
  2. Add more Activation functions