This model classifies cervical images into 3 transformation zone types, which is important for colposcopy evaluation and cervical cancer screening.
┌─────────────────────────────────────────────────────────────┐
│ INPUT (256×256×3) │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ CONV BLOCK 1 │
│ Conv2d(3→32, 3×3) → BatchNorm2d → ReLU → MaxPool2d(2×2) │
│ Output: 128×128×32 │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ CONV BLOCK 2 │
│ Conv2d(32→64, 3×3) → BatchNorm2d → ReLU → MaxPool2d(2×2) │
│ Output: 64×64×64 │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ CONV BLOCK 3 │
│ Conv2d(64→128, 3×3) → BatchNorm2d → ReLU → MaxPool2d(2×2) │
│ Output: 32×32×128 │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ CONV BLOCK 4 │
│ Conv2d(128→256, 3×3) → BatchNorm2d → ReLU → MaxPool2d(2×2)│
│ Output: 16×16×256 │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ GLOBAL POOLING │
│ AdaptiveAvgPool2d(1×1) │
│ Output: 1×1×256 → Flatten → 256 │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ FC BLOCK 1 │
│ Linear(256→256) → ReLU → Dropout(0.4) │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ FC BLOCK 2 │
│ Linear(256→128) → ReLU → Dropout(0.4) │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ CLASSIFIER │
│ Linear(128→3) │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ OUTPUT (3 logits) │
│ [Type 1, Type 2, Type 3] │
└─────────────────────────────────────────────────────────────┘
1import torch
2from PIL import Image
3from torchvision import transforms
4
5# Load model
6from model import BaseCNN
7model = BaseCNN.from_pretrained("./")
8model.eval()
9
10# Preprocess image
11transform = transforms.Compose([
12 transforms.Resize((256, 256)),
13 transforms.ToTensor(),
14])
15
16image = Image.open("cervical_image.jpg").convert("RGB")
17input_tensor = transform(image).unsqueeze(0)
18
19# Inference
20with torch.no_grad():
21 output = model(input_tensor)
22 probabilities = torch.softmax(output, dim=1)
23 prediction = output.argmax(dim=1).item()
24
25labels = ["Type 1", "Type 2", "Type 3"]
26print(f"Prediction: {labels[prediction]}")
27print(f"Confidence: {probabilities[0][prediction]:.2%}")
1from huggingface_hub import hf_hub_download
2from safetensors.torch import load_file
3import torch
4import json
5import importlib.util
6
7# Download files
8repo_id = "toderian/cerviguard_transfer_zones"
9model_weights = hf_hub_download(repo_id, "model.safetensors")
10config_file = hf_hub_download(repo_id, "config.json")
11model_file = hf_hub_download(repo_id, "model.py")
12
13# Load model class dynamically
14spec = importlib.util.spec_from_file_location("model", model_file)
15model_module = importlib.util.module_from_spec(spec)
16spec.loader.exec_module(model_module)
17
18# Load config and create model
19with open(config_file) as f:
20 config = json.load(f)
21
22model = model_module.BaseCNN(**config['model_config'])
23model.load_state_dict(load_file(model_weights))
24model.eval()
25
26# Now use model for inference
1@misc{cerviguard-transfer-zones,
2 title={CerviGuard Cervical Transformation Zone Classifier},
3 author={toderian},
4 year={2026},
5 howpublished={\url{https://huggingface.co/toderian/cerviguard_transfer_zones}}
6}