This is a PyTorch implementation of XNOR-Net, adapted to event-based datasets like N-MNIST.
Tested with:
- Python 3.10.16
- PyTorch 2.7.0 + CUDA 11.8
- TorchVision 0.22.0
- OpenCV 4.11.0
- NumPy 1.24.4
- Pandas 2.2.3
- Matplotlib 3.10.3
- Scikit-learn 1.6.1
- tqdm 4.67.1
conda create -n xnor_net python=3.10 -y
conda activate xnor_net
pip install -r requirements.txt
If you're using CUDA 11.8 and need the official PyTorch binaries:
pip install torch==2.7.0+cu118 torchvision==0.22.0+cu118 --index-url https://download.pytorch.org/whl/cu118
For local testing:
cd N-MNIST/
python main.py --batch-size 2 --test-batch-size 2 --epochs 10
For dgx-1 training
python main.py --batch-size 32 --test-batch-size 32 --epochs 10 --input-dir ../input/nmnist_events_frame/ --output-dir ../output/ --num-workers 4
For dgx-1 training
python main_vgg16.py --batch-size 32 --test-batch-size 32 --epochs 10 --input-dir ../input/cifar10dvs_event_frames_ts/ --output-dir ../output/cifar10dvs_event_frames_ts --num-workers 4
- Trained model:
output/LeNet_5.best.pth.tar
- Confusion matrix:
output/best_confusion_matrix.jpg
- Prediction log:
output/test_preds.csv
- Training accuracy curve:
output/train_accuracy_plot.pdf
MIT. Based on the original XNOR-Net.
g++ -std=c++11 test_binactive.cpp -I /usr/include/eigen3 -o test_binactive
./test_binactive
g++ fullbwresnet.cpp test_binactive.cpp -I /usr/include/eigen3 -O3 -march=native -DEIGEN_MAX_THREADS=4 -pthread -o test_binactive
./test_binactive
g++ fullbwresnet.cpp test_binactive.cpp \
-std=c++17 -O3 -ffast-math -funroll-loops \
-march=native -mtune=native -mfma \
-DNDEBUG -DEIGEN_NO_DEBUG \
-I/usr/include/eigen3 -pthread -fopenmp \
-o test_binactive
g++ fullbwresnet.cpp test_binactive.cpp \
-std=c++17 -O3 -ffast-math -funroll-loops \
-march=native -mtune=native -mfma \
-flto \
-fopenmp -pthread \
-DEIGEN_NO_DEBUG -DEIGEN_DONT_PARALLELIZE -DNDEBUG \
-I/usr/include/eigen3 \
-o test_binactive
cOMP_PROC_BIND=true OMP_NUM_THREADS=4 ./test_binactive
XNOR ACTIVE
g++ xnorresnet.cpp test_xnoractive.cpp \
-std=c++17 -O3 -ffast-math -funroll-loops \
-march=native -mtune=native -mavx2 -mfma -mbmi2 \
-flto -fopenmp -fopenmp-simd -pthread \
-DEIGEN_NO_DEBUG -DNDEBUG \
-I/usr/include/eigen3 -I/usr/local/include \
-o test_xnoractive
cOMP_PROC_BIND=true OMP_NUM_THREADS=4 ./test_xnoractive
perf stat ./test_xnoractive perf record ./test_xnoractive perf report --stdio > perf_report.txt
git clone https://github.com/xtensor-stack/xsimd.git
cd xsimd mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. make -j$(nproc) sudo make install