keras - cannot import name Conv2D

Following packages which are very essential for CNN (Convolutional Neural Networks) are reorganized into different packages

from keras.layers.convolutional import Conv2D
from keras.layers import Dense
from keras.layers.convolutional import MaxPooling2D
from keras.layers import Flatten

Whenever you get an import error always google the name for the package and the library it is associated for example google "Keras Convolution2D". It will direct you to the keras documentation. That will easily give away the path to import.


Try this: from keras.layers.convolutional import Conv2D

Importing changed with the new keras. Are you sure you are not using keras >= 2?


NOTE:

With tensorflow 2.0 keras is included. You can now import the layer with:

from tensorflow.keras.layers import Conv2D

For Keras 1.2.0 (the current one on floydhub as of print(keras.__version__)) use these imports for Conv2D (which you use) and Conv2DTranspose (used in the Keras examples):

from keras.layers import Convolution2D as Conv2D
from keras.layers.convolutional import Deconv2D as Conv2DTranspose