顔認識処理(GPU)
本項では、GPUインスタンスを使用して顔認識を行う方法を説明します。ここでは GPUインスタンスによる顔認識 Face Recognitionというライブラリを使用して顔認識を行います。
顔認識処理のソースコードの内容 ダウンロードしたソースコードの Server フォルダーにある face.py が顔認識処理を行う部分になります。
get_face_locations(image_file) は画像ファイルのバイナリデータを引数として受け取り、Face Recognition による画像処理を行ってその画像の中にある顔をすべて発見し、それらの位置を示した長方形の左右のx座標と上下のy座標を (top, right, bottom, left) の tuple で表し、配列にして返します。
なお、この処理は次項で説明するAPIから呼び出され、自動で処理されるので何かの操作をする必要はありません。
また、お使いのインスタンスのリソース等が不足している場合、4行目の
の model = "cnn" という部分を model = "hog" に書き換えることでより軽量な処理が行えます。return face_recognition.face_locations(face_recognition.load_image_file(image_file), model = "cnn")
Face Recognitionのライセンス表示です。 ライセンス
MIT LicenseCopyright (c) 2021, Adam GeitgeyPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.