# pytorch-mtcnn **Repository Path**: jian.yang/pytorch-mtcnn ## Basic Information - **Project Name**: pytorch-mtcnn - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-01-23 - **Last Updated**: 2020-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pytorch-mtcnn ### Description This repository is the implementation of mtcnn in Pytorch,I refer to different versions of mtcnn and use the pytorch dataloader to improve training speed.5x faster than [Dface](https://github.com/kuaikuaikim/DFace) ### Requirements - cuda - pytorch==0.4.1 - torchvision - opencv-python ### Train #### train PNet - genterate PNet training data by random crop.(Widerface) > gen_Pnet_train_data.py - You can control the proportion of positive , part and negative samples (original paper 1:1:3) > assemble_pnet_imglist.py pnet training accuracy: 0.94~0.97 rnet val accuracy: 0.95+ #### train RNet - genterate RNet training data from PNet.(Widerface) > gen_Rnet_train_data.py - You can control the proportion of positive , part and negative samples (original paper 1:1:3) > assemble_rnet_imglist.py rnet training accuracy: 0.96~0.98 rnet val accuracy: 0.97+ #### train ONet - genterate landmarks training data. (CelebA) > concat_celeba.py #generate CelebA annotations file > gen_landmark_48.py - genterate ONet training data from PNet and RNet.(Widerface) > gen_Onet_train_data.py - You can control the proportion of landmarks, positive , part and negative samples (original paper 1:1:1:3) > assemble_onet_imglist.py onet training accuracy: 0.98~1.00 onet val accuracy: 0.97+ ### Test - You can control the variable 'eval_net' to test a image result of different stage > eval_net = 'pnet' #'pnet' or 'rnet' or 'onet ### Eval - You can control the variable 'eval_net' to generate 'results.txt' of different stage for evaluting performance on FDDB dataset > eval_net = 'pnet' #'pnet' or 'rnet' or 'onet more detials [FDDB.md](./FDDB.md) ![PNet-DiscRoc-o.png](results/PNet-DiscRoc-o.png) ![PNet-DiscRoc.png](results/PNet-DiscRoc.png) ![RNet-DiscRoc-o.png](results/RNet-DiscRoc-o.png) ![ONet-DiscRoc-o.png](results/ONet-DiscRoc-o.png) ![ONet-DiscRoc.png](results/ONet-DiscRoc.png) **Generally speaking, on FDDB,FP is controlled around 2000.But in practical application, FP should be controlled at about 200,and the threshold is set according to this point** ### Problem The first epoch will last for a long time, pytorch dataloader often shows deadlocks. You can observe through a command 'top'.It may require a warm-up process. ```buildoutcfg TRAIN 2019-03-01 11:24:11.006241 : Epoch: 1, Step: 0, accuracy: 0.7410926818847656, det loss: 0.6196473836898804, bbox loss: 0.37166640162467957, all_loss: 0.8054805994033813, lr:0.002 TRAIN 2019-03-01 11:32:41.833743 : Epoch: 1, Step: 200, accuracy: 0.9054373502731323, det loss: 0.22418668866157532, bbox loss: 0.019734250381588936, all_loss: 0.2340538203716278, lr:0.002 TRAIN 2019-03-01 11:44:26.668400 : Epoch: 1, Step: 400, accuracy: 0.8987654447555542, det loss: 0.23218227922916412, bbox loss: 0.01730342023074627, all_loss: 0.24083398282527924, lr:0.002 TRAIN 2019-03-01 11:56:22.168430 : Epoch: 1, Step: 600, accuracy: 0.9473683834075928, det loss: 0.1604328602552414, bbox loss: 0.015454285778105259, all_loss: 0.16816000640392303, lr:0.002 TRAIN 2019-03-01 12:07:12.314462 : Epoch: 1, Step: 800, accuracy: 0.9357143044471741, det loss: 0.1680484414100647, bbox loss: 0.01593124121427536, all_loss: 0.17601406574249268, lr:0.002 TRAIN 2019-03-01 12:17:55.287553 : Epoch: 1, Step: 1000, accuracy: 0.9357143044471741, det loss: 0.14994080364704132, bbox loss: 0.0172434002161026, all_loss: 0.15856251120567322, lr:0.002 TRAIN 2019-03-01 12:28:12.579960 : Epoch: 1, Step: 1200, accuracy: 0.9507389068603516, det loss: 0.13866440951824188, bbox loss: 0.016900667920708656, all_loss: 0.14711473882198334, lr:0.002 TRAIN 2019-03-01 12:37:23.934922 : Epoch: 1, Step: 1400, accuracy: 0.9401913285255432, det loss: 0.1828363984823227, bbox loss: 0.015601279214024544, all_loss: 0.1906370371580124, lr:0.002 TRAIN 2019-03-01 12:45:21.036745 : Epoch: 1, Step: 1600, accuracy: 0.9315403699874878, det loss: 0.17997661232948303, bbox loss: 0.015366708859801292, all_loss: 0.18765996396541595, lr:0.002 TRAIN 2019-03-01 12:53:52.094597 : Epoch: 1, Step: 1800, accuracy: 0.9294117093086243, det loss: 0.16810014843940735, bbox loss: 0.01578947901725769, all_loss: 0.1759948879480362, lr:0.002 TRAIN 2019-03-01 13:00:36.351267 : Epoch: 1, Step: 2000, accuracy: 0.9487804770469666, det loss: 0.1588975489139557, bbox loss: 0.013397682458162308, all_loss: 0.1655963957309723, lr:0.002 TRAIN 2019-03-01 13:07:44.190391 : Epoch: 1, Step: 2200, accuracy: 0.9436274766921997, det loss: 0.15512438118457794, bbox loss: 0.01775275729596615, all_loss: 0.1640007644891739, lr:0.002 TRAIN 2019-03-01 13:13:26.027167 : Epoch: 1, Step: 2400, accuracy: 0.920918345451355, det loss: 0.1854611486196518, bbox loss: 0.017404457554221153, all_loss: 0.19416338205337524, lr:0.002 TRAIN 2019-03-01 13:19:12.844431 : Epoch: 1, Step: 2600, accuracy: 0.9095238447189331, det loss: 0.19011391699314117, bbox loss: 0.01594424992799759, all_loss: 0.19808603823184967, lr:0.002 TRAIN 2019-03-01 13:23:56.850864 : Epoch: 1, Step: 2800, accuracy: 0.936274528503418, det loss: 0.1977410763502121, bbox loss: 0.017198534682393074, all_loss: 0.20634034276008606, lr:0.002 TRAIN 2019-03-01 13:28:21.849753 : Epoch: 1, Step: 3000, accuracy: 0.9367088675498962, det loss: 0.17542578279972076, bbox loss: 0.01505767647176981, all_loss: 0.18295462429523468, lr:0.002 TRAIN 2019-03-01 13:31:50.551907 : Epoch: 1, Step: 3200, accuracy: 0.9354838728904724, det loss: 0.15597793459892273, bbox loss: 0.01350006740540266, all_loss: 0.1627279669046402, lr:0.002 TRAIN 2019-03-01 13:34:33.314798 : Epoch: 1, Step: 3400, accuracy: 0.9390243887901306, det loss: 0.14755655825138092, bbox loss: 0.014701598323881626, all_loss: 0.15490736067295074, lr:0.002 TRAIN 2019-03-01 13:36:27.099368 : Epoch: 1, Step: 3600, accuracy: 0.9544364809989929, det loss: 0.13087546825408936, bbox loss: 0.013782667927443981, all_loss: 0.13776680827140808, lr:0.002 TRAIN 2019-03-01 13:38:06.836487 : Epoch: 1, Step: 3800, accuracy: 0.9536585211753845, det loss: 0.12164527922868729, bbox loss: 0.015257078222930431, all_loss: 0.12927381694316864, lr:0.002 ... ... ... TRAIN 2019-03-01 13:59:17.529441 : Epoch: 3, Step: 600, accuracy: 0.9635036587715149, det loss: 0.11515301465988159, bbox loss: 0.015635157003998756, all_loss: 0.1229705959558487, lr:0.002 TRAIN 2019-03-01 13:59:28.273249 : Epoch: 3, Step: 800, accuracy: 0.9521410465240479, det loss: 0.12291911989450455, bbox loss: 0.015261675231158733, all_loss: 0.13054995238780975, lr:0.002 TRAIN 2019-03-01 13:59:39.032898 : Epoch: 3, Step: 1000, accuracy: 0.9487804770469666, det loss: 0.11900389194488525, bbox loss: 0.013845100998878479, all_loss: 0.1259264349937439, lr:0.002 TRAIN 2019-03-01 13:59:50.304056 : Epoch: 3, Step: 1200, accuracy: 0.9635036587715149, det loss: 0.103697270154953, bbox loss: 0.01357609499245882, all_loss: 0.11048531532287598, lr:0.002 TRAIN 2019-03-01 14:00:01.455675 : Epoch: 3, Step: 1400, accuracy: 0.9495192766189575, det loss: 0.14476129412651062, bbox loss: 0.012655762024223804, all_loss: 0.15108917653560638, lr:0.002 TRAIN 2019-03-01 14:00:12.503074 : Epoch: 3, Step: 1600, accuracy: 0.9307876229286194, det loss: 0.16576361656188965, bbox loss: 0.014260836876928806, all_loss: 0.17289403080940247, lr:0.002 ```