
YOLOX官方文档
YOLOX开源地址
git clone git@github.com:Megvii-BaseDetection/YOLOX.git问题1:ping不通github
查github的ip地址网址:
https://ipaddress.com/website/github.com#ipinfo
命令行输入:vim /etc/hosts
加入一行 140.82.114.3 github.com (我现在查的是这个)
cd YOLOX
pip3 install -U pip && pip3 install -r requirements.txt
问题2:ERROR: pip下载超时换源(我用的清华源)
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学 http://pypi.hustunique.com/
山东理工大学 http://pypi.sdutlinux.org/
pip3 install -U pip && pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install -v -e . # or python3 setup.py develop
问题3:error: can’t create or remove files in install directory(权限不够)sudo python3 setup.py developStep2. Install pycocotools.
pip3 install cython pip3 install pycocotools
官网的这一步的代码,我一直报错,用这个不报错
2.Demo Step1. Download a pretrained model from the benchmark table.
下载一个预训练模型
python tools/demo.py image -n yolox-s -c /path/to/your/yolox_s.pth --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu]
把/path/to/your/yolox_s.pth更换成你下载模型时存放的地址
我的是python tools/demo.py image -n yolox-s -c weights/yolox_s.pth --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu]
可以看见,最后一行的输出就是检测结果保存的位置,到达那个路径下就能看到检测的图片
也可以换的自己照片检测,比如
把这张图片放在assets文件夹里,然后执行
python tools/demo.py image -n yolox-s -c weights/yolox_s.pth --path assets/chicken.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu]
就能得到检测后图像
ncnn开源地址
ncnn官方教程
参考大佬的做法
git clone https://github.com/Tencent/ncnn.git cd ncnn sudo apt install build-essential git cmake libprotobuf-dev protobuf-compiler libvulkan-dev vulkan-utils libopencv-dev mkdir -p build cd build cmake .. make cd ../examples ../build/examples/squeezenet ../images/256-ncnn.png问题1 段错误 (核心已转储)
可能是数组/堆栈越界之类的,不知道具体原因,也不知道怎么就好使了,我进行了以下操作:
git submodule update --init
继续测试验证
cd ../examples ../build/examples/squeezenet ../images/256-ncnn.png
cd ../benchmark ../build/benchmark/benchncnn 10 $(nproc) 0 0Step2 Use provided tools to generate onnx file. For example, if you want to generate onnx file of yolox-s, please run the following command
cd < path of yolox>
python3 tools/export_onnx.py -n yolox-s
cd YOLOX
python3 tools/export_onnx.py -n yolox-s
问题2 An error has been caught in function ‘’, process ‘MainProcess’ (19995), thread ‘MainThread’python3 tools/export_onnx.py -n yolox-s -c weights/yolox_s.pth ~~官方代码后面没有加训练权重路径,加上后就不报错了,正确生成了onnx文件~~Step3 Generate ncnn param and bin file.
cd < path of ncnn>
cd build/tools/ncnn
./onnx2ncnn yolox.onnx model.param model.bin
注意:
1.把刚刚生成的YOLOX路径下的yolox.onnx复制到ncnn/build/tools/onnx路径下
2.看看自己的文件路径,教程是ncnn,我的是onnx
cd ncnn/build/tools/onnx ./onnx2ncnn yolox.onnx yolox.param yolox.binStep4 Open model.param, and modify it.
修正yolox.param文件。
在刚刚复制yolox.onnx的路径下,找到并打开yolox.param,进行以下修改:
1.把第二行的第一个数字减去9
(since we will remove 10 layers and add 1 layers, total layers number should minus 9).
因为我们将去除十层并添加一层,所以总层数减去9
235 -> 226
2.删除10层,替换为focus层
Step5 Use ncnn_optimize to generate new param and binremove 10 lines of code from Split to Concat, but remember the last but 2nd number: 683.
删除从 Split 到 Concat 的十行代码,并且记住倒数第二个数字
Add YoloV5Focus layer After Input (using previous number 683)
添加focus层并且用到先前记住的数字
YoloV5Focus focus 1 1 images 502
cd ncnn/build/tools/onnx ../ncnnoptimize yolox.param yolox.bin yolox-opt.param yolox-opt.bin 65536Step6 Copy or Move yolox.cpp file into ncnn/examples, modify the CMakeList.txt, then build yolox
在 YOLOX/demo/ncnn/cpp/yolox.cpp 路径下找到yolox.cpp,复制到 ncnn/examples/
(最新的nccn已经自带yolox.cpp文件,不需要复制了> ^ <)
cd ncnn/examples/ vim yolox.cpp
第264和265行,修改模型路径
yolox-opt.param和yolox-opt.bin
重新编译nccn
# 删除之前的build目录,重建 # 注意保存在/ncnn/build/tools/onnx路径下的`yolox-opt.param`和`yolox-opt.bin`文件,随便存在哪儿,等会还要用到 rm -rf build mkdir build cd build cmake .. makeStep7 Inference image with executable file yolox, enjoy the detect result:
./yolox demo.jpg
cd ./examples # 在这个路径下会有一个可执行yolox文件 # 放一个demo图片,记住路径 # 复制模型在正确路径(把刚刚保存的`yolox-opt.param`和`yolox-opt.bin`文件放在这个路径下) ./yolox ../assets/dog.jpg问题3:段错误
如果路径找不到,会报错:
fopen yolox-opt.param failed fopen yolox-opt.bin failed find_blob_index_by_name images failed Try find_blob_index_by_name output failed Try 段错误 (核心已转储)
把之前生成的opt两个文件复制到当前路径下,还是报错
find_blob_index_by_name input failed 段错误 (核心已转储)
准备阅读yolox.cpp的源码,今日工作告一段落 2022.06.22
2022.06.23找到错误原因了!!!
问题出在step4,因为我的param文件里concat层没有单纯的数字,因此focus层最后一个数字是错的,把应该出现数字的那一行写成input就可以了!多亏了ncnn群里的大佬!(致谢致谢)这个群
如图修改后,回到step5,就不会报段错误啦!成功跑通demo!
(没读源码…)
使用netron{
访问netron.app
netron开源地址:https://github.com/lutzroeder/netron#install
安装成功后,直接在命令行输入netron,然后稍等片刻,就会弹出这个软件啦
}
查看自己修改后的param文件,能看出有没有改对
从图上容易看出,output参数改为input的时候,才能连在一起,虽然不知道为啥,但是想必连在一起才是对的吧。至此,困扰我几个小时的难题终于解决啦!
其实可以用netron看看最初的param文件,得出concat的output参数就是input!以后碰到类似问题也可以这么查一下。