A binary classifier implemented with a support vector machine (SVM) written in C and converted to HLSL to be used inside VRChat. I have included a program that allows you to train your own detector. You can use it to detect other objects as well.
My implementation has three camera inputs to detect varying sizes 480 x 270, 240 x 135, 120 x 67. A 64 x 64 sliding window is applied with a stride of 16 pixels for the largest camera inputs to 8 pixels for the smallest.
HOG features are extracted by binning by the magnitude of the gradient according to the direction of the gradient into 8 bins. The features are normalized to account for differences in lighting.
The radial basis function (RBF) kernel is applied to each of the 1568 features per 64 x 64 image block and the support vectors. At the end, classification is done by doing the summation of all RBF calculations per 64 x 64 image block.
I have fixed most of the problems I listed in the previous implementation. However,
- In VRChat, cameras are friends only, you can only show this to your friends.
- SVMs needs to store data of the hyperplane that does the classification. So more training = more complex hyper plane = lag in game.
No prerequisites, either clone the repository or download the latest Release and open it in Unity
These steps are only for the people who want to train their own detector.
- Get the svm-detector.exe in Release or compile it yourself. The .exe only works with x64 bit machines, anything else you'll have to compile it yourself. Compiling the C code requires OpenCV 4.0.1.
- Layout your training data like this example for the Faces folder. All pictures must be 64 x 64 in size.
- Run svm-detector.exe with the path to the folder. For example,
svm-detector.exe D:\Storage\Datasets\Faces 100
will look for images in the Faces folder and train for 100 iterations. - After the program finishes, it will output a
svm-out.xml
file containing the support vectors for classification. - To use it inside VRChat, drop the
svm-out.xml
file into the Unity project with this repository. - Navigate the menu Tool -> SCRN -> Bake Support Vectors, put in the .xml file and hit Bake!
- After a few seconds there should be a new
SupportVectors.asset
file in the SVM Detector folder. If aSupportVectors.asset
already exists, it will be overwritten. - In the SVM prefab, find the game object called SVM place the new
SupportVectors.asset
into the Support Vectors texture slot.
- Click on the
svm-out.xml
file and look at the contents in the Inspector, remember the sv_total number.
- Locate
svmhelper.cginc
inside the Shaders folder. - Change number after SV_NUM in
svmhelper.cginc
to the number you saw for sv_total insidesvm-out.xml
.
- Done!
Contact me on Discord if you have any questions or suggestions: SCRN#8008
Thanks to Merlin and 1001 for making this possible.