Enthernet Code
Enthernet Code
DIIDevHeads IoT Integration Server
Created by Boss lady on 9/26/2024 in #firmware-and-baremetal
Normalizing Input Data for CNN Model in Image Recognition System on ESP32
It looks like you're encountering a ValueError: Input data not properly normalized while working on your CNN for image recognition. This error implies that your input data needs to be preprocessed before feeding it into your model. - CNNs perform better when the input data is normalized. For images with pixel values ranging from 0 to 255, scaling them to [0, 1] is standard practice. Normalize your images like this:
train_images = train_images / 255.0
test_images = test_images / 255.0

train_images = train_images / 255.0
test_images = test_images / 255.0

- Check that the dimensions of your images match the expected input shape of your model. If your first convolutional layer expects grayscale images of shape (224, 224, 1), but your images are RGB, adjust the input_shape accordingly:
model = models.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(1, activation='sigmoid')
])

model = models.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(1, activation='sigmoid')
])

- Ensure your data (train_images and test_images) is in a compatible format for TensorFlow, such as numpy arrays or TensorFlow tensors. Incompatible data types can cause issues.
5 replies