Views
No views yet
tta1301/nih-chest-xray-small| Statistic | Value |
|---|---|
| Total images | >10,000 |
| Disease classes | 15 (14 diseases + No Finding) |
| Train/Val/Test split | 70/15/15 |
| Image size | 224x224 |
| Index | Disease (English) | Disease (Vietnamese) |
|---|---|---|
| 0 | No Finding | Không phát hiện bất thường |
| 1 | Atelectasis | Xẹp phổi |
| 2 | Cardiomegaly | Tim to |
| 3 | Effusion | Tràn dịch màng phổi |
| 4 | Infiltration | Thâm nhiễm phổi |
| 5 | Mass | Khối u phổi |
| 6 | Nodule | Nốt phổi |
| 7 | Pneumonia | Viêm phổi |
| 8 | Pneumothorax | Tràn khí màng phổi |
| 9 | Consolidation | Đông đặc phổi |
| 10 | Edema | Phù phổi |
| 11 | Emphysema | Khí phế thũng |
| 12 | Fibrosis | Xơ phổi |
| 13 | Pleural_Thickening | Dày màng phổi |
| 14 | Hernia | Thoát vị hoành |
| Epoch | Loss |
|---|---|
| 0 | 0.7709 |
| 20 | 0.3218 |
| 40 | 0.1987 |
| 69 | 0.1168 |
| Metric | Train | Validation | Test |
|---|---|---|---|
| Accuracy | 0.9306 | 0.9307 | 0.9025 |
| Micro F1 | 0.9254 | 0.9213 | 0.8932 |
| Macro F1 | 0.8912 | 0.8876 | 0.8567 |
| ROC-AUC | 0.9789 | 0.9754 | 0.9612 |
| Disease | F1 |
|---|---|
| No Finding | 0.95 |
| Hernia | 0.945 |
| Pneumothorax | 0.912 |
| Cardiomegaly | 0.903 |
| Edema | 0.894 |
| Pneumonia | 0.892 |
| Effusion | 0.885 |
| Mass | 0.876 |
| Consolidation | 0.873 |
| Atelectasis | 0.859 |
| Emphysema | 0.854 |
| Nodule | 0.843 |
| Fibrosis | 0.833 |
| Pleural_Thickening | 0.823 |
| Infiltration | 0.812 |
1from transformers import AutoImageProcessor, AutoModelForImageClassification
2import torch
3from PIL import Image
4
5# Load model
6processor = AutoImageProcessor.from_pretrained("tta1301/xray-vit-classifier-v3")
7model = AutoModelForImageClassification.from_pretrained("tta1301/xray-vit-classifier-v3")
8model.eval()
9
10# Disease labels (updated order with No Finding)
11DISEASES = [
12 'No Finding', # 0
13 'Atelectasis', # 1
14 'Cardiomegaly', # 2
15 'Effusion', # 3
16 'Infiltration', # 4
17 'Mass', # 5
18 'Nodule', # 6
19 'Pneumonia', # 7
20 'Pneumothorax', # 8
21 'Consolidation', # 9
22 'Edema', # 10
23 'Emphysema', # 11
24 'Fibrosis', # 12
25 'Pleural_Thickening', # 13
26 'Hernia' # 14
27]
28
29def predict_chest_xray(image_path, threshold=0.3):
30 image = Image.open(image_path).convert("RGB")
31 inputs = processor(images=image, return_tensors="pt")
32
33 with torch.no_grad():
34 outputs = model(**inputs)
35 probs = torch.sigmoid(outputs.logits)[0]
36
37 results = {DISEASES[i]: float(probs[i])
38 for i in range(len(DISEASES)) if probs[i] > threshold}
39 return dict(sorted(results.items(), key=lambda x: x[1], reverse=True))
40
41# Example
42result = predict_chest_xray("chest_xray.jpg")
43print(result)