Unable To Fit Data to Conv2D Model

I have data set of images and labels the are multi-hot encoded using CategoryEncoding. I created a CNN model, but I am getting a Warning saying that my shape is incorrect. The model is compiled with an input layer of (512, 512, 1) and it says that my input is (512, 512, 1, 1). I am not sure how this is happening when I printed out the shape of my data set after creating it using Dataset.from_tensor_slices and it was (512, 512, 1).
I also got a ValueError saying:

Exception encountered when calling layer “Seqeuntial”
Input 0 of layer “dense” is incompatible with the layer: expected axis -1 of input shape to have value 1048576, but received input withg shap (512, 16384)

Here is my model:

Sequential([
        layers.Conv2D(64, 7, padding='same', activation='relu', input_shape=(512, 512, 1)),
        layers.MaxPooling2D(pool_size=(2, 2), padding='same'),
        layers.Conv2D(128, 3, padding='same', activation='relu'),
        layers.Conv2D(128, 3, padding='same', activation='relu'),
        layers.MaxPooling2D(pool_size=(2, 2), padding='same'),
        layers.Conv2D(256, 3, padding='same', activation='relu'),
        layers.Conv2D(256, 3, padding='same', activation='relu'),
        layers.MaxPooling2D(pool_size=(2, 2), padding='same'),
        layers.Flatten(),
        layers.Dense(128, activation='relu'),
        layers.Dropout(0.5),
        layers.Dense(64, activation='relu'),
        layers.Dropout(0.5),
        layers.Dense(7, activation='softmax')
    ])