图片哈希计算处理器
更新时间:2026-04-23
简介
图片哈希计算处理器
功能描述
- 支持五种哈希方法:
ahash、dhash、phash、whash、md5 - 输入类型可选:
image_url、image_base64、image_binary - 支持批量处理
算子参数
输入
| 输入 | 含义 |
|---|---|
| image | 包含输入图像的数组,支持URL/二进制格式 |
输出
| 输出 | 含义 |
|---|---|
| hash_hex | 图像的十六进制哈希值。对于 md5 方法,该值为 16 个字符(截取完整摘要的前 64 位) |
| hash_bin | 图像的二进制哈希值。对于 md5 方法,该值为 64 位 |
参数
| 参数 | 类型 | 含义 | 默认值 |
|---|---|---|---|
| image_src_type | str | 输入图片的来源类型可选值:["image_url", "image_base64", "image_binary"] | "image_url" |
| method | str | 哈希计算方法。md5 使用 hashlib.md5 计算,其它方法使用 imagededup 库。可选值:{"ahash", "dhash", "phash", "whash", "md5"} | "phash" |
| batch_size | int | 批处理大小,用于在吞吐量和内存消耗之间进行平衡 | 64 |
调用示例
Plain Text
1from __future__ import annotations
2
3import os
4import daft
5from daft import col
6
7from daft.aihc.common.udf import aihc_udf
8from daft.aihc.functions.image.image_hash import ImageHash
9
10if __name__ == "__main__":
11 if os.getenv("DAFT_RUNNER", "native") == "ray":
12 import ray
13 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
14 daft.set_runner_ray()
15 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
16
17 samples = {
18 "image": [
19 "file:///local/sample_1.jpg",
20 "file:///mnt/pfs/sample_2.jpg",
21 "file:///mnt/bos/sample_3.jpg",
22 ]
23 }
24
25 ds = daft.from_pydict(samples)
26 ds = ds.with_column(
27 "image_hash",
28 aihc_udf(
29 ImageHash,
30 construct_args={
31 "image_src_type": "image_url",
32 "method": "phash",
33 },
34 num_gpus=0,
35 batch_size=1,
36 concurrency=1,
37 )(col("image")),
38 )
39
40 ds.show()
评价此篇文章
