Need to run LeNet with integer type input from ComputeLibrary
Hi: ComputeLibrary LetNet example only supports float32. When I changed the data type argument to integer (e.g., 32 bit, 16 bit or 8 bit), I got error message from one of the lower level functions. I wonder if there is major effort to change the LeNet example to support these data types. Anyone who has had it working, please give advice. I think there should be an easy way, however, I am new to the library and have not studied deep enough to draw conclusion. Thanks, David
Hi @davidchaozhang , Could you please give us more details? ( compilation command, running example command with parameters and also the logs of the error you get )
Thanks, Manuel
Manuel, I have tried two data types: type=QASYMM8, and type=F16. I am running LeNet example and runs the Compute Library's graph API. The first type triggers error from graph_lenet.cpp:59: QASYMM8 not supported for this graph!!!!
When I tried the second type, the graph configuration is ok, but the data type is not supported in NEON/kernels/NEIm2ColKernel.cpp:
Threads : 1 Target : NEON Data type : F16 Data layout : NHWC Tuner enabled? : false Tuner file : Fast math enabled? : false Data path : /home/pi/projects/LeNet/LeNet/model Image file : /home/pi/projects/LeNet/LeNet/images/0/00.ppm Labels file : /home/pi/projects/LeNet/LeNet/images/labels.txt !!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR in configure src/core/NEON/kernels/NEIm2ColKernel.cpp:391: Data type not supported !!!!!!!!!!!!!!!!!!!!!!!!!!! Test FAILED
Please advice if all the lower level supporting functions for integer types and Float 16 are available. Please also tell how much effort in making changes from the LeNet example to demonstrate different types of integer and their operations. Thanks, David
Hi @davidchaozhang , QASYMM8 is actually supported by all the layers used in the network, but we don't have quantitized coefficients. So, you can just remove ARM_COMPUTE_EXIT_ON_MSG() in the example but you need to provide your own coeffs.
For the F16 data type we need to know running environment and your scons command. F16 is supported on NEON, but only for architectures v8.2 or above. So scons should have arch=arm64-v8.2-a and cpu architecture of the device your are running the program v8.2 or above.
Thanks, Manuel
Hi, Manuel:
Thanks for the prompt reply. I am using Raspberry Pi 3+ as a platform to build and test ComputeLibrary. The arm architecture I used is Armv7a, which is Arm's release OS on Pi3+. I believe it doesn't support F16 based on your input. However, Pi3+ has 64-bit ARM processors, ideally, the hardware should support arm64 compilers. I am going to download Ubuntu Mate for PI and build with arm64-v8x. If you have experience on that, please give me suggestions.
Further question on QASYMM8, is the integer 8 support NEON only in all the layers? Or does this data type also support OPENCL? Does ComputeLibrary support both NEON and OPENCL running at the same time?
I removed ARM_COMPUTE_EXIT_ON_MSG() in the example and had an error message in one of the lower level library calls. I will send you details in the next message after collect it from Pi.
Thanks, David
Hi @davidchaozhang , NEON doesn't support F16, but if you run the graph example with OpenCL you can use F16. We actually have a blog post that goes step by step on running AlexNet on a Raspberry Pi 2 or 3 with Ubuntu Mate 16.04.02: https://community.arm.com/processors/b/blog/posts/running-alexnet-on-raspberry-pi-with-compute-library
It should help you out in setting up the environment. QASYMM8 seems to be supported by all the operators in LeNet.
Theoretically you can use OpenCL and NEON at the same time, but you have to create an adhoc network and manage the tensors. For simplicity we propose our graph_example which will use NEON or OpenCL layers.
Thanks, Manuel
Manuel: Thanks for the blog. I read it and think it is helpful. A few questions as I study more of the library. Please bear with me on these basic questions:
-
To support QASYMM8, do I need to generate an integer typed weight files (such as conv1_w.npy, etc)? Can I still use the float32 weight files? I think you said I need to provide my own coefs. Can you elaborate on how to do that?
-
I converted LeNet weight files from a pretrained tensorflow weights. The shape is {FilterN, Channel, W, H}. Does this match with DataLayout::NCHW? If you have a npy weight file I can try, please let me know. Thanks for your help, David
- You have to convert the float32 weights to QASYMM8 and then give them to the network. You'll probably have to work a bit to find the best offset/scale. Right now our lenet example is provided and has been tested only with float32 weights
- We only have the weights that we are proposing in our example. About how we handle the dimensions in NCHW and NHWC please refer to this function: https://github.com/ARM-software/ComputeLibrary/blob/master/src/graph/Utils.cpp#L124
Best, Manuel
Manuel, Thanks for the reply. I am using r = S(q-Z) to convert float r to the quantized q. I have also found functions in Types.h and QAsymm8.inl to perform the conversion. I assume the scale S and offset Z is estimated per convolution, per pooling, per activation layer. Let me know if my understanding is correct. Also scale and offset need to be carried as data input in npy file. I assume LeNet example has not programmed to take in these extra parameters (QuantizationInfo in and out). Is there other examples in ComputeLibrary that supports the QAsymm8 data input?
Also for data layout, regardless input/output data, and weights, ComputeLibrary uses NCHW format, right?
Thanks, David
Our MobileNet example is proposed also using QASYMM8 with the coefficients already quantitized: https://github.com/ARM-software/ComputeLibrary/blob/master/examples/graph_mobilenet.cpp#L177 As you can see the weight files contains the data and the quantization info is hard coded.
The LeNet example currently doesn't have any quantization info.
You can set the format of the input tensor and (if supported) the layer will be able to carry out the operation. If it cannot it should throw a runtime error during validation
Best, Manuel
Closing for inactivity, feel free to reopen otherwise
advice
Dear Manuel,
I want to run AlexNet, GoogleNet, MobileNet, ResNet, and SqueezeNet graphs in quantized mode. I already run these graphs with dummy input and weights data and measure their performance. Now I want to run them with dummy data in quantized u8 or int8 and measure their performance. Is it possible to run with quantization on CPU and GPU? if Yes, would you please let me know how could I do that?
Best, Ehsan