LoginSignup
5
2

Nextcloud に 私の顔認証モデルがテスト採用された

Posted at

Nextcloud の顔認証アプリケーションで使用するモデルに私の Taguchi model がテスト採用されたようです。

nextcloud-facerecognition.jpg

Nextcloud の概略

Nextcloudは、オンラインストレージの作成と使用のためのクライアント・サーバ型のソフトウェアである。機能的にはDropboxに似ているが、オフプレミスのオンラインストレージサービスは提供しない。Nextcloudはフリーかつオープンソースなので、誰でも自分のプライベートサーバ(英語版)にインストールして利用することができる。
Dropboxのようなプロプライエタリなサービスとは異なり、Nextcloudのようなオープンアーキテクチャではアプリケーションの形でサーバに機能を追加することができ、ユーザーがデータを完全に自身の制御下に置くことができる。
NextcloudはownCloudの作者であるフランク・カーリチェックによって、ownCloudからフォークして誕生した。Nextcloudはカーリチェックやその他のオリジナルのownCloudの開発チームのメンバーによって積極的に開発されている。- (Wikipedia より)

Taguchi model の概略

dlib には優秀な顔認証モデルがあります。しかし、残念ながら人種に偏りがあり、特に北東アジア人、とりわけ日本人に関してはまったく役に立たないと言っても過言ではありません。ですが、それは仕方のないことだと思います。訓練に使用した顔認証用のデータセットに偏りがあったためです。
そこで私は日本人を中心とした多くのデータセットを収集し、ゼロから訓練を行いました。これには途方もない時間を要しましたが、ある程度は実用に耐えうる基準に達したと思います。日本人用に訓練したとは言っても欧米人の顔認証に関しても dlib のモデルに近い結果となってます。dlib の example で用意されているハリウッドのアクション ヒーローの写真も dlib と同様に分類が可能です。

詳細な説明は下記をご覧ください

Face Recognition 担当者からの連絡

今週、Taguchi Models の isuue に Nextcloud の顔認証アプリ担当者から連絡が来ました。

matiasdelellis
Hi @TaguchiModels
Just thank you for the work done. 😄

I work on a facial recognition application for nextcloud. We tried to use the original nextcloud models with very good results, but of course there are people who had these bias problems, who hopefully improve with your work.

So far I'm testing it with a set of test images and at least I'm not seeing regressions. Therefore I am going to recommend that those who have had problems try it.

See:

Add the sixth model to the application. Aka DlibTaguchiHog model. =) matiasdelellis/facerecognition#750

翻訳すると以下の内容でした。

matiasdelellis
こんにちは @TaguchiModels

お仕事に感謝しています。😄

私はNextcloud向けの顔認識アプリケーションに取り組んでいます。元のNextcloudモデルを使用して非常に良い結果が得られましたが、もちろんバイアスの問題があった人々もいました。この問題があなたの作業で改善されることを願っています。

現在、テスト画像のセットでテストしているところで、少なくとも後退は見られません。したがって、問題を抱えていた人々に試してもらうことをお勧めしようと思います。

要するに今までも顔認証アプリは上手くいっていたが、バイアスのかかった(≓アジア人と思われる)一部の人物の顔写真の分類に不満を訴えていたユーザーのために、私のモデルをテスト採用したいとの事でした。

DlibTaguchiHogModelの紹介

組み込まれたソースコードはコチラになります。
'taguchi_face_recognition_resnet_model_v1.dat' が私の作成したモデルになります。

<?php
/**
 * @copyright Copyright (c) 2020-2024, Matias De lellis <mati86dl@gmail.com>
 *
 * @author Matias De lellis <mati86dl@gmail.com>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\FaceRecognition\Model\DlibTaguchiHogModel;

use OCA\FaceRecognition\Helper\FaceRect;

use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnnModel;
use OCA\FaceRecognition\Model\IModel;

class DlibTaguchiHogModel extends DlibCnnModel implements IModel {

	/*
	 * Model files.
	 */
	const FACE_MODEL_ID = 6;
	const FACE_MODEL_NAME = "DlibTaguchiHog";
	const FACE_MODEL_DESC = "Extends the Taguchi model, doing a face validation with the Hog detector";
	const FACE_MODEL_DOC = "https://github.com/matiasdelellis/facerecognition/wiki/Models#model-6";

	/** Relationship between image size and memory consumed */
	const MEMORY_AREA_RELATIONSHIP = 1 * 1024;
	const MINIMUM_MEMORY_REQUIREMENTS = 1 * 1024 * 1024 * 1024;

	/*
	 * Model files.
	 */
	const FACE_MODEL_FILES = [
		'detector' => [
			'url' => 'https://github.com/davisking/dlib-models/raw/94cdb1e40b1c29c0bfcaf7355614bfe6da19460e/mmod_human_face_detector.dat.bz2',
			'filename' => 'mmod_human_face_detector.dat'
		],
		'predictor' => [
			'url' => 'https://github.com/davisking/dlib-models/raw/4af9b776281dd7d6e2e30d4a2d40458b1e254e40/shape_predictor_5_face_landmarks.dat.bz2',
			'filename' => 'shape_predictor_5_face_landmarks.dat',
		],
		'resnet' => [
			'url' => 'https://github.com/TaguchiModels/dlibModels/raw/main/taguchi_face_recognition_resnet_model_v1.7z',
			'filename' => 'taguchi_face_recognition_resnet_model_v1.dat'
		]
	];

	public function detectFaces(string $imagePath, bool $compute = true): array {
		$detectedFaces = [];

		$cnnFaces = parent::detectFaces($imagePath);
		if (count($cnnFaces) === 0) {
			return $detectedFaces;
		}

		$hogFaces = dlib_face_detection($imagePath);

		foreach ($cnnFaces as $proposedFace) {
			$detectedFaces[] = $this->validateFace($proposedFace, $hogFaces);
		}

		return $detectedFaces;
	}

	private function validateFace($proposedFace, array $validateFaces) {
		foreach ($validateFaces as $validateFace) {
			$overlapPercent = FaceRect::overlapPercent($proposedFace, $validateFace);
			/**
			 * The weak link in our default model is the landmark detector that
			 * can't align profile or rotate faces correctly.
			 *
			 * The Hog detector also fails and cannot detect these faces. So, we
			 * consider if Hog detector can detect it, to infer when the predictor
			 * will give good results.
			 *
			 * If Hog detects it (Overlap > 35%), we can assume that landmark
			 * detector will do it too. In this case, we consider the face valid,
			 * and just return it.
			 */
			if ($overlapPercent >= 0.35) {
				return $proposedFace;
			}
		}

		/**
		 * If Hog don't detect this face, they are probably in profile or rotated.
		 * These are bad to compare, so we lower the confidence, to avoid clustering.
		 */
		$confidence = $proposedFace['detection_confidence'];
		$proposedFace['detection_confidence'] = $confidence * 0.6;

		return $proposedFace;
	}

}

このテストモデルは以下から入手可能です。

最後に

もしも、あなた若しくはあなたの会社で Nextcloud を使用していたなら、このテストモデルをぜひ、お試し頂ければと思います。

また、QRコードを使った簡単な顔認証アプリも紹介しています。
特に日本人の顔認証の精度が高くなるよう調整した Taguchi model を使用しています。
あわせてこちらも、ぜひお試しください。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2