When I made a mobile-phone image recognition project the year before last,
Successively tried the Mxnet,thnets,caffe,tensorflow.
At the time, mxnet memory management, memory often due to the lack of allocation of model operations, the app hangs off.
Later investigation of the next Caffe found also very unfriendly.
Finally found that thnets relatively lightweight,
After tuning the algorithm, the performance is good,
In particular, the Accelerate Acceleration library is enabled under iOS.
Later TensorFlow rapid development, cut to TensorFlow on.
Recently saw the next thnets, the author Mvitez seems not very much.
So far, the improvement is not much.
Thnets's mobile sample code, you can refer to:
Https://github.com/e-lab/apps-iOs
Https://github.com/e-lab/apps-android
For a while Nnpack accelerated the library up, just want to give thnets to patch a bit nnpack.
But because the project was too hurried, there was no time to do it.
Later also because of switching to TensorFlow.
Thnets was hidden from the snow.
Submitted two recommendations to the author, 1, using stb_image to load image 2, support Windows platform
I've done both of these jobs.
The author was 1.
2 I closed it. A few days ago to see the history, the author asked me why I closed, I did not return.
The real reason is ... Thnets was forgotten by me, and the existence of the Windows version didn't make much sense.
Today a little bit of time, in Windows to write a thnets demo sample, to the needs of users ~
Project Address:
Https://github.com/cpuimage/thnets
Code examples see: DEMO.C
#include <string.h>#include<stdlib.h>#include<stdio.h>#include"Thnets.h"// http://tntmonks.cnblogs.com/Thnetwork *net;Char* labels[] = {"Lamp","Bottle","Watch","Pen","Grass","Shoe","Wall","Chair","Mug","Fork","Table"," Book","tablet","Bookcase","Pencil","Door"," Face","Ceiling","Sofa","Bicycle","Aluminum-can","window","Road","Stairs"," Floor","painting","Toy","Remote","Computer","Plant","Television","Dog","Laptop","Microwave","Cat","Tree","Knife","Car","Motorcycle"," Person","Cup","Sidewalk","Telephone","Spoon","Hand","sofabed" };intMainintargcChar**argv) {img_t image= {0 }; //test.jpg Char* Pic_file = argv[1]; //Model Char* Model_path = argv[2]; intDropclassifier =0; LoadImage (Pic_file,&image); Thinit (); printf ("init_thnets."); NET=thloadnetwork (Model_path); if(NET) {thusespatialconvolutionmm (net),2); if(Dropclassifier = =1) { if(Net->net->modules[net->net->nelem-1].type = =Mt_softmax) Net->net->nelem--; if(Net->net->modules[net->net->nelem-1].type = =mt_linear) Net->net->nelem--; if(Net->net->modules[net->net->nelem-1].type = =mt_view) Net->net->nelem--; } } Else{printf ("Shiiiiit went down."); return-1; } float* percentages =0; intOutwidth, Outheight; if(!net) { return 0; } inti =0; intNbatch =1; unsignedChar*bitmaps[ the]; for(i =0; i < Nbatch; i++) Bitmaps[i]=Image.bitmap; intSize = thprocessimages (NET, bitmaps, Nbatch, Image.width, Image.height, IMAGE.CP * image.width, &percentages, &ou Twidth, &outheight,0); for(i =0; i < Nbatch; i++) if(Bitmaps[i]) Free(Bitmaps[i]); if(percentages) {floatmax[3] = {0 }; intmaxpos[3] = {0 }; for(intj =0; J < size; J + +) { if(Percentages[j] > max[0]) {maxpos[0] =J; max[0] =Percentages[j]; } Else if(Percentages[j] > max[1]) {maxpos[1] =J; max[1] =Percentages[j]; } Else if(Percentages[j] > max[2]) {maxpos[2] =J; max[2] =Percentages[j]; } } for(intindex =0; Index <3; Index + =1) { Const floatPredictionvalue =Max[index]; if(Predictionvalue >0.05f) {printf ("%f%s \ n", Predictionvalue, Labels[maxpos[index]%size]); } } Free(percentages); } getchar ();}
If you use vs compile, you need to download Openblas:
https://jaist.dl.sourceforge.net/project/openblas/v0.2.19/
LIB Library link file: LIBOPENBLAS.DLL.A can be compiled.
The accompanying model comes from the e-Lab project.
The sample output has the highest score and three results above 0.05.
Example Picture: test.jpg
Sample models: Model
The corresponding label, see the code or the Model folder under the Categories.txt
Above, to have the energy again to thnets performance tuning.
For forward propagation, the best code learning data is: darknet
Https://github.com/pjreddie/darknet
Darknet code is written very engaging, logic clear.
Darknet+nnpack:
Https://github.com/digitalbrain79/darknet-nnpack
If you have other related questions or needs, you can contact me to discuss the email.
e-mail address is:
[Email protected]
Pytorch Mobile End Frame thnets C sample code