【问题标题】:Finding out distance between output of two Convolutional Neural Network (CNN) i.e Siamese Network找出两个卷积神经网络(CNN)的输出之间的距离,即连体网络
【发布时间】:2021-12-22 00:46:43
【问题描述】:

我正在尝试构建一个简单的连体神经网络,用于人类重新识别。

为此,我使用 MTCNN (https://github.com/timesler/facenet-pytorch) 进行人脸检测,并使用 pytorch 官方实现 arcface 算法 (https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch) 进行 CNN 实现。

我使用了在 resnet 50 上训练的预训练模型 (ms1mv3_arcface_r50_fp16) 和来自其存储库的主干 CNN 模型来实现 CNN。 CNN 获取 112x112 的图像并生成一个 512x1 的数组。

所以我得到了两个数组作为网络的结果。我尝试使用余弦相似度比较两个数组,但它并没有一直给我正确的结果。

那么,我需要更改模型参数还是需要使用其他指标进行比较?

我的代码:https://gist.github.com/desertSniper87/26f5f45f4cece9d0f3008e89cea94be8

【问题讨论】:

    标签: neural-network pytorch conv-neural-network face-recognition arcface


    【解决方案1】:

    我已经尝试过使用标准 dlib 人脸向量 (128x1) 充分享受 Elasticsearch... ES 可以超级快速准确地存储、搜索和比较此类向量。 我用这样的东西来创建一个 ES 索引:

    from elasticsearch import Elasticsearch
    
    es = Elasticsearch([{'host': ELASTIC_HOST, 'port': ELASTIC_PORT }], 
                           timeout=30, retry_on_time=True, max_retries=3,
                           http_auth=(ELASTIC_NAME, ELASTIC_PSW)
                       )
    
    mapping = {
         "mappings": {
         "properties": {
             "face_vector":{
                 "type": "dense_vector",
                 "dims": 128
                  },
             "pic_file": {
                 "type": "text"},
             "face_loc": {
                 "type": "integer"}
                 }
             }
         }
     es.indices.create(index="fr_idx", body=mapping)
    

    然后

    s_body = {"size": ELASTIC_MAX_RESULTS, "min_score": tolerance,
                              "query": {
                                    "script_score": {
                                        "query": {
                                            "match_all": {}
                                        },
                                "script": {
                                    "source": "1 / (1 + l2norm(params.query_vector, 'face_vector'))",
                                    "params": {"query_vector": UNKNOWN_FACE_ENCOD}
                                            }
                                        }
                                    }
                            }
    res = es.search(index="fr_idx", body=s_body) #standard index
    for hit in res["hits"]["hits"]:
    ...
    

    搜索相似的向量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      • 2020-05-26
      • 2019-08-03
      • 1970-01-01
      • 2015-04-09
      • 2018-01-24
      • 1970-01-01
      相关资源
      最近更新 更多