108 Star 869 Fork 1.5K

MindSpore/models

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Contents

DeepID-description

论文: Sun Y, Wang X, Tang X. Deep learning face representation from predicting 10,000 classes[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2014: 1891-1898.

This paper proposes to learn a set of high-level feature representations through deep learning, referred to as Deep hidden IDentity features (DeepID), for face verification. We argue that DeepID can be effectively learned through challenging multi-class face identification tasks, whilst they can be generalized to other tasks (such as verification) and new identities unseen in the training set. Moreover, the generalization capability of DeepID increases as more face classes are to be predicted at training. DeepID features are taken from the last hidden layer neuron activations of deep convolutional networks (ConvNets). When learned as classifiers to recognize about 10; 000 face identities in the training set and configured to keep reducing the neuron numbers along the feature extraction hierarchy, these deep ConvNets gradually form compact identity-related features in the top layers with only a small number of hidden neurons. The proposed features are extracted from various face regions to form complementary and over-complete mrepresentations. Any state-of-the-art classifiers can be learned based on these high-level representations for face verification. 97:45% verification accuracy on LFW is achieved with only weakly aligned faces.

Dataset

YouTube Faces

The data set contains 3,425 videos of 1,595 different people. All the videos were downloaded from YouTube. An average of 2.15 videos are available for each subject. The shortest clip duration is 48 frames, the longest clip is 6,070 frames, and the average length of a video clip is 181.3 frames.

Dataset Process

Used to get the face out of the img. Face in youtube data has been aligned into the center of the img. So this programme aims to increase the ratio of the face in the whole img and resize the img into (47,55), which is the input size for the DeepID.

Crop images

cd ./src

Change the aligned_db_folder and result_folder in crop.py.

python crop.py

Split images

After cropping images, change src_folder in split.py and split data into two set, One is for train and one is for valid.

python split.py

Environment Requirements

Script Description

Script and Sample Code

.
└─ DeepID
  ├── ascend310_infer                 // 310 infer directory
  ├─ README.md                        // Descriptions about DeepID
  ├─ scripts
    ├─ run_standalone_train_ascend.sh // Train standalone
    ├─ run_distribute_train_ascend.sh // Train distribute
    ├─ run_eval_ascend.sh             // Evaluation
    ├─ run_infer_310.sh               // 310 inference
    ├─ eval_ascend.sh             // Evaluation
    ├─ run_standalone_train_gpu.sh // Train standalone
    ├─ run_distribute_train_gpu.sh // Train distribute
    └─ eval_gpu.sh             // Evaluation
  ├─src
    ├─ dataset.py                     // Prepare dataset
    ├─ loss.py                        // Loss function
    ├─ model.py                       // Define subnetwork about DeepID
    ├─ util.py                        // Utils for DeepID
    ├─ reporter.py                    // Reporter class
    ├─ cell.py                        // StarGAN model define
    ├─ crop.py                        // Crop images
    ├─ split.py                       // Split train and valid dataset
  ├─ eval.py                          // Evaluation script
  ├─ train.py                         // Train script
  ├─ export.py                        // Export mindir script
  ├─ preprocess.py                    // Convert images and labels to bin
  ├─ postprocess.py                   // Calculate accuracy

Script parameters

'data_url':'./data/'      # Dataset path
'epochs':200              # Total epochs
'lr':1e-4                 # Learning rate
'batch_size':2048         # Batch size
'input_dim':125           # Image dim
'ckpt_path':''            # Checkpoint saving path
'run_distribute':0        # Run distribute, default: 0
'device_target':'Ascend'  # Device target
'device_id':4             # Device id, default: 0
'device_num':1            # Number of device, default: 1
'rank_id':0               # Rank id, default: 0
'modelarts':0             # Running on modelarts
'train_url':'None'        # Train output path in modelarts

After installing MindSpore, follow these steps:

Training Process

Train on Ascend

# train standalone
bash run_standalone_train_ascend.sh [DEVICE_NUM] [DEVICE_ID]

# train distribute
bash run_distribute_train.sh [DEVICE_NUM] [DISTRIBUTE] [RANK_TABLE_FILE]

Train on GPU

# train standalone
bash run_standalone_train_gpu.sh [DEVICE_ID] [DATA_DIR]
for example: bash run_standalone_train_gpu.sh 0 ./data

# train distribute
bash run_distribute_train_gpu.sh [DEVICE_NUM] [CUDA_VISIBLE_DEVICES(0,1,2,3,4,5,6,7)] [DATA_DIR]
for example: bash run_distribute_train_gpu.sh 8 0,1,2,3,4,5,6,7 /home/DeepID/data

Prediction Process

Eval on Ascend

# Evaluation on Ascend
sh eval_ascend.sh [DEVICE_NUM] [DEVICE_ID]

Ascen 310 infer

Before inference, please refer to MindSpore Inference with C++ Deployment Guide to set environment variables.

Export MindIR

python export.py

Infer on Ascend 310

cd scripts
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DEVICE_ID]
  • MINDIR_PATH Directionary of MINDIR
  • DATA_PATH Directionary of dataset
  • DEVICE_ID Optional, default 0

======= Eval on GPU

# Evaluation on GPU
bash eval_gpu.sh [DEVICE_ID] [CHECKPOINTPATH] [DATA_DIR] [MODE(valid,test)]
for example: bash eval_gpu.sh 0 /home/DeepID.ckpt /home/DeepID/data valid

Result

The evaluation results will be saved in the sample path in a log file named "log_eval.txt". You can find results similar to the following in the log.

Valid dataset accuracy: 0.9683

Model Description

Performance

Training Performance

Parameters Ascend 910 GPU
Model Version DeepID DeepID
Resource Ascend GPU
uploaded Date 11/04/2021 (month/day/year) 11/18/2021
MindSpore Version 1.3.1 1.5.0
Dataset Youtube Face Youtube Face
Training Parameters epochs=200, batch_size=1024, lr=0.0001 epochs=200, batch_size=2048, lr=0.0001
Optimizer Adam Adam
outputs Accuracy = 99.18% Accuracy = 99.24%
Speed 1pc: 900 ms/step; 1pc: 1250 ms/step 8pc:290 ms/step
Total time 1pc: 3h6s; 1pc: 4:44:52 8pc:0:50:23
Parameters (M) 4.56 M 4.56 M
Checkpoint for Fine tuning 2.03 M (.ckpt file) 2.03 M (.ckpt file)

Inference Performance

Parameters Ascend 910 GPU
Model Version DeepID DeepID
Resource Ascend GPU
Uploaded Date 11/04/2021 (month/day/year) 11/18/2021
MindSpore Version 1.3.1 1.5.0
Dataset Youtube Face Youtube Face
batch_size 512 256
outputs Accuracy = 96.83% Accuracy = 95.05%
Parameters Ascend 310
Model Version DeepID
Resource Ascend
Uploaded Date 11/30/2021 (month/day/year)
MindSpore Version 1.3.1
Dataset Youtube Face
batch_size 1
outputs Accuracy = 96.83%

ModelZoo Homepage

Please check the official homepage.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mindspore/models.git
git@gitee.com:mindspore/models.git
mindspore
models
models
master

搜索帮助