Pretrained Keras/TensorFlow Model Integration Issues in Web App (Bone Tumor Detection) Input 0 of layer "stem_conv" is incompatible with the layer: expected axis -1 of input shape to have value 3, but received input with shape (None, 385, 385, 1)

,

I’m working on my final-year project: an AI-driven Bone Tumor Detection system that detects and classifies bone tumors from X-ray images. The system performs multiclass classification, pathology prediction, and tumor segmentation, and also generates Grad-CAM visualizations to explain model predictions.

Model & Training Details:

  • Pretrained EfficientNetB0 multitask CNN in Keras/TensorFlow.

  • Trained on X-ray images to perform three tasks:

    1. Multiclass classification (benign, malignant, normal)

    2. Pathology detection (multi-label)

    3. Tumor segmentation

  • Loss function: Binary cross-entropy + Dice loss for segmentation.

  • Input: RGB, 384x384, normalized to [-1,1].

  • Training was done on Colab with T4 GPU, and the model gives correct outputs during training/testing.

Backend Integration:

  • Using Flask to receive images, preprocess, and run inference.

  • Preprocessing: convert to RGB if needed, resize to 384x384, normalize to [-1,1].

  • Postprocessing: extract classification, pathology, and segmentation outputs.

  • Grad-CAM overlay implemented for interpretability.

Errors Encountered:

  1. Model input shape mismatch:
Input 0 of layer "stem_conv" is incompatible with the layer: expected axis -1 of input shape to have value 3, but received input with shape (None, 385, 385, 1)

  • Model expects 3-channel RGB input, but some inputs are coming through as single-channel.
  1. Input normalization warning:
Warning: Input image does not appear to be normalized correctly. The input image has the range [0.00,0.96] which doesn't seem to be in the [-1024,1024] range

  • Even though I normalize to [-1,1], this warning appears, suggesting a mismatch between expected preprocessing and the model’s actual input.

What I’ve Tried:

  • Ensuring all images are converted to RGB.

  • Adjusting resizing and normalization.

  • Tweaking model loading and preprocessing code.

  • Following AI-suggested solutions and retraining the model.

Unfortunately, these errors still persist, preventing proper inference and Grad-CAM generation.

Request for Guidance:

I would greatly appreciate advice on:

  • Correct preprocessing and normalization to ensure compatibility with pretrained Keras/TensorFlow models.

  • Handling shape mismatches for RGB/grayscale inputs.

  • Best practices for integrating pretrained Keras/TensorFlow models into web backends for inference.