File size: 3,105 Bytes
83ebd30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
license: mit
tags:
- image-classification
- medical
- microscopy
- sperm-analysis
- pytorch
library_name: pytorch
---

# Sperm Agglutinine Presence Detector

## Model Description

This model detects the presence of agglutinine in human sperm microscopic images using a ResNet50 architecture.

**Architecture**: ResNet50 with custom classifier head  
**Task**: Binary Image Classification  
**Classes**: Negative, Positive  
**Input**: Single frame, 800x600 RGB  
**Framework**: PyTorch

## Intended Use

This model is designed for detecting agglutinine presence in human sperm microscopic images. It's intended for research and diagnostic support in reproductive medicine.

## Model Details

- **Input Format**: Single RGB image from microscopic video
- **Preprocessing**: 
  - Resize to 800x600
  - ImageNet normalization
- **Output**: Binary classification (Negative/Positive)

## Architecture Details

- **Backbone**: ResNet50 (pretrained on ImageNet)
- **Classifier Head**: 
  - Dropout(0.5)
  - Linear(2048 → 512)
  - ReLU
  - Dropout(0.3)
  - Linear(512 → 2)

## Usage

```python
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
import numpy as np

# Define model architecture
model = models.resnet50(pretrained=False)
num_ftrs = model.fc.in_features
model.fc = nn.Sequential(
    nn.Dropout(0.5),
    nn.Linear(num_ftrs, 512),
    nn.ReLU(),
    nn.Dropout(0.3),
    nn.Linear(512, 2)
)

# Load weights
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
checkpoint = torch.load('agglutinine_presence.pth', map_location=device)
model.load_state_dict(checkpoint['model_state_dict'] if 'model_state_dict' in checkpoint else checkpoint)
model.to(device)
model.eval()

# Define preprocessing
transform = transforms.Compose([
    transforms.Resize((600, 800)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

# Load and preprocess image
image = Image.open("path/to/image.jpg").convert('RGB')
image_tensor = transform(image).unsqueeze(0).to(device)

# Inference
with torch.no_grad():
    outputs = model(image_tensor)
    probabilities = torch.softmax(outputs, dim=1)
    predicted_class = torch.argmax(probabilities, dim=1).item()
    confidence = probabilities[0][predicted_class].item()

class_names = ["Negative", "Positive"]
print(f"Prediction: {class_names[predicted_class]}")
print(f"Confidence: {confidence:.4f}")
print(f"Positive probability: {probabilities[0][1].item():.4f}")
```

## Limitations

- Trained on specific microscopy equipment and protocols
- Performance may vary with different imaging conditions
- Should be used as diagnostic support, not sole decision-making tool
- Single-frame analysis may not capture temporal dynamics

## Citation

If you use this model, please cite:

```
@misc{sperm-agglutinine-detector,
  author = {Raid Athmane Benlala},
  title = {Sperm Agglutinine Presence Detector},
  year = {2025},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/raidAthmaneBenlala/agglutinine-detector}}
}
```