I also encountered this issue in VScode. the code works fine without any exceptions. The problem was autocompletion is not there when dealing with
from tensorflow.keras.models import *
and
from tensorflow.keras.layers import *
Instead write
from keras.api.models import *
and
from keras.api.layers import *
note : this solution is for tensorflow version 2.7.0 + (i think)