File size: 5,865 Bytes
2f24079
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
license: mit
tags:
  - pytorch
  - computer-vision
  - medical-imaging
  - multi-task-learning
  - classification
  - regression
  - single-cell
  - microscopy
  - white-blood-cell
datasets:
  - BSCCM
  - BCCD
language:
  - en
pipeline_tag: image-classification
---

# Single-Cell Phenotyping β€” Hybrid CNN-ViT Multi-Task Model

**Paper:** [Towards Label-Free Single-Cell Phenotyping Using Multi-Task Learning](https://arxiv.org/abs/2605.14717)  
**Authors:** Saqib Nazir and Ardhendu Behera (Edge Hill University, UK)  
**Conference:** ICPR 2026  
**Code:** [github.com/saqibnaziir/Single-Cell-Phenotyping](https://github.com/saqibnaziir/Single-Cell-Phenotyping)

---

## Model Description

A unified deep learning framework that jointly performs **White Blood Cell (WBC) classification** and **continuous protein-expression regression** from label-free Differential Phase Contrast (DPC) microscopy images β€” *without fluorescent staining*.

### Architecture

```
Input: (B, 4, 28, 28)  ← 4-channel DPC (Left, Right, Top, Bottom)
    β”‚
    └─ Shared ECA Channel Attention
           β”œβ”€ CNN Branch: Stem β†’ InceptionΓ—2 + Residual β†’ (B, 196, 192)
           └─ ViT Branch: Patch(4Γ—4) β†’ TransformerΓ—2 β†’ (B, 50, 128)
                  β”‚
                  └─ Cross-Modal Fusion (256-dim, learnable weights)
                         β”œβ”€ Task-Specific Refinement
                         └─ Task Gating (bidirectional cross-task exchange)
                                β”œβ”€ Classification Head β†’ (B, 3)
                                └─ Regression Head    β†’ (B, 4)
```

- **Parameters:** ~12M
- **FLOPs:** ~0.8 GFLOPs per 28Γ—28 image (real-time capable)
- **Input:** 4-channel DPC images, 28Γ—28 pixels

### Tasks

| Task | Output | Classes / Markers |
|---|---|---|
| WBC Classification | 3 classes | Lymphocyte, Granulocyte, Monocyte |
| Protein Regression | 4 markers | CD45, CD3, CD19, CD14 |

---

## Files in This Repository

| File | Description |
|---|---|
| `bsccm_best_model.pth` | Best checkpoint on BSCCM dataset (91.3% accuracy) |
| `bccd_best_model.pth` | Best checkpoint on BCCD benchmark (93.77% accuracy) |

---

## Performance

### BSCCM Dataset

| Metric | Value |
|---|---|
| WBC Classification Accuracy | **91.3%** |
| Macro F1-Score | **0.92** |
| Pearson r (CD16 regression) | **0.73** |
| RMSE | 0.68 |

### BCCD Benchmark (Classification Only)

| Class | Precision | Recall | F1 |
|---|---|---|---|
| Lymphocyte | 1.000 | 1.000 | 1.000 |
| Granulocyte | 0.889 | 1.000 | 0.941 |
| Monocyte | 1.000 | 0.750 | 0.857 |
| **Macro Avg.** | **0.963** | **0.917** | **0.933** |

Overall BCCD accuracy: **93.77%**

---

## Usage

### Installation

```bash
git clone https://github.com/saqibnaziir/Single-Cell-Phenotyping.git
cd Single-Cell-Phenotyping
pip install -r requirements.txt
```

### Load Model

```python
import torch
from huggingface_hub import hf_hub_download
from model import create_model

# Download checkpoint
ckpt_path = hf_hub_download(
    repo_id="saqialii/single-cell-phenotyping",
    filename="bsccm_best_model.pth"
)

# Create model and load weights
model = create_model(num_classes=3, num_proteins=4, img_size=28, in_channels=4)
checkpoint = torch.load(ckpt_path, map_location='cpu', weights_only=False)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()

print(f"Loaded model β€” best val accuracy: {checkpoint['best_val_acc']:.2f}%")
```

### Inference

```python
import torch
import torch.nn.functional as F

# Input: (B, 4, 28, 28) β€” 4-channel DPC image, normalised to [-1, 1]
image = torch.randn(1, 4, 28, 28)  # replace with real image

with torch.no_grad():
    cls_logits, prot_preds = model(image)

# Cell type classification
probs = F.softmax(cls_logits, dim=1)
class_names = ['Lymphocyte', 'Granulocyte', 'Monocyte']
predicted_class = class_names[probs.argmax().item()]
confidence = probs.max().item()

print(f"Predicted: {predicted_class} ({confidence:.1%})")

# Protein expression (Z-scored)
protein_names = ['CD45', 'CD3', 'CD19', 'CD14']
for name, val in zip(protein_names, prot_preds[0].tolist()):
    print(f"  {name}: {val:.3f}")
```

### Data Preparation

```bash
# Download BSCCM dataset
pip install bsccm
python -c "from bsccm import download_dataset; download_dataset('./data', mnist=True)"

# Train from scratch
python train.py --data_path ./data/BSCCMNIST --save_dir checkpoints/run1

# Evaluate
python evaluate.py \
    --model_path checkpoints/run1/best_model.pth \
    --data_path ./data/BSCCMNIST \
    --output_dir evaluation_results
```

---

## Dataset

**BSCCM** (Berkeley Single Cell Computational Microscopy):
- 7,889 single-cell DPC images at 28Γ—28 pixels
- 3 WBC classes: Lymphocyte (456), Granulocyte (736), Monocyte (226) β€” test split
- 4 protein markers measured by fluorescence: CD45, CD3, CD19, CD14
- Source: [Waller-Lab/BSCCM](https://github.com/Waller-Lab/BSCCM)

**BCCD** (Blood Cell Images):
- ~12,000 RGB images at 128Γ—128 pixels (4-class β†’ mapped to 3-class)
- Source: [Kaggle: Blood Cell Images](https://www.kaggle.com/datasets/paultimothymooney/blood-cells)

---

## Citation

```bibtex
@inproceedings{nazir2026label,
  title     = {Towards Label-Free Single-Cell Phenotyping Using Multi-Task Learning},
  author    = {Nazir, Saqib and Behera, Ardhendu},
  booktitle = {Proceedings of the International Conference on Pattern Recognition (ICPR)},
  year      = {2026},
  note      = {arXiv:2605.14717}
}
```

```bibtex
@article{pinkard2024berkeley,
  title   = {Berkeley Single Cell Computational Microscopy Dataset},
  author  = {Pinkard, Henry and others},
  journal = {arXiv preprint arXiv:2402.06191},
  year    = {2024}
}
```

---

## License

[MIT License](https://github.com/saqibnaziir/Single-Cell-Phenotyping/blob/main/LICENSE) β€” Saqib Nazir, Ardhendu Behera, Edge Hill University, 2026