神經搜尋黑客馬拉松第二名?
我們目睹了各種視頻共享網站中視頻數據的爆炸式增長,互聯網上有數十億個視頻,從大規模視頻數據庫中執行近重複視頻檢索(NDVR)成為一個重大挑戰。 NDVR旨在從海量視頻資料庫中檢索近似重複的視頻,其中近似重複的視頻被定義為視覺上接近原始視頻的視頻。
用戶有強烈的動機去複製熱門短片並上傳增強版本來獲得關注。隨著短影片的成長,偵測近似重複短影片出現了新的困難和挑戰。
在這裡,我們使用 Jina 建立了一個神經搜尋解決方案來解決 NDVR 的挑戰。
目錄
硬陽性候選影片範例。上排:側紋、濾色、水洗。中檔:橫屏改為垂直屏,黑邊較大。底行:旋轉
硬負面影片的範例。所有候選者在視覺上都與查詢相似,但不接近重複。
選擇候選影片有以下三種策略:
由於時間和資源的限制,我們決定採用轉換檢索策略。在實際應用程式中,用戶會複製熱門影片以獲取個人激勵措施。用戶通常會選擇稍微修改複製的影片以繞過偵測。這些修改包括影片裁切、邊框插入等。
為了模仿這種使用者行為,我們定義了一種時間變換,即視訊加速,和三種空間變換,即視訊裁剪、黑色邊框插入和視訊旋轉。
不幸的是,所研究的 NDVR 資料集要么分辨率低,要么巨大,要么特定領域,要么不公開(我們個人也很少聯繫過)。因此,我們決定建立小型自訂資料集進行實驗。
pip install --upgrade -r requirements.txt
bash ./get_data.sh
python app.py -t index
Flow索引定義如下:
!Flow
with :
logserver : false
pods :
chunk_seg :
uses : craft/craft.yml
parallel : $PARALLEL
read_only : true
timeout_ready : 600000
tf_encode :
uses : encode/encode.yml
needs : chunk_seg
parallel : $PARALLEL
read_only : true
timeout_ready : 600000
chunk_idx :
uses : index/chunk.yml
shards : $SHARDS
separated_workspace : true
doc_idx :
uses : index/doc.yml
needs : gateway
join_all :
uses : _merge
needs : [doc_idx, chunk_idx]
read_only : true
這分為以下步驟:
這裡我們使用 YAML 檔案來定義 Flow 並用它來索引資料。 index
函數採用input_fn
參數,該參數採用 Iterator 來傳遞檔案路徑,該檔案路徑將進一步包裝在IndexRequest
中並傳送至 Flow。
DATA_BLOB = "./index-videos/*.mp4"
if task == "index" :
f = Flow (). load_config ( "flow-index.yml" )
with f :
f . index ( input_fn = input_index_data ( DATA_BLOB , size = num_docs ), batch_size = 2 )
def input_index_data ( patterns , size ):
def iter_file_exts ( ps ):
return it . chain . from_iterable ( glob . iglob ( p , recursive = True ) for p in ps )
d = 0
if isinstance ( patterns , str ):
patterns = [ patterns ]
for g in iter_file_exts ( patterns ):
yield g . encode ()
d += 1
if size is not None and d > size :
break
python app.py -t query
然後,您可以使用自訂端點http://localhost:45678/api/search
開啟 Jinabox
查詢流程定義如下:
!Flow
with :
logserver : true
read_only : true # better add this in the query time
pods :
chunk_seg :
uses : craft/index-craft.yml
parallel : $PARALLEL
tf_encode :
uses : encode/encode.yml
parallel : $PARALLEL
chunk_idx :
uses : index/chunk.yml
shards : $SHARDS
separated_workspace : true
polling : all
uses_reducing : _merge_all
timeout_ready : 100000 # larger timeout as in query time will read all the data
ranker :
uses : BiMatchRanker
doc_idx :
uses : index/doc.yml
查詢流程分為以下步驟: