Upload folder using huggingface_hub
Browse files- README.md +97 -0
- albumentations_config_eval.json +1 -0
- config.json +19 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
- dpt
|
| 12 |
+
languages:
|
| 13 |
+
- python
|
| 14 |
+
---
|
| 15 |
+
# DPT Model Card
|
| 16 |
+
|
| 17 |
+
Table of Contents:
|
| 18 |
+
- [Load trained model](#load-trained-model)
|
| 19 |
+
- [Model init parameters](#model-init-parameters)
|
| 20 |
+
- [Model metrics](#model-metrics)
|
| 21 |
+
- [Dataset](#dataset)
|
| 22 |
+
|
| 23 |
+
## Load trained model
|
| 24 |
+
|
| 25 |
+
[](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/dpt_inference_pretrained.ipynb)
|
| 26 |
+
|
| 27 |
+
1. Install requirements.
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
pip install -U segmentation_models_pytorch albumentations
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
2. Run inference.
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import torch
|
| 37 |
+
import requests
|
| 38 |
+
import numpy as np
|
| 39 |
+
import albumentations as A
|
| 40 |
+
import segmentation_models_pytorch as smp
|
| 41 |
+
|
| 42 |
+
from PIL import Image
|
| 43 |
+
|
| 44 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 45 |
+
|
| 46 |
+
# Load pretrained model and preprocessing function
|
| 47 |
+
checkpoint = "smp-hub/smp-hub/dpt-large-ade20k""
|
| 48 |
+
model = smp.from_pretrained(checkpoint).eval().to(device)
|
| 49 |
+
preprocessing = A.Compose.from_pretrained(checkpoint)
|
| 50 |
+
|
| 51 |
+
# Load image
|
| 52 |
+
url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
|
| 53 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 54 |
+
|
| 55 |
+
# Preprocess image
|
| 56 |
+
np_image = np.array(image)
|
| 57 |
+
normalized_image = preprocessing(image=np_image)["image"]
|
| 58 |
+
input_tensor = torch.as_tensor(normalized_image)
|
| 59 |
+
input_tensor = input_tensor.permute(2, 0, 1).unsqueeze(0) # HWC -> BCHW
|
| 60 |
+
input_tensor = input_tensor.to(device)
|
| 61 |
+
|
| 62 |
+
# Perform inference
|
| 63 |
+
with torch.no_grad():
|
| 64 |
+
output_mask = model(input_tensor)
|
| 65 |
+
|
| 66 |
+
# Postprocess mask
|
| 67 |
+
mask = torch.nn.functional.interpolate(
|
| 68 |
+
output_mask, size=(image.height, image.width), mode="bilinear", align_corners=False
|
| 69 |
+
)
|
| 70 |
+
mask = mask.argmax(1).cpu().numpy() # argmax over predicted classes (channels dim)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
## Model init parameters
|
| 74 |
+
```python
|
| 75 |
+
model_init_params = {
|
| 76 |
+
"encoder_name": "tu-vit_large_patch16_384",
|
| 77 |
+
"encoder_depth": 4,
|
| 78 |
+
"encoder_weights": None,
|
| 79 |
+
"encoder_output_indices": None,
|
| 80 |
+
"decoder_intermediate_channels": (256, 512, 1024, 1024),
|
| 81 |
+
"decoder_fusion_channels": 256,
|
| 82 |
+
"dynamic_img_size": True,
|
| 83 |
+
"in_channels": 3,
|
| 84 |
+
"classes": 150,
|
| 85 |
+
"activation": None,
|
| 86 |
+
"aux_params": None
|
| 87 |
+
}
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Dataset
|
| 91 |
+
Dataset name: [ADE20K](https://ade20k.csail.mit.edu/)
|
| 92 |
+
|
| 93 |
+
## More Information
|
| 94 |
+
- Library: https://github.com/qubvel/segmentation_models.pytorch
|
| 95 |
+
- Docs: https://smp.readthedocs.io/en/latest/
|
| 96 |
+
|
| 97 |
+
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__": "LongestMaxSize", "p": 1.0, "max_size": 480, "max_size_hw": null, "interpolation": 2, "mask_interpolation": 0}, {"__class_fullname__": "Normalize", "p": 1.0, "mean": [0.5, 0.5, 0.5], "std": [0.5, 0.5, 0.5], "max_pixel_value": 255.0, "normalization": "standard"}, {"__class_fullname__": "PadIfNeeded", "p": 1.0, "min_height": null, "min_width": null, "pad_height_divisor": 32, "pad_width_divisor": 32, "position": "center", "border_mode": 0, "fill": 0.0, "fill_mask": 0.0}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}, "is_check_shapes": true}}
|
config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_model_class": "DPT",
|
| 3 |
+
"activation": null,
|
| 4 |
+
"aux_params": null,
|
| 5 |
+
"classes": 150,
|
| 6 |
+
"decoder_fusion_channels": 256,
|
| 7 |
+
"decoder_intermediate_channels": [
|
| 8 |
+
256,
|
| 9 |
+
512,
|
| 10 |
+
1024,
|
| 11 |
+
1024
|
| 12 |
+
],
|
| 13 |
+
"dynamic_img_size": true,
|
| 14 |
+
"encoder_depth": 4,
|
| 15 |
+
"encoder_name": "tu-vit_large_patch16_384",
|
| 16 |
+
"encoder_output_indices": null,
|
| 17 |
+
"encoder_weights": null,
|
| 18 |
+
"in_channels": 3
|
| 19 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b527beda408b0d4614f5fee260542e0ecc4db3cb33a0664891f5d5ffc51564a5
|
| 3 |
+
size 1377510920
|