Dreamy0 commited on
Commit
020d89d
·
verified ·
1 Parent(s): fab22d0

Add fine-tuned MaskFormer model with CVAT compatibility

Browse files
Files changed (4) hide show
  1. README.md +55 -0
  2. config.json +91 -0
  3. model.safetensors +3 -0
  4. preprocessor_config.json +20 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - maskformer
5
+ - instance-segmentation
6
+ - image-segmentation
7
+ - abnormal-detection
8
+ datasets:
9
+ - custom
10
+ pipeline_tag: image-segmentation
11
+ ---
12
+
13
+ # MaskFormer for Normal/Abnormal Detection
14
+
15
+ This model is fine-tuned to detect and segment regions classified as either "Normal" or "Abnormal".
16
+
17
+ ## Model description
18
+
19
+ This is a MaskFormer model fine-tuned on a custom dataset with polygon annotations in COCO format. It has two classes:
20
+ - Normal (ID: 0)
21
+ - Abnormal (ID: 1)
22
+
23
+ ## Intended uses & limitations
24
+
25
+ This model is intended for instance segmentation tasks to identify normal and abnormal regions in images.
26
+
27
+ ### How to use in CVAT
28
+
29
+ 1. In CVAT, go to Models → Add Model
30
+ 2. Select Hugging Face as the source
31
+ 3. Enter the model path: "{your-username}/maskformer-abnormal-detection-v4"
32
+ 4. Configure the appropriate mapping for your labels (Normal and Abnormal)
33
+
34
+ ### Usage in Python
35
+
36
+ ```python
37
+ from transformers import MaskFormerForInstanceSegmentation, MaskFormerImageProcessor
38
+ import torch
39
+ from PIL import Image
40
+
41
+ # Load model and processor
42
+ model = MaskFormerForInstanceSegmentation.from_pretrained("{your-username}/maskformer-abnormal-detection-v4")
43
+ processor = MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-tiny-ade")
44
+
45
+ # Prepare image
46
+ image = Image.open("your_image.jpg")
47
+ inputs = processor(images=image, return_tensors="pt")
48
+
49
+ # Make prediction
50
+ with torch.no_grad():
51
+ outputs = model(**inputs)
52
+
53
+ # Process outputs for visualization
54
+ # (see example code in model repository)
55
+ ```
config.json ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./maskformer_finetuned",
3
+ "architectures": [
4
+ "MaskFormerForInstanceSegmentation"
5
+ ],
6
+ "backbone": null,
7
+ "backbone_config": {
8
+ "depths": [
9
+ 2,
10
+ 2,
11
+ 6,
12
+ 2
13
+ ],
14
+ "drop_path_rate": 0.3,
15
+ "embed_dim": 96,
16
+ "encoder_stride": 32,
17
+ "hidden_size": 768,
18
+ "image_size": 224,
19
+ "in_channels": 3,
20
+ "model_type": "maskformer-swin",
21
+ "num_heads": [
22
+ 3,
23
+ 6,
24
+ 12,
25
+ 24
26
+ ],
27
+ "out_features": [
28
+ "stage1",
29
+ "stage2",
30
+ "stage3",
31
+ "stage4"
32
+ ],
33
+ "out_indices": [
34
+ 1,
35
+ 2,
36
+ 3,
37
+ 4
38
+ ],
39
+ "path_norm": true,
40
+ "pretrain_img_size": 224,
41
+ "window_size": 7
42
+ },
43
+ "backbone_kwargs": null,
44
+ "ce_weight": 1.0,
45
+ "cross_entropy_weight": 1.0,
46
+ "decoder_config": {
47
+ "max_position_embeddings": 1024,
48
+ "model_type": "detr",
49
+ "scale_embedding": false
50
+ },
51
+ "dice_weight": 1.0,
52
+ "fpn_feature_size": 256,
53
+ "init_std": 0.02,
54
+ "init_xavier_std": 1.0,
55
+ "mask_feature_size": 256,
56
+ "mask_weight": 20.0,
57
+ "model_type": "maskformer",
58
+ "no_object_weight": 0.1,
59
+ "num_attention_heads": 8,
60
+ "num_hidden_layers": 6,
61
+ "num_queries": 100,
62
+ "output_auxiliary_logits": null,
63
+ "torch_dtype": "float32",
64
+ "transformers_version": "4.38.2",
65
+ "use_auxiliary_loss": false,
66
+ "use_pretrained_backbone": false,
67
+ "use_timm_backbone": false,
68
+ "pipeline_tag": "image-segmentation",
69
+ "id2label": {
70
+ "0": "Normal",
71
+ "1": "Abnormal"
72
+ },
73
+ "label2id": {
74
+ "Normal": 0,
75
+ "Abnormal": 1
76
+ },
77
+ "num_labels": 2,
78
+ "task_specific_params": {
79
+ "image-segmentation": {
80
+ "num_labels": 2,
81
+ "id2label": {
82
+ "0": "Normal",
83
+ "1": "Abnormal"
84
+ },
85
+ "label2id": {
86
+ "Normal": 0,
87
+ "Abnormal": 1
88
+ }
89
+ }
90
+ }
91
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d23f9a5a47177b2451f74996de9fde955600ef82e2f4cfec7204f9512d5c789c
3
+ size 167175760
preprocessor_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_resize": true,
4
+ "feature_extractor_type": "MaskFormerFeatureExtractor",
5
+ "image_mean": [
6
+ 0.485,
7
+ 0.456,
8
+ 0.406
9
+ ],
10
+ "image_std": [
11
+ 0.229,
12
+ 0.224,
13
+ 0.225
14
+ ],
15
+ "reduce_labels": false,
16
+ "size": {
17
+ "height": 512,
18
+ "width": 512
19
+ }
20
+ }