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]
train

[Valid acc]
valid

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

Things I tried

  1. Drop out
  2. Add more Activation functions

Welcome to the GitHub community, @cjfghk5697 ! We’re happy you’re here. You are more likely to get a useful response if you are posting your question(s) in the applicable category. I’ve gone ahead and moved it for you. Good luck!