Is there any possible to print the intermediate result of each layer?
Problem description: I just run ResNet on the embedded device, but the output label is not correct. So I just wondering is there any way to see the input and output of each layer? I use the Example object to setup the ResNet.
Unfortunately we don't have anything that will print automatically. You have to add the prints manually in each layer you are interested. Here's a couple of thing that should speed up the process:
First compile in debug mode, here are example:
scons os=linux arch=arm64-v8a Werror=1 mode=debug neon=1 opencl=1 examples=1 validation_tests=1 benchmark_tests=1 -j32
This will enable the print function of a tensor. CLTensors work a little different from Tensor (used by NEON). Since you didn't specify I will go with NEON which is a little simpler. The idea would be to print the output tensor of the kernels used by the network after the result has been computed. Here an example:
output_tensor->print(std::cout)
Checking which kernel are being used manually might be time consuming, so you can use one of the benchmark functionalities to check the used kernels for you. Here is the command:
./tests/benchmark_graph_resnet50 --instruments=SCHEDULER_TIMER_MS --example_args=--layout=NHWC,--target=NEON
...
SchedulerTimer/block1/unit1/bottleneck_v1/Relu/NEActivationLayerKernel #16: AVG=1.8680 ms
SchedulerTimer/block1/unit1/bottleneck_v1/add/NEArithmeticAdditionKernel #15: AVG=4.1030 ms
SchedulerTimer/block1/unit1/bottleneck_v1/add/NEFillBorderKernel #14: AVG=0.0030 ms
SchedulerTimer/block1/unit1/bottleneck_v1/conv1/BatchNorm/NEBatchNormalizationLayerKernel #5: AVG=2.7400 ms
SchedulerTimer/block1/unit1/bottleneck_v1/conv1/convolution/NEGEMMAssemblyWrapperKernel/sgemm_nativeA_pretransposeB_16x4 #4: AVG=5.4380 ms
SchedulerTimer/block1/unit1/bottleneck_v1/conv2/BatchNorm/NEBatchNormalizationLayerKernel #11: AVG=9.8840 ms
SchedulerTimer/block1/unit1/bottleneck_v1/conv2/BatchNorm/NEBatchNormalizationLayerKernel #9: AVG=2.8020 ms
SchedulerTimer/block1/unit1/bottleneck_v1/conv2/convolution/NEGEMMAssemblyWrapperKernel/sgemm_nativeA_pretransposeB_16x4 #7: AVG=12.4590 ms
Let's take NEActivationLayerKernel as example, here where you should add you code: https://github.com/ARM-software/ComputeLibrary/blob/master/src/core/NEON/kernels/NEActivationLayerKernel.cpp#L572
Which should become:
void NEActivationLayerKernel::run(const Window &window, const ThreadInfo &info)
{
ARM_COMPUTE_UNUSED(info);
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
ARM_COMPUTE_ERROR_ON(_func == nullptr);
(this->*_func)(window);
_output->print(std::cout);
}
Hope this helps Thanks
Unfortunately we don't have anything that will print automatically. You have to add the prints manually in each layer you are interested. Here's a couple of thing that should speed up the process:
First compile in debug mode, here are example:
scons os=linux arch=arm64-v8a Werror=1 mode=debug neon=1 opencl=1 examples=1 validation_tests=1 benchmark_tests=1 -j32This will enable the print function of a tensor. CLTensors work a little different from Tensor (used by NEON). Since you didn't specify I will go with NEON which is a little simpler. The idea would be to print the output tensor of the kernels used by the network after the result has been computed. Here an example:
output_tensor->print(std::cout)Checking which kernel are being used manually might be time consuming, so you can use one of the benchmark functionalities to check the used kernels for you. Here is the command:
./tests/benchmark_graph_resnet50 --instruments=SCHEDULER_TIMER_MS --example_args=--layout=NHWC,--target=NEON ... SchedulerTimer/block1/unit1/bottleneck_v1/Relu/NEActivationLayerKernel #16: AVG=1.8680 ms SchedulerTimer/block1/unit1/bottleneck_v1/add/NEArithmeticAdditionKernel #15: AVG=4.1030 ms SchedulerTimer/block1/unit1/bottleneck_v1/add/NEFillBorderKernel #14: AVG=0.0030 ms SchedulerTimer/block1/unit1/bottleneck_v1/conv1/BatchNorm/NEBatchNormalizationLayerKernel #5: AVG=2.7400 ms SchedulerTimer/block1/unit1/bottleneck_v1/conv1/convolution/NEGEMMAssemblyWrapperKernel/sgemm_nativeA_pretransposeB_16x4 #4: AVG=5.4380 ms SchedulerTimer/block1/unit1/bottleneck_v1/conv2/BatchNorm/NEBatchNormalizationLayerKernel #11: AVG=9.8840 ms SchedulerTimer/block1/unit1/bottleneck_v1/conv2/BatchNorm/NEBatchNormalizationLayerKernel #9: AVG=2.8020 ms SchedulerTimer/block1/unit1/bottleneck_v1/conv2/convolution/NEGEMMAssemblyWrapperKernel/sgemm_nativeA_pretransposeB_16x4 #7: AVG=12.4590 msLet's take NEActivationLayerKernel as example, here where you should add you code: https://github.com/ARM-software/ComputeLibrary/blob/master/src/core/NEON/kernels/NEActivationLayerKernel.cpp#L572
Which should become:
void NEActivationLayerKernel::run(const Window &window, const ThreadInfo &info) { ARM_COMPUTE_UNUSED(info); ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); ARM_COMPUTE_ERROR_ON(_func == nullptr); (this->*_func)(window); _output->print(std::cout); }Hope this helps Thanks
Thank you very much for replying me. My target core is GPU, so it's OpenCL. I will try this method on CL layers. I just checked the GraphManager.cpp code. And got the GraphManager::exectue_graph(Graph &graph) function. It has a chain of layers called "it->second" which seems to hold tensors "input" and "output". It seems that Tensor and ITensor object is different.
You cannot dump all the tensors, however you can modify the graph to add an output tensor to see what the tensor contains. For example:
graph << Layer_0() << Layer_1() << Layer_2() << Layer_3() << OutputLayer(OutputAccessor());
If you want to check the output of Layer_1 just change the graph to:
graph << Layer_0() << Layer_1() << OutputLayer(OutputAccessor());
And print the content of the tensor in your OutputAccessor()
Hi, AnthonyARM Many thanks to telling me this. Can you give me some details about the OutputAccessor() parameters. According to the examples, they are related to the number of the items of the label. I've no idea how to set up them.
You need to create an Accessor class which inherits from ITensorAccessor, a bit like this (Note: I haven't actually tried to compile this code):
class PrintAccessor final : public graph::ITensorAccessor
{
public:
PrintAccessor()=default;
/** Allows instances to move constructed */
PrintAccessor(PrintAccessor &&) = default;
// Inherited methods overriden:
bool access_tensor(ITensor &tensor) override
{
tensor.print(std::cout);
return true;
}
};