本計畫的靈感來自 Y. Tang 的《使用線性支持向量機進行深度學習》(2013)。
有關該項目的完整論文可以在 arXiv.org 上閱讀。
卷積神經網路 (CNN) 與「普通」神經網路類似,因為它們由具有「可學習」參數的神經元組成的隱藏層組成。這些神經元接收輸入,執行點積,然後進行非線性運算。整個網絡表達了原始圖像像素與其類別分數之間的映射。按照慣例,Softmax 函數是該網路最後一層使用的分類器。然而,已有研究(Alalshekmubarak 和 Smith,2013;Agarap,2017;Tang,2013)挑戰了這個規範。引用的研究介紹了線性支援向量機 (SVM) 在人工神經網路架構中的使用。這個項目是另一個對主題的嘗試,靈感來自(Tang,2013)。經驗數據表明,CNN-SVM 模型使用 MNIST 資料集能夠達到約 99.04% 的測試精度(LeCun、Cortes 和 Burges,2010)。另一方面,CNN-Softmax 使用相同的資料集能夠實現約 99.23% 的測試精度。這兩個模型也在最近發布的 Fashion-MNIST 資料集(Xiao、Rasul 和 Vollgraf,2017)上進行了測試,該資料集被認為是比 MNIST(Zalandoresearch,2017)更困難的圖像分類資料集。事實證明,CNN-SVM 的測試精度達到了約 90.72%,而 CNN-Softmax 的測試精度達到了約 91.86%。如果對資料集採用資料預處理技術,且基礎 CNN 模型比本研究中使用的模型相對更複雜,則上述結果可能會得到改善。
首先,克隆項目。
git clone https://github.com/AFAgarap/cnn-svm.git/
執行setup.sh
以確保環境中安裝了必備庫。
sudo chmod +x setup.sh
./setup.sh
程序參數。
usage: main.py [-h] -m MODEL -d DATASET [-p PENALTY_PARAMETER] -c
CHECKPOINT_PATH -l LOG_PATH
CNN & CNN-SVM for Image Classification
optional arguments:
-h, --help show this help message and exit
Arguments:
-m MODEL, --model MODEL
[1] CNN-Softmax, [2] CNN-SVM
-d DATASET, --dataset DATASET
path of the MNIST dataset
-p PENALTY_PARAMETER, --penalty_parameter PENALTY_PARAMETER
the SVM C penalty parameter
-c CHECKPOINT_PATH, --checkpoint_path CHECKPOINT_PATH
path where to save the trained model
-l LOG_PATH, --log_path LOG_PATH
path where to save the TensorBoard logs
然後,轉到儲存庫的目錄,並根據所需的參數執行main.py
模組。
cd cnn-svm
python3 main.py --model 2 --dataset ./MNIST_data --penalty_parameter 1 --checkpoint_path ./checkpoint --log_path ./logs
該項目中使用的超參數是手動分配的,而不是透過最佳化。
超參數 | CNN-Softmax | 支援向量機 |
---|---|---|
批量大小 | 128 | 128 |
學習率 | 1e-3 | 1e-3 |
步驟 | 10000 | 10000 |
支援向量機 | 不適用 | 1 |
實驗在配備 Intel Core(TM) i5-6300HQ CPU @ 2.30GHz x 4、16GB DDR3 RAM 和 NVIDIA GeForce GTX 960M 4GB DDR5 GPU 的筆記型電腦上進行。
圖 1. 使用 MNIST 進行影像分類時 CNN-Softmax 和 CNN-SVM 的訓練精確度(左)和損失(右)。
橘色圖指的是CNN-Softmax的訓練準確率和損失,測試準確率為99.22999739646912%。另一方面,藍色圖指的是CNN-SVM的訓練精準度和損失,測試精準度為99.04000163078308%。結果並未證實 Tang (2017) 對 MNIST 手寫數字分類的發現。這可能是由於該專案的資料集沒有進行資料預處理或降維。
圖 2. 使用 Fashion-MNIST 進行影像分類時 CNN-Softmax 和 CNN-SVM 的訓練精確度(左)和損失(右)。
紅色圖指的是CNN-Softmax的訓練準確率和損失,測試準確率為91.86000227928162%。另一方面,淺藍色圖指的是CNN-SVM的訓練精準度與損失,測試精準度為90.71999788284302%。 CNN-Softmax 的結果證實了 zalandoresearch 在 Fashion-MNIST 上的發現。
要引用論文,請使用以下 BibTex 條目:
@article{agarap2017architecture,
title={An Architecture Combining Convolutional Neural Network (CNN) and Support Vector Machine (SVM) for Image Classification},
author={Agarap, Abien Fred},
journal={arXiv preprint arXiv:1712.03541},
year={2017}
}
若要引用儲存庫/軟體,請使用以下 BibTex 條目:
@misc{abien_fred_agarap_2017_1098369,
author = {Abien Fred Agarap},
title = {AFAgarap/cnn-svm v0.1.0-alpha},
month = dec,
year = 2017,
doi = {10.5281/zenodo.1098369},
url = {https://doi.org/10.5281/zenodo.1098369}
}
Copyright 2017-2020 Abien Fred Agarap
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.