Um simples documento e mecanismo de pesquisa de imagem implementado em Keras
Goto Keras_search_engine_web diretório e execute o seguinte comando:
python flaskr.pyAgora navegue pelo seu navegador para http: // localhost: 5000 e você pode experimentar
Com o servidor da API da Web em execução, você pode indexar um novo documento chamando a seguinte API da Web:
http://localhost:5000/index_textPor exemplo, o seguinte é o comando curl para chamar a API da Web para indexar alguns documentos:
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_textPara consultar usando a API da Web, você pode chamar a seguinte API da Web:
curl -H ' Content-Type application/json ' -X POST -d ' {"query":"mathematician and coffee", "limit": 3, "model": "glove"} ' http://localhost:5000/search_textCom o servidor da API da Web em execução, você pode indexar uma nova imagem chamando a seguinte API da Web via solicitação de postagem:
http://localhost:5000/index_imageVocê pode consultar imagens semelhantes chamando a seguinte solicitação de postagem da API da web:
http://localhost:5000/search_image/10onde 10 é o limite do número de imagens retornadas
Há também uma classe SearchEngineclient na Keras_search_engine_client, os códigos de amostra se parecem:
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 )