Questions regrading the AlexNet.h Example
Hello @AnthonyARM and other contributors of AlexNet.h:
I have spent a few hours reading your implementation of AlexNet in ComputeLibrary/tests/model_objects/AlexNet.h. While I could understand most of the codes, there are a few places I feel a little confused. I hope you could help me to clarify them. Thanks!
Question 1: In line 53 of AlexNet.h int fixed_point_position = 4
I found that you the variable fixed_point_position have been used very often later in the codes. I remember the default value is 0, but why do you define fixed_point_position as 4 here?
Question 2: In line 65 of AlexNet.h _reshaped_weights = reshaped_weights;
Isn't the shape of the AlexNet is already fixed, what is motivation behind the reshaping of the weights? Is there a alternative structure for AlexNet?
Questions3: In line 78 of AlexNet.h w[0]->allocator()->init(TensorInfo(TensorShape(11U, 11U, 3U, 96U), 1, dt, fixed_point_position));
I looked up the documentation, and find that the constructor for TensorInfo is
TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, int fixed_point_position = 0);
what does num_channels = 1 mean? why is the num_channel is 1.
Question4: In line 112 of AlexNet.h const unsigned int dt_size = 16 / arm_compute::data_size_from_type(dt);
I also looked up the documentation, dt here is defined as F32, and data_size_from_type(dt) will return a value of 4. Thus the value for dt_size will be 16/4 = 4. And later you used dt_size = 4 to define and initializing many other different variables. Why is dt_size is 4?
Question 5: In line 124 of AlexNet.h w[0]->allocator()->init(TensorInfo(TensorShape(366U * dt_size, 96U / dt_size), 1, dt, fixed_point_position));
I sort of finding a pattern that 366 = 11 * 11 * 3 + 3 (refering to line 78 of TensorShape (11U, 11U, 3U 96U). Why do we add the extra 3? Why isn't the new Tensorship 11 * 11 * 3 = 363?
As also related to questions 4, why do we have 336U * dt_size, and 96U / dt_size.
Questions 6: In lines from 151-156 of AlexNet.h
f(_batches > 1)
{
w[5]->allocator()->init(TensorInfo(TensorShape(9216U * dt_size, 4096U / dt_size), 1, dt, fixed_point_position));
w[6]->allocator()->init(TensorInfo(TensorShape(4096U * dt_size, 4096U / dt_size), 1, dt, fixed_point_position));
w[7]->allocator()->init(TensorInfo(TensorShape(4096U * dt_size, 1000U / dt_size), 1, dt, fixed_point_position));
}
I do not understand why when batch number is greater than 1, we have to change the TensorShape into
TensorShape(9216U * dt_size, 4096U / dt_size
Questions 7: In lines from 436-456 of AlexNet.h
for(auto &wi : w)
{
wi.reset();
}
for(auto &bi : b)
{
bi.reset();
}
w21.reset();
w22.reset();
b21.reset();
b21.reset();
w41.reset();
w42.reset();
b41.reset();
b42.reset();
w51.reset();
w52.reset();
b51.reset();
b52.reset();
If we want to reuse the weights of biases, we do not need to call reset(). right?
Questions 8: The original AlexNet has the Dropout Layer, but I do not see any implementations of the dropout layer. Can we implement dropout Layer by ourself some other way?
P.S. Sorry for so many questions, and I just real want to understand the implementations. I believe the anwsers to those will be really beneficial for me and others who are trying to understand the Compute Library. Thanks!
Hello @XiaoMaol ,
Question 1: We recently added fixed point support in the library thus this is just a default value that we use and is essentially taken into account if you pass QS8 as a data type to the model.
Question 2: The reshaped_weights specifies if the weights that are given as an input to the model have already been reshaped externally. To give more details here, some of the functions in ACL (e.g ConvolutionLayer) reshape the weights matrix to essentially map the Deep Convolution operation into a Matrix Multiplication. Moreover, our matrix multiplication implementation does some layout transformation to achieve higher performance. Thus, this flag just says to the model that the weights that will be provided are already reshaped to the needs of the function and it does not need to do a reshaping again. One of the functions for example that you can use to do the reshaping is NEConvolutionLayerReshapeWeights
Question 3: Number of channels for the Neural Network functions is most of the time 1. This specifies the number of interleaved channels and is usually needed for the Computer Vision modules that we provide, where inputs in interleaved format like RGB are accepted. We assume that in Neural Network modules such inputs will be provided in planar format instead (3 feature maps)
Question 4: This path is taken if the weights given have already been reshaped. So we have to create our tensor shapes in the appropriate manner. If you check each reshaping kernel will see what the expected shape of the reshaped weights should be. We usually reshape depending on the datatype size so that we usually operate on 128-bit vectors and this is the reason we do this 16 / datatype_size calculation.
Question 5: We add 1 more to each row because we embed the bias when we reshape to avoid launching another kernel in the end to do the bias addition. We make it part of the matrix multiplication instead.
Question 6: If batch size is 1 then the FullyConnectedLayer will use an Matrix-Vector Multiplication instead of Matrix-Matrix Multiplication, so the layout reshaping that I mention in Question 4 is not needed. That is essentially the reason that we have two paths there.
Questions 7: Correct, we do it here to avoid holding memory while running the benchmarks.
Questions 8: Well dropout layer is usually used during training to avoid overfitting and its a noop(propagate input to output) during inference. ACL is an inference engine for now, that's why we do not provide a Dropout layer.
Hope this helps
Thanks for all your support and everything!