I reproduced the code and encountered the same error. However, after making a small adjustment—import tf_keras as keras and replacing tf.keras with keras—the code worked correctly.Please refer to this gist
tf_keras
keras
tf.keras