From 8b9c8f5cb866734080d2be8fe13171b55ddb327c Mon Sep 17 00:00:00 2001 From: ChengZi Date: Fri, 3 Feb 2023 11:01:48 +0800 Subject: [PATCH] update readme with dc2 --- README.md | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d05c6f6..9d626f6 100644 --- a/README.md +++ b/README.md @@ -18,41 +18,57 @@ This operator select input list by simply aggregating, sorting and then filterin For two input lists: video urls and scores, aggregate url by reduce_function, then sort aggregated scores, then select top k results. ```python -import towhee +from towhee.dc2 import pipe, ops, DataCollection -towhee.dc['video_urls', 'scores']([[['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1]]])\ -.video_copy_detection.select_video[('video_urls','scores'), 'res'](top_k=2, reduce_function='mean', reverse=True)\ -.show() +p = ( + pipe.input('video_urls', 'scores') \ + .map(('video_urls', 'scores'), 'res', ops.video_copy_detection.select_video(top_k=2, reduce_function='mean', reverse=True)) \ + .output('video_urls', 'scores', 'res') +) + +DataCollection(p(['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1])).show() ``` ![](mean.png) ```python -import towhee +from towhee.dc2 import pipe, ops, DataCollection + +p = ( + pipe.input('video_urls', 'scores') \ + .map(('video_urls', 'scores'), 'res', ops.video_copy_detection.select_video(top_k=2, reduce_function='sum', reverse=True)) \ + .output('video_urls', 'scores', 'res') +) -towhee.dc['video_urls', 'scores']([[['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1]]])\ -.video_copy_detection.select_video[('video_urls','scores'), 'res'](top_k=2, reduce_function='sum', reverse=True)\ -.show() +DataCollection(p(['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1])).show() ``` ![](mean.png) ```python -import towhee +from towhee.dc2 import pipe, ops, DataCollection -towhee.dc['video_urls', 'scores']([[['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1]]])\ -.video_copy_detection.select_video[('video_urls','scores'), 'res'](top_k=2, reduce_function='max', reverse=True)\ -.show() +p = ( + pipe.input('video_urls', 'scores') \ + .map(('video_urls', 'scores'), 'res', ops.video_copy_detection.select_video(top_k=2, reduce_function='max', reverse=True)) \ + .output('video_urls', 'scores', 'res') +) + +DataCollection(p(['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1])).show() ``` ![](max.png) ```python -import towhee +from towhee.dc2 import pipe, ops, DataCollection + +p = ( + pipe.input('video_urls', 'scores') \ + .map(('video_urls', 'scores'), 'res', ops.video_copy_detection.select_video(top_k=2, reduce_function='min', reverse=True)) \ + .output('video_urls', 'scores', 'res') +) -towhee.dc['video_urls', 'scores']([[['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1]]])\ -.video_copy_detection.select_video[('video_urls','scores'), 'res'](top_k=2, reduce_function='min', reverse=True)\ -.show() +DataCollection(p(['a', 'a', 'c', 'a', 'b', 'b', 'c', 'c'], [2, 8, 9.3, 5, 2, 1, 0, -1])).show() ``` ![](min.png)