【问题标题】:Shape of face encodings differ人脸编码的形状不同
【发布时间】:2021-08-14 05:18:46
【问题描述】:

我正在尝试制作一个人脸识别程序,但问题是某些编码的人脸编码形状比其他编码大,因此我得到了错误

ValueError: setting an array element with a sequence.

这是我生成编码的代码

class FaceEncoder():
    def __init__(self, files, singleton = False, model_path='./models/lbpcascade_animeface.xml', scale_factor=1.1, min_neighbours=1):
        self.singleton = singleton
        self.files = files
        self.model = model_path
        self.scale_factor = scale_factor
        self.min_neighbours = min_neighbours

    def encode(self, singleton=False):

        if  self.singleton == False:
            encodings = []
            labels = []

            for file in self.files:
                cascade = cv2.CascadeClassifier(self.model)
                
                image = cv2.imread(file)
                rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

                faces = cascade.detectMultiScale(rgb, self.scale_factor, self.min_neighbours)

                if len(faces) > 0:
                    print('Found face in '+file)
                    encodings.append(faces.flatten())
                    labels.append(file.split('/')[2])
                else:
                    print('Couldnt find face in '+file)

            return encodings, labels

这里有一些编码

[204  96 211 211]
[525 168 680 680]
[205  11 269 269]
[ 165   31  316  316 1098  181  179  179]
[ 113  422 1371 1371]
[ 71  86 183 183]
[209  19  33  33  88  27  60  60 133  80  65  65  68 117  52  52]
[117  77 149 149]
[ 63  77 284 284]
[370 222 490 490]
[433 112 114 114 183  98 358 358]
[ 44  35  48  48 192  34  48  48]
[210  82 229 229]
[429  90 153 153]
[318  50 174 174 118 142 120 120]

【问题讨论】:

  • 照片中的人脸数量可能不同。

标签: python opencv opencv-python torchvision


【解决方案1】:

您不应该将多个找到的矩形放入同一个列表条目中。 如果找到很多人脸,将每个人放在自己的行中,并为找到的每个人脸添加一个标签(不是每个图像)

那么,你现在拥有的不是“编码”,只是盒子/矩形。

阅读如何获得真正的编码(facenet、spherenet?),然后您需要:

  • 裁剪图像中的人脸区域
  • 将其调整为 nn 输入大小(例如 96x96)
  • 通过 nn 运行它以接收编码
  • 那个连同标签一起保存到数据库/列表中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2014-08-20
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    相关资源
    最近更新 更多