tajnin2001/segmentation_model
Medical Tissue Segmentation — MultiRes Model Collection
This repository contains trained Keras segmentation models used for biomedical/medical tissue image segmentation. The models were trained to detect multiple tissue segments at different resolution levels and are intended for research and evaluation with medical imaging datasets.
Models included
attention_tissue_epoch40_datasetsize16000_fullmodel_16_days.kerasmultires_tissue_epoch340_datasetsize16000_fullmodel_15_days.kerassharp_tissue_epoch255_datasetsize16000_fullmodel_14Days.kerasunet_tissue_epoch70_datasetsize15836_fullmodel_1month.keras
(These are full Keras model files saved with the .keras format.)
Project overview
- Purpose: Multi-resolution segmentation of tissue images (medical imaging). The
multiresmodel is a multi-resolution architecture; other models include U-Net, attention variants and models trained with sharpening/loss tweaks. - Input: image tiles or full images (model input shape can vary between files). Inspect the model with
model.summary()to confirm the expected input shape and number of output classes. - Output: segmentation masks (per-pixel class probabilities or labels). Post-processing may be needed (argmax, thresholding, morphological ops).
Quick start (inference)
Recommended Python packages (example):
- Python 3.8+ (use a virtual environment)
- tensorflow (tested with 2.x)
- numpy, opencv-python (or pillow)
Install minimal deps:
python -m venv .venv; .\.venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install -r requirements.txtExample inference script (Python):
import numpy as np
import tensorflow as tf
import cv2
# adjust path to your model file
model_path = r"c:\Users\anik1\Desktop\model_segmentation\multires_tissue_epoch340_datasetsize16000_fullmodel_15_days.keras"
model = tf.keras.models.load_model(model_path, compile=False)
print(model.summary())
# load an example image (grayscale or RGB depending on model)
img = cv2.imread('path/to/image.png', cv2.IMREAD_COLOR)
# resize to model input if needed (example 256x256)
img_resized = cv2.resize(img, (256, 256))
# normalize
img_resized = img_resized.astype('float32') / 255.0
# add batch dim
x = np.expand_dims(img_resized, axis=0)
pred = model.predict(x)
# post-process: if model outputs class probabilities per pixel
mask = np.argmax(pred[0], axis=-1)
# save or visualize
cv2.imwrite('pred_mask.png', (mask.astype('uint8') * 50))Notes:
- Replace the resize shape with the model's expected input. Use
model.input_shapeormodel.summary()to confirm. - If your model expects single-channel input, convert with
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)and expand dims accordingly.
Included helper scripts
infer.py— a small batch inference script that loads a.kerasmodel, runs prediction on all images in a folder, and writes predicted masks to an output folder. See header comments for usage.validate.py— computes Dice and IoU scores given a folder of predicted masks and a folder of ground-truth masks (PNG masks). Useful for quick validation runs.requirements.txt— minimal recommended Python packages: TensorFlow, NumPy and OpenCV.
Inspect model details
Use these quick checks inside Python to learn more about a .keras model:
model = tf.keras.models.load_model(model_path, compile=False)
print('Input shape:', model.input_shape)
print('Output shape:', model.output_shape)
model.summary()Evaluation & metrics
Common segmentation metrics to compute for validation:
- Dice / F1 score
- IoU (Jaccard)
- Precision / recall per class
Provide ground-truth masks and compute metrics on held-out data. Consider per-class reporting when multiple tissue classes are present.
Medical data & compliance
These models were trained on medical tissue images — be careful with privacy, patient data protection, and clinical use. This code and the models are provided for research and development only, not for clinical diagnosis. If you plan to use models in any regulated setting, follow local laws and institutional review board (IRB) rules.
Limitations and notes
- Input size and pre-processing must match training (normalization, channel order, tiling strategy).
- Model performance depends on dataset shift; re-evaluate if your input modality or staining differs.
- Consider inference tiling/overlap for large images to avoid memory issues.
Next steps / suggestions
- Add small validation scripts to compute Dice/IoU on a labelled dataset. (
validate.pyincluded) - Provide a lightweight wrapper script that accepts a folder of images and writes masks to disk. (
infer.pyincluded) - Package model-specific preprocessing functions (normalization, resizing rules).
License & contact
Add an appropriate license file if you want to share these models (e.g., MIT, Apache-2.0). For questions, add your contact or project maintainer information here.
Generated README: describes the included .keras segmentation models, quick inference and inspection steps, and notes about medical usage and evaluation.
