直接用 SQL 就可以调用 Yolov5 模型,做图像检测。
下面是用 sql 查询得到结果,用 python 把检测结果图层叠加上去的代码片段:
from rikai.viz import Text
from rikai.types.vision import Image
from functools import reduce
df = spark.sql(f"""
select * from (
select explode(ML_PREDICT(yolov5m, image)) as pred
from (
select to_image('{uri}') as image
)
)
where pred.label = 'person' -- truck/car/person
""")
preds = [row.pred for row in df.collect()]
def add_layer(image, pred):
return image | pred.box | Text(pred.label, (pred.box.xmin, pred.box.ymin - 10))
reduce(lambda a,b: add_layer(a, b), [image] + preds)
对 Rikai 感兴趣的小伙伴可以观看完整视频《 Rikai: 视频内容理解引擎》
帮忙在 Hacknews Upvote: https://news.ycombinator.com/item?id=30019507