I understand that tensorflow version 2.x are eager execution enabled. However, I see a big performance and speed difference if I import Keras from tensorflow via tensorflow.python.keras vs tensorflow.keras. I am using tensorflow version 2.3.1.
I can train my model much faster in 50 epochs reaching 100% accuracy by importing Keras via python.keras, whereas my model never gets 100% accuracy with test data even with 100 epochs if I import Keras as tensorflow.keras.
Fast execution (also used in kaggle tutorials)
from tensorflow.python import keras
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, Flatten, Conv2D, Dropout, MaxPooling2D
from tensorflow.python.keras.callbacks import ModelCheckpoint
from tensorflow.keras.optimizers import Adam
Slow Execution:
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, Dropout, MaxPooling2D
from tensorflow.keras.callbacks import ModelCheckpoint
from tensorflow.keras.optimizers import Adam
My model details and results are here: https://github.com/skhalil/DataScience/blob/master/Projects/AdidasVsNike/WithKeras.ipynb