yanmuyuan commited on
Commit ·
f0e3abd
1
Parent(s): be62613
new
Browse files- .idea/.gitignore +8 -0
- config.json +114 -0
- handler.py +56 -0
- model.safetensors +3 -0
- preprocessor_config.json +42 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 默认忽略的文件
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# 基于编辑器的 HTTP 客户端请求
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
config.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_projection": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"ZoeDepthForDepthEstimation"
|
| 5 |
+
],
|
| 6 |
+
"attractor_alpha": 1000,
|
| 7 |
+
"attractor_gamma": 2,
|
| 8 |
+
"attractor_kind": "mean",
|
| 9 |
+
"backbone": null,
|
| 10 |
+
"backbone_config": {
|
| 11 |
+
"hidden_size": 1024,
|
| 12 |
+
"image_size": 384,
|
| 13 |
+
"intermediate_size": 4096,
|
| 14 |
+
"model_type": "beit",
|
| 15 |
+
"num_attention_heads": 16,
|
| 16 |
+
"num_hidden_layers": 24,
|
| 17 |
+
"out_features": [
|
| 18 |
+
"stage6",
|
| 19 |
+
"stage12",
|
| 20 |
+
"stage18",
|
| 21 |
+
"stage24"
|
| 22 |
+
],
|
| 23 |
+
"out_indices": [
|
| 24 |
+
6,
|
| 25 |
+
12,
|
| 26 |
+
18,
|
| 27 |
+
24
|
| 28 |
+
],
|
| 29 |
+
"reshape_hidden_states": false,
|
| 30 |
+
"stage_names": [
|
| 31 |
+
"stem",
|
| 32 |
+
"stage1",
|
| 33 |
+
"stage2",
|
| 34 |
+
"stage3",
|
| 35 |
+
"stage4",
|
| 36 |
+
"stage5",
|
| 37 |
+
"stage6",
|
| 38 |
+
"stage7",
|
| 39 |
+
"stage8",
|
| 40 |
+
"stage9",
|
| 41 |
+
"stage10",
|
| 42 |
+
"stage11",
|
| 43 |
+
"stage12",
|
| 44 |
+
"stage13",
|
| 45 |
+
"stage14",
|
| 46 |
+
"stage15",
|
| 47 |
+
"stage16",
|
| 48 |
+
"stage17",
|
| 49 |
+
"stage18",
|
| 50 |
+
"stage19",
|
| 51 |
+
"stage20",
|
| 52 |
+
"stage21",
|
| 53 |
+
"stage22",
|
| 54 |
+
"stage23",
|
| 55 |
+
"stage24"
|
| 56 |
+
],
|
| 57 |
+
"use_relative_position_bias": true
|
| 58 |
+
},
|
| 59 |
+
"backbone_hidden_size": 1024,
|
| 60 |
+
"batch_norm_eps": 1e-05,
|
| 61 |
+
"bin_centers_type": "softplus",
|
| 62 |
+
"bin_configurations": [
|
| 63 |
+
{
|
| 64 |
+
"max_depth": 10.0,
|
| 65 |
+
"min_depth": 0.001,
|
| 66 |
+
"n_bins": 64,
|
| 67 |
+
"name": "nyu"
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"max_depth": 80.0,
|
| 71 |
+
"min_depth": 0.001,
|
| 72 |
+
"n_bins": 64,
|
| 73 |
+
"name": "kitti"
|
| 74 |
+
}
|
| 75 |
+
],
|
| 76 |
+
"bin_embedding_dim": 128,
|
| 77 |
+
"bottleneck_features": 256,
|
| 78 |
+
"fusion_hidden_size": 256,
|
| 79 |
+
"head_in_index": -1,
|
| 80 |
+
"hidden_act": "gelu",
|
| 81 |
+
"initializer_range": 0.02,
|
| 82 |
+
"max_temp": 50.0,
|
| 83 |
+
"min_temp": 0.0212,
|
| 84 |
+
"model_type": "zoedepth",
|
| 85 |
+
"neck_hidden_sizes": [
|
| 86 |
+
256,
|
| 87 |
+
512,
|
| 88 |
+
1024,
|
| 89 |
+
1024
|
| 90 |
+
],
|
| 91 |
+
"num_attractors": [
|
| 92 |
+
16,
|
| 93 |
+
8,
|
| 94 |
+
4,
|
| 95 |
+
1
|
| 96 |
+
],
|
| 97 |
+
"num_patch_transformer_layers": 4,
|
| 98 |
+
"num_relative_features": 32,
|
| 99 |
+
"patch_transformer_hidden_size": 128,
|
| 100 |
+
"patch_transformer_intermediate_size": 1024,
|
| 101 |
+
"patch_transformer_num_attention_heads": 4,
|
| 102 |
+
"readout_type": "project",
|
| 103 |
+
"reassemble_factors": [
|
| 104 |
+
4,
|
| 105 |
+
2,
|
| 106 |
+
1,
|
| 107 |
+
0.5
|
| 108 |
+
],
|
| 109 |
+
"torch_dtype": "float32",
|
| 110 |
+
"transformers_version": "4.42.0.dev0",
|
| 111 |
+
"use_batch_norm_in_fusion_residual": false,
|
| 112 |
+
"use_bias_in_fusion_residual": null,
|
| 113 |
+
"use_pretrained_backbone": false
|
| 114 |
+
}
|
handler.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
import io
|
| 3 |
+
import json
|
| 4 |
+
from typing import Dict, Any
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
class EndpointHandler:
|
| 9 |
+
"""
|
| 10 |
+
Custom handler for the ZoeDepth model, fully compliant with the latest
|
| 11 |
+
Hugging Face Inference Endpoints documentation.
|
| 12 |
+
The final result is serialized into a single JSON string.
|
| 13 |
+
"""
|
| 14 |
+
def __init__(self, path=""):
|
| 15 |
+
# Initialize the pipeline for depth-estimation
|
| 16 |
+
self.pipe = pipeline(task="depth-estimation", model=path)
|
| 17 |
+
print("Depth estimation pipeline initialized successfully.")
|
| 18 |
+
|
| 19 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
| 20 |
+
"""
|
| 21 |
+
This method is called for every API request.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
data (Dict): The input data dictionary. Expects "inputs" key with image bytes.
|
| 25 |
+
|
| 26 |
+
Returns:
|
| 27 |
+
Dict[str, str]: A dictionary with a single key "generated_text",
|
| 28 |
+
containing a JSON string of the results.
|
| 29 |
+
"""
|
| 30 |
+
# Get image bytes from the request
|
| 31 |
+
inputs = data.pop("inputs", data)
|
| 32 |
+
image = Image.open(io.BytesIO(inputs))
|
| 33 |
+
|
| 34 |
+
# Pass the image to the pipeline
|
| 35 |
+
prediction = self.pipe(image)
|
| 36 |
+
|
| 37 |
+
# Extract raw depth data and visual map
|
| 38 |
+
raw_depth_tensor = prediction["predicted_depth"]
|
| 39 |
+
raw_depth_data = raw_depth_tensor.cpu().tolist()
|
| 40 |
+
|
| 41 |
+
visual_map_image = prediction["depth"]
|
| 42 |
+
buffered = io.BytesIO()
|
| 43 |
+
visual_map_image.save(buffered, format="PNG")
|
| 44 |
+
visual_map_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 45 |
+
|
| 46 |
+
# Create a dictionary to hold all results
|
| 47 |
+
results = {
|
| 48 |
+
"raw_depth_data": raw_depth_data,
|
| 49 |
+
"visual_depth_map": f"data:image/png;base64,{visual_map_base64}"
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# Serialize the entire results dictionary into a JSON string
|
| 53 |
+
json_output_string = json.dumps(results)
|
| 54 |
+
|
| 55 |
+
# Return the final dictionary in the required format
|
| 56 |
+
return {"generated_text": json_output_string}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c5494fa0938f18d71e215e245472470c3aefebd7b434abd89750e5ae4008e2dc
|
| 3 |
+
size 1380374404
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_valid_processor_keys": [
|
| 3 |
+
"images",
|
| 4 |
+
"do_resize",
|
| 5 |
+
"size",
|
| 6 |
+
"keep_aspect_ratio",
|
| 7 |
+
"ensure_multiple_of",
|
| 8 |
+
"resample",
|
| 9 |
+
"do_rescale",
|
| 10 |
+
"rescale_factor",
|
| 11 |
+
"do_normalize",
|
| 12 |
+
"image_mean",
|
| 13 |
+
"image_std",
|
| 14 |
+
"do_pad",
|
| 15 |
+
"return_tensors",
|
| 16 |
+
"data_format",
|
| 17 |
+
"input_data_format"
|
| 18 |
+
],
|
| 19 |
+
"do_normalize": true,
|
| 20 |
+
"do_pad": true,
|
| 21 |
+
"do_rescale": true,
|
| 22 |
+
"do_resize": true,
|
| 23 |
+
"ensure_multiple_of": 32,
|
| 24 |
+
"image_mean": [
|
| 25 |
+
0.5,
|
| 26 |
+
0.5,
|
| 27 |
+
0.5
|
| 28 |
+
],
|
| 29 |
+
"image_processor_type": "ZoeDepthImageProcessor",
|
| 30 |
+
"image_std": [
|
| 31 |
+
0.5,
|
| 32 |
+
0.5,
|
| 33 |
+
0.5
|
| 34 |
+
],
|
| 35 |
+
"keep_aspect_ratio": true,
|
| 36 |
+
"resample": 2,
|
| 37 |
+
"rescale_factor": 0.00392156862745098,
|
| 38 |
+
"size": {
|
| 39 |
+
"height": 384,
|
| 40 |
+
"width": 512
|
| 41 |
+
}
|
| 42 |
+
}
|