'Input to reshape is a tensor with 9 values, but the requested shape requires a multiple of 32

I'm trying to implement a deep learning model with differential privacy I used TensorFlow Privacy with Keras but always get this error

here is my code :

import tensorflow_privacy
from tensorflow_privacy.privacy.analysis import compute_dp_sgd_privacy
import tensorflow as tf

from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Dense

epochs = 10
batch_size = 32
l2_norm_clip = 1.5
noise_multiplier = 1.3
num_microbatches = 32
learning_rate = 0.25
model = keras.Sequential()
model.add(Dense(27, activation="relu", input_shape=(187,)))
model.add(Dense(27, activation="relu"))
model.add(Dense(1, activation='sigmoid'))
optimizer = tensorflow_privacy.DPKerasSGDOptimizer(
    l2_norm_clip=l2_norm_clip,
    noise_multiplier=noise_multiplier,
    num_microbatches=num_microbatches,
    learning_rate=learning_rate)
loss = tf.keras.losses.BinaryCrossentropy(
    from_logits=False, reduction=tf.losses.Reduction.NONE)

model.compile(optimizer=optimizer, loss=loss,
    metrics='accuracy')
model.fit(
    X_train,y_train,batch_size=batch_size, epochs=epochs,
   
)

I tried many solutions but with no results



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source