Refer to
(1.) https://blog.francium.tech/custom-object-training-and-detection-with-yolov3-darknet-and-opencv-41542f2ff44e
(2.) https://learnopencv.com/training-yolov3-deep-learning-based-custom-object-detector
(3.) https://github.com/pjreddie/darknet/issues/2257
(4.) https://github.com/pjreddie/darknet/issues/1458
Start Training
1.
git clone --recursive https://github.com/pjreddie/darknet
2.
wget https://github.com/arnoldfychen/darknet/blob/master/src/convolutional_layer.c
replace ~/darknet/src/convolutional_layer.c with new one
3. build OpenCV (option)
download branches https://github.com/opencv/opencv/tree/5.x
if you have cuda then -DWITH_CUDA=OFF to -DWITH_CUDA=ON
////////////////////////opencv x64 debug////////////////////////
CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')
echo "CPU number = "$CPU_NUM
mkdir -p build
cd build
cmake .. -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/opt/opencv/x64/debug \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS_DEBUG="-O0 -g" \
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -g" \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_opencv_java=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_CUDA=OFF \
-DCV_ENABLE_INTRINSICS=OFF \
-DENABLE_SSE=OFF \
-DENABLE_SSE2=OFF \
-DENABLE_SSE3=OFF \
-DENABLE_SSSE3=OFF \
-DENABLE_SSE41=OFF \
-DENABLE_SSE42=OFF \
-DENABLE_POPCNT=OFF \
-DENABLE_AVX=OFF \
-DENABLE_AVX2=OFF \
-DENABLE_AVX512F=OFF \
-DENABLE_FMA3=OFF \
-DENABLE_NEON=OFF \
-DENABLE_VFPV3=OFF \
-DENABLE_FAST_MATH=OFF
cmake --build . --config Debug --target install -- -j$CPU_NUM VERBOSE=1
////////////////////////opencv x64 release////////////////////////
CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')
echo "CPU number = "$CPU_NUM
mkdir -p build
cd build
cmake .. -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/opt/opencv/x64/release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="-O3" \
-DCMAKE_CXX_FLAGS_RELEASE="-O3" \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_opencv_apps=OFF \
-DBUILD_opencv_java=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_CUDA=OFF \
-DCV_ENABLE_INTRINSICS=ON \
-DENABLE_SSE=ON \
-DENABLE_SSE2=ON \
-DENABLE_SSE3=ON \
-DENABLE_SSSE3=ON \
-DENABLE_SSE41=ON \
-DENABLE_SSE42=ON \
-DENABLE_POPCNT=ON \
-DENABLE_AVX=ON \
-DENABLE_AVX2=ON \
-DENABLE_AVX512F=OFF \
-DENABLE_FMA3=ON \
-DENABLE_NEON=OFF \
-DENABLE_VFPV3=OFF \
-DENABLE_FAST_MATH=ON
cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1
4.
enable follows if you need
gedit ~/darknet/Makefile
GPU=1
CUDNN=1
OPENCV=1
#save
make -j8
5.
training way Refer to (1.)
create directory ~/darknet/custom_data
create directories cfg, images, labels
create files classes.names, detector.data, test.txt, train.txt
In [labels] there are many xxxxx.txt that are created by labelImg in yolo format
6.
cd ~/darknet
wget https://pjreddie.com/media/files/darknet53.conv.74
7.
./darknet detector train custom_data/detector.data custom_data/cfg/yolov3-custom.cfg darknet53.conv.74
8.
gedit ~/darknet/opencv_cpp/source/opencv_yolo.cpp
the width and height of opencv_yolo.cpp match with ~/darknet/custom_data/cfg/yolov3-custom.cfg
make and run
9. resume training (option)
./darknet detector train custom_data/detector.data custom_data/cfg/yolov3-custom.cfg backup/yolov3-custom_final.weights
bug fixed full source:
https://www.mediafire.com/file/3fsz5rn9f2n58k8/darknet.zip
沒有留言:
張貼留言