keras search engine
1.0.0
KERAS中實現的簡單文檔和圖像搜索引擎
goto keras_search_engine_web目錄並運行以下命令:
python flaskr.py現在將瀏覽器導航到http:// localhost:5000,您可以嘗試一下
在運行Web API服務器後,您可以通過調用以下Web API來索引新文檔:
http://localhost:5000/index_text例如,以下是curl命令調用Web API索引一些文檔:
curl -H ' Content-Type application/json ' -X POST -d ' {"doc":"Whether you think that you can, or that you can ' t, you are usually right. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " Try to learn something about everything and everything about something. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " You can avoid reality, but you cannot avoid the consequences of avoiding reality. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " A mathematician is a device for turning coffee into theorems. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " In theory, there is no difference between theory and practice. But in practice, there is. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " I find that the harder I work, the more luck I seem to have. " }' http://localhost:5000/index_text要使用Web API查詢,您可以調用以下Web API:
curl -H ' Content-Type application/json ' -X POST -d ' {"query":"mathematician and coffee", "limit": 3, "model": "glove"} ' http://localhost:5000/search_text在運行Web API服務器後,您可以通過郵政請求調用以下Web API來索引新圖像:
http://localhost:5000/index_image您可以通過調用以下Web API發布請求來查詢類似的圖像:
http://localhost:5000/search_image/10其中10是返回的圖像數量的限制
keras_search_engine_client中還有一個searchengineclient類,示例代碼看起來像:
from keras_search_engine_client . search_engine_client import SearchEngineClient
client = SearchEngineClient ()
# text indexing and search
doc_count = client . doc_count ()
if doc_count < 4 :
client . index_text ( 'Whether you think that you can, or that you can.' )
client . index_text ( 'Try to learn something about everything and everything about something.' )
client . index_text ( 'You can avoid reality, but you cannot avoid the consequences of avoiding reality.' )
client . index_text ( 'A mathematician is a device for turning coffee into theorems.' )
client . index_text ( 'In theory, there is no difference between theory and practice. But in practice, there is.' )
client . index_text ( 'I find that the harder I work, the more luck I seem to have.' )
client . search_text ( query = 'mathematician and coffee' , limit = 3 , model = 'glove' )
client . search_text ( query = 'mathematician and coffee' , limit = 3 , model = 'doc-encoder' )
# image indexing and search
client . index_image ( './images/Pokemon7.png' )
client . search_image ( './images/Pokemon1.jpg' , 6 )