raidAthmaneBenlala commited on
Commit
83ebd30
·
verified ·
1 Parent(s): d682e41

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +116 -0
README.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - image-classification
5
+ - medical
6
+ - microscopy
7
+ - sperm-analysis
8
+ - pytorch
9
+ library_name: pytorch
10
+ ---
11
+
12
+ # Sperm Agglutinine Presence Detector
13
+
14
+ ## Model Description
15
+
16
+ This model detects the presence of agglutinine in human sperm microscopic images using a ResNet50 architecture.
17
+
18
+ **Architecture**: ResNet50 with custom classifier head
19
+ **Task**: Binary Image Classification
20
+ **Classes**: Negative, Positive
21
+ **Input**: Single frame, 800x600 RGB
22
+ **Framework**: PyTorch
23
+
24
+ ## Intended Use
25
+
26
+ This model is designed for detecting agglutinine presence in human sperm microscopic images. It's intended for research and diagnostic support in reproductive medicine.
27
+
28
+ ## Model Details
29
+
30
+ - **Input Format**: Single RGB image from microscopic video
31
+ - **Preprocessing**:
32
+ - Resize to 800x600
33
+ - ImageNet normalization
34
+ - **Output**: Binary classification (Negative/Positive)
35
+
36
+ ## Architecture Details
37
+
38
+ - **Backbone**: ResNet50 (pretrained on ImageNet)
39
+ - **Classifier Head**:
40
+ - Dropout(0.5)
41
+ - Linear(2048 → 512)
42
+ - ReLU
43
+ - Dropout(0.3)
44
+ - Linear(512 → 2)
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ import torch
50
+ import torch.nn as nn
51
+ from torchvision import models, transforms
52
+ from PIL import Image
53
+ import numpy as np
54
+
55
+ # Define model architecture
56
+ model = models.resnet50(pretrained=False)
57
+ num_ftrs = model.fc.in_features
58
+ model.fc = nn.Sequential(
59
+ nn.Dropout(0.5),
60
+ nn.Linear(num_ftrs, 512),
61
+ nn.ReLU(),
62
+ nn.Dropout(0.3),
63
+ nn.Linear(512, 2)
64
+ )
65
+
66
+ # Load weights
67
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
68
+ checkpoint = torch.load('agglutinine_presence.pth', map_location=device)
69
+ model.load_state_dict(checkpoint['model_state_dict'] if 'model_state_dict' in checkpoint else checkpoint)
70
+ model.to(device)
71
+ model.eval()
72
+
73
+ # Define preprocessing
74
+ transform = transforms.Compose([
75
+ transforms.Resize((600, 800)),
76
+ transforms.ToTensor(),
77
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
78
+ ])
79
+
80
+ # Load and preprocess image
81
+ image = Image.open("path/to/image.jpg").convert('RGB')
82
+ image_tensor = transform(image).unsqueeze(0).to(device)
83
+
84
+ # Inference
85
+ with torch.no_grad():
86
+ outputs = model(image_tensor)
87
+ probabilities = torch.softmax(outputs, dim=1)
88
+ predicted_class = torch.argmax(probabilities, dim=1).item()
89
+ confidence = probabilities[0][predicted_class].item()
90
+
91
+ class_names = ["Negative", "Positive"]
92
+ print(f"Prediction: {class_names[predicted_class]}")
93
+ print(f"Confidence: {confidence:.4f}")
94
+ print(f"Positive probability: {probabilities[0][1].item():.4f}")
95
+ ```
96
+
97
+ ## Limitations
98
+
99
+ - Trained on specific microscopy equipment and protocols
100
+ - Performance may vary with different imaging conditions
101
+ - Should be used as diagnostic support, not sole decision-making tool
102
+ - Single-frame analysis may not capture temporal dynamics
103
+
104
+ ## Citation
105
+
106
+ If you use this model, please cite:
107
+
108
+ ```
109
+ @misc{sperm-agglutinine-detector,
110
+ author = {Raid Athmane Benlala},
111
+ title = {Sperm Agglutinine Presence Detector},
112
+ year = {2025},
113
+ publisher = {Hugging Face},
114
+ howpublished = {\url{https://huggingface.co/raidAthmaneBenlala/agglutinine-detector}}
115
+ }
116
+ ```