I cloned this repository and I replaced the model in "app\src\main\assets" with one I trained myself on YOLOv7.
I trained it using the "yolov7.pt" weights and the results were great.
I followed the official WIKI to get the ONNX and then NCNN model: https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx
Basically I used torch.onnx._export() to create the onnx, then onnxsim to create the simplified version and then onnx2ncnn to get the NCNN version.
So I got the .bin and .param files and I renamed them "yolov7-tiny.bin" and "yolov7-tiny.param" so that I can just paste and replace the existing files in "app\src\main\assets"
I then just built the project using Android Studio, and my "local.properties" are:
sdk.dir=C:\Users\GiannisM\AppData\Local\Android\Sdk
ndk.dir=C:\Users\GiannisM\AppData\Local\Android\Sdk\ndk\25.0.8775105
cmake.dir=C:\Users\GiannisM\AppData\Local\Android\Sdk\cmake\3.22.1
The build was successful so I got the .apk file and I installed it on my phone.
The app works and I can change front and back camera as well as CPU or GPU.
I can see what the camera sees, but object detections isn't working, it's just like a camera app - nothing is being detected.
When I build it with the original "yolov7-tiny.bin" and "yolov7-tiny.param" however, it does draw bounding boxes and it shows the labels.
I should mention that when I evaluate my trained model in python, it does draw bounding boxes and labels - it's just that it doesn't work on the android app.
Any idea why that is?
Lastly, I should say that I couldn't get onnx2ncnn
to work on windows so I installed and used it from WSL (Linux inside windows 11)
I found this post (https://programs.wiki/wiki/622f14b67fea9.html) that mentions things which the official WIKI doesn't mention.
It says that you should have protobuf
and opencv
installed before you install ncnn.
I tried it as it was said on the official WIKI without installing protobuf and opencv and no errors occurred (but like I said, when i open the app I get no detections).
I then uninstalled ncnn, installed protobuf, but the opencv installation fails. Not sure if this is the problem
Update:
I actually downloaded the pre-compiled windows binaries that include onnx2ncnn
but the same things happens where I get video feed but no detections
I also managed to build and install opencv on linux (WSL) and then install ncnn afterwards and the onnx2ncnn works, but I have the exact same problem - no detections
Also, with the original yolov7-tiny.bin
I get 5FPS on my "Razer Phone 2", and with my model it's 30FPS which makes me think that it really just doesn't do any forward passes to do object detection at all.