Upload folder using huggingface_hub
Browse files- README.md +92 -0
- albumentations_config_eval.json +1 -0
- config.json +13 -0
- model.safetensors +3 -0
README.md
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
[](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-convnext-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-convnext_large",
|
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 |
+
}
|
83 |
+
```
|
84 |
+
|
85 |
+
## Dataset
|
86 |
+
Dataset name: [ADE20K](https://ade20k.csail.mit.edu/)
|
87 |
+
|
88 |
+
## More Information
|
89 |
+
- Library: https://github.com/qubvel/segmentation_models.pytorch
|
90 |
+
- Docs: https://smp.readthedocs.io/en/latest/
|
91 |
+
|
92 |
+
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,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-convnext_large",
|
10 |
+
"encoder_weights": null,
|
11 |
+
"in_channels": 3,
|
12 |
+
"upsampling": 4
|
13 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9df0e86c68743d3ce47e6963ea3fe950f1314a9f458eb320a549396e811899be
|
3 |
+
size 932842224
|