qubvel-hf HF Staff commited on
Commit
7314897
·
verified ·
1 Parent(s): c066d09

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +93 -0
  2. albumentations_config_eval.json +1 -0
  3. config.json +14 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: segmentation-models-pytorch
3
+ license: mit
4
+ pipeline_tag: image-segmentation
5
+ tags:
6
+ - model_hub_mixin
7
+ - pytorch_model_hub_mixin
8
+ - segmentation-models-pytorch
9
+ - semantic-segmentation
10
+ - pytorch
11
+ - upernet
12
+ languages:
13
+ - python
14
+ ---
15
+ # UPerNet Model Card
16
+
17
+ Table of Contents:
18
+ - [Load trained model](#load-trained-model)
19
+ - [Model init parameters](#model-init-parameters)
20
+ - [Dataset](#dataset)
21
+
22
+ ## Load trained model
23
+
24
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/upernet_inference_pretrained.ipynb)
25
+
26
+ 1. Install requirements.
27
+
28
+ ```bash
29
+ pip install -U segmentation_models_pytorch albumentations
30
+ ```
31
+
32
+ 2. Run inference.
33
+
34
+ ```python
35
+ import torch
36
+ import requests
37
+ import numpy as np
38
+ import albumentations as A
39
+ import segmentation_models_pytorch as smp
40
+
41
+ from PIL import Image
42
+
43
+ device = "cuda" if torch.cuda.is_available() else "cpu"
44
+
45
+ # Load pretrained model and preprocessing function
46
+ checkpoint = "smp-hub/upernet-swin-large"
47
+ model = smp.from_pretrained(checkpoint).eval().to(device)
48
+ preprocessing = A.Compose.from_pretrained(checkpoint)
49
+
50
+ # Load image
51
+ url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
52
+ image = Image.open(requests.get(url, stream=True).raw)
53
+
54
+ # Preprocess image
55
+ np_image = np.array(image)
56
+ normalized_image = preprocessing(image=np_image)["image"]
57
+ input_tensor = torch.as_tensor(normalized_image)
58
+ input_tensor = input_tensor.permute(2, 0, 1).unsqueeze(0) # HWC -> BCHW
59
+ input_tensor = input_tensor.to(device)
60
+
61
+ # Perform inference
62
+ with torch.no_grad():
63
+ output_mask = model(input_tensor)
64
+
65
+ # Postprocess mask
66
+ mask = mask.argmax(1).cpu().numpy() # argmax over predicted classes (channels dim)
67
+ ```
68
+
69
+ ## Model init parameters
70
+ ```python
71
+ model_init_params = {
72
+ "encoder_name": "tu-swin_large_patch4_window12_384",
73
+ "encoder_depth": 5,
74
+ "encoder_weights": None,
75
+ "decoder_channels": 512,
76
+ "decoder_use_norm": "batchnorm",
77
+ "in_channels": 3,
78
+ "classes": 150,
79
+ "activation": None,
80
+ "upsampling": 4,
81
+ "aux_params": None,
82
+ "img_size": 512
83
+ }
84
+ ```
85
+
86
+ ## Dataset
87
+ Dataset name: [ADE20K](https://ade20k.csail.mit.edu/)
88
+
89
+ ## More Information
90
+ - Library: https://github.com/qubvel/segmentation_models.pytorch
91
+ - Docs: https://smp.readthedocs.io/en/latest/
92
+
93
+ This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin)
albumentations_config_eval.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"__version__": "2.0.5", "transform": {"__class_fullname__": "Compose", "p": 1.0, "transforms": [{"__class_fullname__": "Resize", "p": 1.0, "height": 512, "width": 512, "interpolation": 1, "mask_interpolation": 0}, {"__class_fullname__": "Normalize", "p": 1.0, "mean": [123.675, 116.28, 103.53], "std": [58.395, 57.12, 57.375], "max_pixel_value": 1.0, "normalization": "standard"}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}, "is_check_shapes": true}}
config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_model_class": "UPerNet",
3
+ "activation": null,
4
+ "aux_params": null,
5
+ "classes": 150,
6
+ "decoder_channels": 512,
7
+ "decoder_use_norm": "batchnorm",
8
+ "encoder_depth": 5,
9
+ "encoder_name": "tu-swin_large_patch4_window12_384",
10
+ "encoder_weights": null,
11
+ "img_size": 512,
12
+ "in_channels": 3,
13
+ "upsampling": 4
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82d354d6d37e814fe58d07e6572aa67e72a78fe44332e489f805ae7131eda506
3
+ size 928714152