In early 2025, I set out to build MEDINSIGHT AI — a deep learning system that classifies chest X-rays with 92.4% accuracy using only open-source tools. Here’s the full journey — from data to deployment.
1. Dataset & Preprocessing
Used the Chest X-Ray Images (Pneumonia) dataset from Kaggle — 5,863 images across Normal, Bacterial, and Viral classes.
- Resized to 224×224 (ResNet input)
- Applied CLAHE for contrast enhancement
- Augmented with rotation, flip, zoom
2. Model Architecture: Transfer Learning
Chose ResNet-50 pretrained on ImageNet. Froze early layers, fine-tuned the top.
import tensorflow as tf
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras.models import Model
base = ResNet50(weights='imagenet', include_top=False, input_shape=(224,224,3))
x = base.output
x = GlobalAveragePooling2D()(x)
x = Dense(512, activation='relu')(x)
predictions = Dense(3, activation='softmax')(x)
model = Model(inputs=base.input, outputs=predictions)
# Freeze base layers
for layer in base.layers:
layer.trainable = False
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
3. Training & Results
Trained on Google Colab Pro (T4 GPU) for 25 epochs. Used ReduceLROnPlateau and EarlyStopping.
- Validation Accuracy: 92.4%
- Precision (Pneumonia): 95%
- Inference Time: ~40ms per image
4. Flask API Deployment
Built a REST API using Flask + Gunicorn. Accepts base64 image → returns JSON prediction.
@app.route('/predict', methods=['POST'])
def predict():
data = request.json['image']
img = base64_to_image(data)
img = preprocess(img)
pred = model.predict(img)
return jsonify({'class': CLASSES[np.argmax(pred)], 'confidence': float(np.max(pred))})
5. Docker + Nginx Production
Containerized the app and served via Nginx reverse proxy with SSL.
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
Key Learnings
- Mixed precision training → 2.3× faster
- Grad-CAM for explainability → doctors loved it
- Always validate on external datasets
MEDINSIGHT AI is now live at medinsight.vishalkadam.in (demo).