server_query_images.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:rekognition-image-search-engine 作者: awslabs 项目源码 文件源码
def search():
    qry = request.args.get('query', '')
    test = np.zeros((tfidf[0].shape))

    keywords = []

    for word in qry.split(' '):
        # validate word
        if len(word) <2 or word in stop_words:
            continue 
        try:
            idx = features.index(word)
            test[0][idx] = 1
        except ValueError, e:
            pass

    cosine_similarities = cosine_similarity(test, tfidf).flatten()
    related_docs_indices = cosine_similarities.argsort()[:-100:-1] # TOP 100 results

    MAX = 100 
    data = []
    related_docs_indices = related_docs_indices[:MAX]
    tag_map = {} # All tags and their counts

    for img in indices[related_docs_indices]:
        file_path = "/Users/smallya/workspace/Rekognition-personal-searchengine/" + img
        labels = d_index[img]
        word = qry.split(' ')[0]
        data.append(file_path)

    print related_docs_indices
    return json.dumps(data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号