lxyuan commited on
Commit
3a89034
1 Parent(s): 7d16295

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -7
README.md CHANGED
@@ -22,6 +22,7 @@ model-index:
22
  - name: Accuracy
23
  type: accuracy
24
  value: 0.9742489270386266
 
25
  ---
26
 
27
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
@@ -34,20 +35,26 @@ It achieves the following results on the evaluation set:
34
  - Loss: 0.0868
35
  - Accuracy: 0.9742
36
 
37
- ## Model description
38
 
39
- More information needed
 
40
 
41
- ## Intended uses & limitations
42
 
43
- More information needed
 
44
 
45
- ## Training and evaluation data
 
 
46
 
47
- More information needed
48
 
49
  ## Training procedure
50
 
 
 
51
  ### Training hyperparameters
52
 
53
  The following hyperparameters were used during training:
@@ -62,6 +69,44 @@ The following hyperparameters were used during training:
62
  - lr_scheduler_warmup_ratio: 0.1
63
  - num_epochs: 15
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  ### Training results
66
 
67
  | Training Loss | Epoch | Step | Validation Loss | Accuracy |
@@ -86,4 +131,4 @@ The following hyperparameters were used during training:
86
  - Transformers 4.30.2
87
  - Pytorch 1.9.0+cu102
88
  - Datasets 2.12.0
89
- - Tokenizers 0.13.3
 
22
  - name: Accuracy
23
  type: accuracy
24
  value: 0.9742489270386266
25
+ pipeline_tag: image-classification
26
  ---
27
 
28
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
 
35
  - Loss: 0.0868
36
  - Accuracy: 0.9742
37
 
38
+ ## Inference example
39
 
40
+ ```python
41
+ from transformers import pipeline
42
 
43
+ classifier = pipeline(model="lxyuan/vit-xray-pneumonia-classification")
44
 
45
+ # image taken from https://www.news-medical.net/health/What-is-Viral-Pneumonia.aspx
46
+ classifier("https://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20200618040600/ri/650/picture/2020/6/shutterstock_786937069.jpg")
47
 
48
+ >>>
49
+ [{'score': 0.990334689617157, 'label': 'PNEUMONIA'},
50
+ {'score': 0.009665317833423615, 'label': 'NORMAL'}]
51
 
52
+ ```
53
 
54
  ## Training procedure
55
 
56
+ Notebook link: [here](https://github.com/LxYuan0420/nlp/blob/main/notebooks/ViT-xray-classification.ipynb)
57
+
58
  ### Training hyperparameters
59
 
60
  The following hyperparameters were used during training:
 
69
  - lr_scheduler_warmup_ratio: 0.1
70
  - num_epochs: 15
71
 
72
+ ```python
73
+ from transformers import EarlyStoppingCallback
74
+
75
+ training_args = TrainingArguments(
76
+ output_dir="vit-xray-pneumonia-classification",
77
+ remove_unused_columns=False,
78
+ evaluation_strategy="epoch",
79
+ save_strategy="epoch",
80
+ logging_strategy="epoch",
81
+ learning_rate=5e-5,
82
+ per_device_train_batch_size=16,
83
+ gradient_accumulation_steps=4,
84
+ per_device_eval_batch_size=16,
85
+ num_train_epochs=15,
86
+ save_total_limit=2,
87
+ warmup_ratio=0.1,
88
+ load_best_model_at_end=True,
89
+ metric_for_best_model="eval_loss",
90
+ greater_is_better=False,
91
+ fp16=True,
92
+ push_to_hub=True,
93
+ report_to="tensorboard"
94
+ )
95
+
96
+ early_stopping = EarlyStoppingCallback(early_stopping_patience=3)
97
+
98
+ trainer = Trainer(
99
+ model=model,
100
+ args=training_args,
101
+ data_collator=data_collator,
102
+ train_dataset=train_ds,
103
+ eval_dataset=val_ds,
104
+ tokenizer=processor,
105
+ compute_metrics=compute_metrics,
106
+ callbacks=[early_stopping],
107
+ )
108
+ ```
109
+
110
  ### Training results
111
 
112
  | Training Loss | Epoch | Step | Validation Loss | Accuracy |
 
131
  - Transformers 4.30.2
132
  - Pytorch 1.9.0+cu102
133
  - Datasets 2.12.0
134
+ - Tokenizers 0.13.3