此存儲庫實現了SSD(單鏡頭多貝克斯檢測器)。該實施受到項目SSD.Pytorch和Dentectron的嚴重影響。設計目標是模塊化和可擴展性。
目前,它具有MobilenetV1,MobilenetV2和基於VGG的SSD/SSD-LITE實現。
它還具有在Google Open Images數據集上進行重新培訓的隔開支持。

請下載模型,然後將它們放入文件夾“ ./models”。以下各節將需要它們。 URL:https://drive.google.com/drive/folders/1pkn-rifvjgwiox0zcrltcxm5gt5laluu?usp=sharing
# If you haven't downloaded the models, please download from https://drive.google.com/drive/folders/1pKn-RifvJGWiOx0ZCRLtCXM5GT5lAluu?usp=sharing.
python run_ssd_live_demo.py mb1-ssd models/mobilenet-v1-ssd-mp-0_675.pth models/voc-model-labels.txt # If you haven't downloaded the models, please download from https://drive.google.com/drive/folders/1pKn-RifvJGWiOx0ZCRLtCXM5GT5lAluu?usp=sharing.
python run_ssd_live_caffe2.py models/mobilenet-v1-ssd_init_net.pb models/mobilenet-v1-ssd_predict_net.pb models/voc-model-labels.txt 您可以使用CAFFE2看到不錯的速度提升。
# If you haven't downloaded the models, please download from https://drive.google.com/drive/folders/1pKn-RifvJGWiOx0ZCRLtCXM5GT5lAluu?usp=sharing.
python run_ssd_live_demo.py mb2-ssd-lite models/mb2-ssd-lite-mp-0_686.pth models/voc-model-labels.txt 上述MobileNetV2 SSD-Lite模型與ONNX兼容不兼容,因為它使用了Relu6,而Relu6不支持ONNX。該代碼支持與ONNX兼容的版本。一旦我用Relu培訓了足夠好的MobilenetV2模型,我將上傳相應的Pytorch和Caffe2型號。
您可能會注意到Mobilenetv2 SSD/SSD-Lite比PC上的Mobilenetv1 SSD/Lite慢。但是,MobilenetV2在移動設備上的速度更快。
如果您尚未下載模型,請從https://drive.google.com/drive/folders/1pkn-rifvjgwiox0zcrltcxm5gt5gt5laluu?usp = sharing下載。
型號:Mobilenet-V1-SSD-MP-0_675.pth
Average Precision Per-class:
aeroplane: 0.6742489426027927
bicycle: 0.7913672875238116
bird: 0.612096015101108
boat: 0.5616407126931772
bottle: 0.3471259064860268
bus: 0.7742298893362103
car: 0.7284171192326804
cat: 0.8360675520354323
chair: 0.5142295855384792
cow: 0.6244090341627014
diningtable: 0.7060035669312754
dog: 0.7849252606216821
horse: 0.8202146617282785
motorbike: 0.793578272243471
person: 0.7042670984734087
pottedplant: 0.40257147509774405
sheep: 0.6071252282334352
sofa: 0.7549120254763918
train: 0.8270992920206008
tvmonitor: 0.6459903029666852
Average Precision Across All Classes:0.6755
如果您尚未下載模型,請從https://drive.google.com/drive/folders/1pkn-rifvjgwiox0zcrltcxm5gt5gt5laluu?usp = sharing下載。
型號:MB2-SSD-LITE-MP-0_686.PTH
Average Precision Per-class:
aeroplane: 0.6973327307871002
bicycle: 0.7823755921687233
bird: 0.6342429230125619
boat: 0.5478160937380846
bottle: 0.3564069147093762
bus: 0.7882037885117419
car: 0.7444122242934775
cat: 0.8198865557991936
chair: 0.5378973422880109
cow: 0.6186076149254742
diningtable: 0.7369559500950861
dog: 0.7848265495754562
horse: 0.8222948787839229
motorbike: 0.8057808854619948
person: 0.7176976451996411
pottedplant: 0.42802932547480066
sheep: 0.6259124005994047
sofa: 0.7840368059271103
train: 0.8331588002612781
tvmonitor: 0.6555051795079904
Average Precision Across All Classes:0.6860690100560214
重新生產模型的代碼:
# If you haven't downloaded the models, please download from https://drive.google.com/drive/folders/1pKn-RifvJGWiOx0ZCRLtCXM5GT5lAluu?usp=sharing.
python train_ssd.py --dataset_type voc --datasets ~ /data/VOC0712/VOC2007 ~ /data/VOC0712/VOC2012 --validation_dataset ~ /data/VOC0712/test/VOC2007/ --net mb2-ssd-lite --base_net models/mb2-imagenet-71_8.pth --scheduler cosine --lr 0.01 --t_max 200 --validation_epochs 5 --num_epochs 200型號:VGG16-SSD-MP-0_7726.pth
Average Precision Per-class:
aeroplane: 0.7957406334737802
bicycle: 0.8305351156180996
bird: 0.7570969203281721
boat: 0.7043869846367731
bottle: 0.5151666571756393
bus: 0.8375121237865507
car: 0.8581508869699901
cat: 0.8696185705648963
chair: 0.6165431194526735
cow: 0.8066422244852381
diningtable: 0.7629391213959706
dog: 0.8444541531856452
horse: 0.8691922094815812
motorbike: 0.8496564646906418
person: 0.793785185549561
pottedplant: 0.5233462463152305
sheep: 0.7786762429478917
sofa: 0.8024887701948746
train: 0.8713861172265407
tvmonitor: 0.7650514925384194
Average Precision Across All Classes:0.7726184620009084
重新生產模型的代碼:
wget -P models https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth
python train_ssd.py --datasets ~ /data/VOC0712/VOC2007/ ~ /data/VOC0712/VOC2012/ --validation_dataset ~ /data/VOC0712/test/VOC2007/ --net vgg16-ssd --base_net models/vgg16_reducedfc.pth --batch_size 24 --num_epochs 200 --scheduler " multi-step” —-milestones “120,160” python train_ssd.py --datasets ~ /data/VOC0712/VOC2007/ ~ /data/VOC0712/VOC2012/ --validation_dataset ~ /data/VOC0712/test/VOC2007/ --net mb1-ssd --base_net models/mobilenet_v1_with_relu_69_5.pth --batch_size 24 --num_epochs 200 --scheduler cosine --lr 0.01 --t_max 200數據集路徑是文件夾的父目錄:註釋,圖像集,JPegimages,SecenmentationClass和SecgementationObject。您可以使用多個數據集進行訓練。
python eval_ssd.py --net mb1-ssd --dataset ~ /data/VOC0712/test/VOC2007/ --trained_model models/mobilenet-v1-ssd-mp-0_675.pth --label_file models/voc-model-labels.txt python convert_to_caffe2_models.py mb1-ssd models/mobilenet-v1-ssd-mp-0_675.pth models/voc-model-labels.txt 轉換後的模型是模型/Mobilenet-v1-ssd.onnx,型號/mobilenet-v1-ssd_init_net.pb和型號/mobilenet-v1-ssd_predict_net.pb。還保存了PBTXT格式的模型以供參考。
讓我們正在建立一個模型來檢測出於安全目的的槍支。
在開始之前,您可以嘗試演示。
python run_ssd_example.py mb1-ssd models/gun_model_2.21.pth models/open-images-model-labels.txt ~ /Downloads/big.JPG
如果您設法獲得更多註釋的數據,那麼準確性可能會更高。
python open_images_downloader.py --root ~ /data/open_images --class_names " Handgun,Shotgun " --num_workers 20它將將數據下載到文件夾〜/data/open_images。
數據目錄的內容如下。
class-descriptions-boxable.csv test validation
sub-test-annotations-bbox.csv test-annotations-bbox.csv validation-annotations-bbox.csv
sub-train-annotations-bbox.csv train
sub-validation-annotations-bbox.csv train-annotations-bbox.csv
文件夾訓練,測試,驗證包含圖像。諸如sub-Train-Annotations-bbox.csv之類的文件是註釋文件。
python train_ssd.py --dataset_type open_images --datasets ~ /data/open_images --net mb1-ssd --pretrained_ssd models/mobilenet-v1-ssd-mp-0_675.pth --scheduler cosine --lr 0.01 --t_max 100 --validation_epochs 5 --num_epochs 100 --base_net_lr 0.001 --batch_size 5您可以凍結基本網或除預測頭外的所有圖層。
--freeze_base_net Freeze base net layers.
--freeze_net Freeze all the layers except the prediction head.
您還可以為基礎網,額外的層和預測頭使用不同的學習率。
--lr LR, --learning-rate LR
--base_net_lr BASE_NET_LR
initial learning rate for base net.
--extra_layers_lr EXTRA_LAYERS_LR
由於開放式圖像數據的子集可能非常不平衡,因此它也提供了一個方便的選項,以大致平衡數據。
--balance_data Balance training data by down-sampling more frequent
labels.
python run_ssd_example.py mb1-ssd models/mobilenet-v1-ssd-Epoch-99-Loss-2.2184619531035423.pth models/open-images-model-labels.txt ~ /Downloads/gun.JPG呢由於此處提到的問題“#33(評論)”,該模型並不是真正友好的友好型。
縮放的L2標準層已被BatchNorm替換,以使NET ONNX兼容。
基於預處理的是從https://s3.amazonaws.com/amdegroot-models/vgg16_reduccesfc.pth借用的。
python train_ssd.py --datasets ~ /data/VOC0712/VOC2007/ ~ /data/VOC0712/VOC2012/ --validation_dataset ~ /data/VOC0712/test/VOC2007/ --net " vgg16-ssd " --base_net models/vgg16_reducedfc.pth --batch_size 24 --num_epochs 150 --scheduler cosine --lr 0.0012 --t_max 150 --validation_epochs 5python eval_ssd.py --net vgg16-ssd --dataset ~ /data/VOC0712/test/VOC2007/ --trained_model models/vgg16-ssd-Epoch-115-Loss-2.819455094383535.pth --label_file models/voc-model-labels.txt