1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "Debug.hpp"
#include <Half.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <algorithm>
#include <iostream>
namespace armnn
{
template <typename T>
void Debug(const TensorInfo& inputInfo,
const T* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex)
{
const unsigned int numDims = inputInfo.GetNumDimensions();
const unsigned int numElements = inputInfo.GetNumElements();
const TensorShape& inputShape = inputInfo.GetShape();
std::vector<unsigned int> strides(numDims, 0);
strides[numDims - 1] = inputShape[numDims - 1];
for (unsigned int i = 2; i <= numDims; i++)
{
strides[numDims - i] = strides[numDims - i + 1] * inputShape[numDims - i];
}
std::cout << "{ ";
std::cout << "\"layerGuid\": " << guid << ", ";
std::cout << "\"layerName\": \"" << layerName << "\", ";
std::cout << "\"outputSlot\": " << slotIndex << ", ";
std::cout << "\"shape\": ";
std::cout << "[";
for (unsigned int i = 0; i < numDims; i++)
{
std::cout << inputShape[i];
if (i != numDims - 1)
{
std::cout << ", ";
}
}
std::cout << "], ";
std::cout << "\"min\": "
<< boost::numeric_cast<float>(*std::min_element(inputData, inputData + numElements)) << ", ";
std::cout << "\"max\": "
<< boost::numeric_cast<float>(*std::max_element(inputData, inputData + numElements)) << ", ";
std::cout << "\"data\": ";
for (unsigned int i = 0; i < numElements; i++)
{
for (unsigned int j = 0; j < numDims; j++)
{
if (i % strides[j] == 0)
{
std::cout << "[" ;
}
}
std::cout << boost::numeric_cast<float>(inputData[i]);
for (unsigned int j = 0; j < numDims; j++)
{
if ((i+1) % strides[j] == 0)
{
std::cout << "]" ;
}
}
if (i != numElements - 1)
{
std::cout << ", ";
}
}
std::cout << " }" << std::endl;
}
template void Debug<Half>(const TensorInfo& inputInfo,
const Half* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
template void Debug<float>(const TensorInfo& inputInfo,
const float* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
template void Debug<uint8_t>(const TensorInfo& inputInfo,
const uint8_t* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
template void Debug<int8_t>(const TensorInfo& inputInfo,
const int8_t* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
template void Debug<int16_t>(const TensorInfo& inputInfo,
const int16_t* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
template void Debug<int32_t>(const TensorInfo& inputInfo,
const int32_t* inputData,
LayerGuid guid,
const std::string& layerName,
unsigned int slotIndex);
} // namespace armnn
|