End of training
Browse files- README.md +65 -0
- config.json +13 -0
- configuration_alexnet.py +14 -0
- modeling_alexnet.py +47 -0
- pytorch_model.bin +3 -0
- training_args.bin +3 -0
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- generated_from_trainer
|
4 |
+
metrics:
|
5 |
+
- accuracy
|
6 |
+
model-index:
|
7 |
+
- name: alexnet-pneumonia
|
8 |
+
results: []
|
9 |
+
---
|
10 |
+
|
11 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
12 |
+
should probably proofread and complete it, then remove this comment. -->
|
13 |
+
|
14 |
+
# alexnet-pneumonia
|
15 |
+
|
16 |
+
This model is a fine-tuned version of [](https://huggingface.co/) on an unknown dataset.
|
17 |
+
It achieves the following results on the evaluation set:
|
18 |
+
- Loss: 0.1142
|
19 |
+
- Accuracy: 0.9541
|
20 |
+
|
21 |
+
## Model description
|
22 |
+
|
23 |
+
More information needed
|
24 |
+
|
25 |
+
## Intended uses & limitations
|
26 |
+
|
27 |
+
More information needed
|
28 |
+
|
29 |
+
## Training and evaluation data
|
30 |
+
|
31 |
+
More information needed
|
32 |
+
|
33 |
+
## Training procedure
|
34 |
+
|
35 |
+
### Training hyperparameters
|
36 |
+
|
37 |
+
The following hyperparameters were used during training:
|
38 |
+
- learning_rate: 5e-05
|
39 |
+
- train_batch_size: 16
|
40 |
+
- eval_batch_size: 50
|
41 |
+
- seed: 42
|
42 |
+
- gradient_accumulation_steps: 4
|
43 |
+
- total_train_batch_size: 64
|
44 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
45 |
+
- lr_scheduler_type: linear
|
46 |
+
- lr_scheduler_warmup_ratio: 0.1
|
47 |
+
- num_epochs: 5
|
48 |
+
|
49 |
+
### Training results
|
50 |
+
|
51 |
+
| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|
52 |
+
|:-------------:|:-----:|:----:|:---------------:|:--------:|
|
53 |
+
| 0.3989 | 0.99 | 52 | 0.3528 | 0.8484 |
|
54 |
+
| 0.22 | 2.0 | 105 | 0.1949 | 0.9296 |
|
55 |
+
| 0.1723 | 2.99 | 157 | 0.2775 | 0.8962 |
|
56 |
+
| 0.1758 | 4.0 | 210 | 0.1318 | 0.9475 |
|
57 |
+
| 0.1117 | 4.95 | 260 | 0.1192 | 0.9558 |
|
58 |
+
|
59 |
+
|
60 |
+
### Framework versions
|
61 |
+
|
62 |
+
- Transformers 4.33.2
|
63 |
+
- Pytorch 2.0.1+cu117
|
64 |
+
- Datasets 2.14.4
|
65 |
+
- Tokenizers 0.13.3
|
config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"AlexNetPneumoniaClassification"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "configuration_alexnet.AlexNetConfig",
|
7 |
+
"AutoModelForImageClassification": "modeling_alexnet.AlexNetPneumoniaClassification"
|
8 |
+
},
|
9 |
+
"input_channels": 3,
|
10 |
+
"model_type": "alexnet",
|
11 |
+
"torch_dtype": "float32",
|
12 |
+
"transformers_version": "4.33.2"
|
13 |
+
}
|
configuration_alexnet.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# create pretrainconfig
|
2 |
+
from transformers import PretrainedConfig
|
3 |
+
|
4 |
+
class AlexNetConfig(PretrainedConfig):
|
5 |
+
model_type = "alexnet"
|
6 |
+
def __init__(self, id2label=None, label2id=None, labels=[], **kwargs):
|
7 |
+
self.input_channels = 3
|
8 |
+
self.output_hidden_states = True
|
9 |
+
self.return_dict = True
|
10 |
+
self.id2label=id2label
|
11 |
+
self.label2id=label2id
|
12 |
+
self.num_labels = len(labels)
|
13 |
+
self.model_type = "alexnet"
|
14 |
+
super().__init__(**kwargs)
|
modeling_alexnet.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch.nn as nn
|
2 |
+
import torch
|
3 |
+
from transformers.modeling_outputs import SequenceClassifierOutput
|
4 |
+
from transformers.modeling_utils import PreTrainedModel
|
5 |
+
from alexnet_model.configuration_alexnet import AlexNetConfig
|
6 |
+
|
7 |
+
class AlexNetPneumoniaClassification(PreTrainedModel):
|
8 |
+
config_class = AlexNetConfig
|
9 |
+
|
10 |
+
def __init__(self, config):
|
11 |
+
super(AlexNetPneumoniaClassification, self).__init__(config)
|
12 |
+
self.num_labels = config.num_labels
|
13 |
+
self.conv1 = nn.Conv2d(3, 96, kernel_size=11, stride=4, padding=0)
|
14 |
+
self.conv2 = nn.Conv2d(96, 256, kernel_size=5, stride=1,padding=2)
|
15 |
+
self.conv3 = nn.Conv2d(256, 384, kernel_size=3, stride=1, padding=1)
|
16 |
+
self.conv4 = nn.Conv2d(384, 384, kernel_size=3, stride=1, padding=1)
|
17 |
+
self.conv5 = nn.Conv2d(384, 256, kernel_size=3, stride=1, padding=1)
|
18 |
+
self.fc1 = nn.Linear(256*6*6, 4096)
|
19 |
+
self.fc2 = nn.Linear(4096, 4096)
|
20 |
+
self.fc3 = nn.Linear(4096, config.num_labels)
|
21 |
+
|
22 |
+
def forward(self, pixel_values, labels=None):
|
23 |
+
x = torch.relu(self.conv1(pixel_values))
|
24 |
+
x = torch.max_pool2d(x, kernel_size=3, stride=2, padding=0)
|
25 |
+
x = torch.relu(self.conv2(x))
|
26 |
+
x = torch.max_pool2d(x, kernel_size=3, stride=2, padding=0)
|
27 |
+
x = torch.relu(self.conv3(x))
|
28 |
+
x = torch.relu(self.conv4(x))
|
29 |
+
x = torch.relu(self.conv5(x))
|
30 |
+
x = torch.max_pool2d(x, kernel_size=3, stride=2, padding=0)
|
31 |
+
x = x.view(-1, 256*6*6)
|
32 |
+
x = torch.relu(self.fc1(x))
|
33 |
+
x = torch.relu(self.fc2(x))
|
34 |
+
logits = self.fc3(x)
|
35 |
+
|
36 |
+
loss = None
|
37 |
+
if labels is not None:
|
38 |
+
loss_fct = nn.CrossEntropyLoss()
|
39 |
+
loss = loss_fct(logits.view(-1, self.num_labels), labels)
|
40 |
+
return SequenceClassifierOutput(
|
41 |
+
loss=loss,
|
42 |
+
logits=logits,
|
43 |
+
)
|
44 |
+
|
45 |
+
return SequenceClassifierOutput(
|
46 |
+
logits=torch.softmax(logits, dim=1),
|
47 |
+
)
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:080a47fa65872669b93dea27128d61e5bad4ba19df81a6e38ac2f643e55a0de6
|
3 |
+
size 233163169
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4c5faf82b2dc0e79d48d4a7477bca55fd4c964b6d7d10465f256be6f6dacb523
|
3 |
+
size 4027
|