itsomk commited on
Commit
266e106
·
0 Parent(s):

Initial commit of vit-xray-v1

Browse files
Files changed (7) hide show
  1. .gitattributes +3 -0
  2. LICENSE +21 -0
  3. README.md +23 -0
  4. config.json +36 -0
  5. model.safetensors +3 -0
  6. preprocessor_config.json +22 -0
  7. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
2
+ *.pt filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OM KUMAR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ViT X-ray Multi-label (vit-xray-v1)
2
+
3
+ **Author:** OM KUMAR (Hugging Face: @itsomk)
4
+ **Model type:** Vision Transformer (google/vit-base-patch16-224-in21k fine-tuned)
5
+ **Task:** Multi-label chest X-ray classification (Nodule, Infiltration, Effusion, Atelectasis)
6
+ **License:** MIT
7
+
8
+ ## Quick usage
9
+ ```python
10
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
11
+ import torch
12
+ from PIL import Image
13
+
14
+ MODEL = "itsomk/vit-xray-v1"
15
+ processor = AutoImageProcessor.from_pretrained(MODEL)
16
+ model = AutoModelForImageClassification.from_pretrained(MODEL)
17
+ img = Image.open("path/to/xray.jpg").convert("RGB")
18
+ inputs = processor(images=img, return_tensors="pt")
19
+ with torch.no_grad():
20
+ logits = model(**inputs).logits
21
+ probs = torch.sigmoid(logits).squeeze().tolist()
22
+ labels = [model.config.id2label[str(i)] for i in range(len(probs))]
23
+ print(list(zip(labels, probs)))
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch16-224-in21k",
3
+ "architectures": [
4
+ "ViTForImageClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.0,
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "Nodule",
13
+ "1": "Infiltration",
14
+ "2": "Effusion",
15
+ "3": "Atelectasis"
16
+ },
17
+ "image_size": 224,
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 3072,
20
+ "label2id": {
21
+ "Atelectasis": 3,
22
+ "Effusion": 2,
23
+ "Infiltration": 1,
24
+ "Nodule": 0
25
+ },
26
+ "layer_norm_eps": 1e-12,
27
+ "model_type": "vit",
28
+ "num_attention_heads": 12,
29
+ "num_channels": 3,
30
+ "num_hidden_layers": 12,
31
+ "patch_size": 16,
32
+ "problem_type": "multi_label_classification",
33
+ "qkv_bias": true,
34
+ "torch_dtype": "float32",
35
+ "transformers_version": "4.38.2"
36
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d91dbfa7fb4fe32a15e1059200db5f415852f1f4cf440d2a061028803375f74
3
+ size 343230128
preprocessor_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_rescale": true,
4
+ "do_resize": true,
5
+ "image_mean": [
6
+ 0.5,
7
+ 0.5,
8
+ 0.5
9
+ ],
10
+ "image_processor_type": "ViTImageProcessor",
11
+ "image_std": [
12
+ 0.5,
13
+ 0.5,
14
+ 0.5
15
+ ],
16
+ "resample": 2,
17
+ "rescale_factor": 0.00392156862745098,
18
+ "size": {
19
+ "height": 224,
20
+ "width": 224
21
+ }
22
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers>=4.38.2
2
+ torch
3
+ Pillow
4
+ safetensors