Skip to content

Commit

Permalink
[circle-inspect] Introduce new circleInspect for tensor shape (#14092)
Browse files Browse the repository at this point in the history
This commit intorduces new circleInspect for tensor shape.

ONE-DCO-1.0-Signed-off-by: JuYoung Lee [email protected]
  • Loading branch information
icodo98 authored Sep 26, 2024
1 parent 69d29b7 commit a0c0391
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/circle-inspect/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int entry(int argc, char **argv)
arser.add_argument("--constants").nargs(0).help("Dump constant tensors name");
arser.add_argument("--op_version").nargs(0).help("Dump versions of the operators in circle file");
arser.add_argument("--tensor_dtype").nargs(0).help("Dump dtype of tensors");
arser.add_argument("--tensor_shape").nargs(0).help("Dump shape of tensors");
arser.add_argument("circle").help("Circle file to inspect");

try
Expand All @@ -51,7 +52,7 @@ int entry(int argc, char **argv)
}

if (!arser["--operators"] && !arser["--conv2d_weight"] && !arser["--op_version"] &&
!arser["--tensor_dtype"] && !arser["--constants"])
!arser["--tensor_dtype"] && !arser["--constants"] && !arser["--tensor_shape"])
{
std::cout << "At least one option must be specified" << std::endl;
std::cout << arser;
Expand All @@ -70,6 +71,8 @@ int entry(int argc, char **argv)
dumps.push_back(std::make_unique<circleinspect::DumpTensorDType>());
if (arser["--constants"])
dumps.push_back(std::make_unique<circleinspect::DumpConstants>());
if (arser["--tensor_shape"])
dumps.push_back(std::make_unique<circleinspect::DumpTensorShape>());

std::string model_file = arser.get<std::string>("circle");

Expand Down
35 changes: 35 additions & 0 deletions compiler/circle-inspect/src/Dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,38 @@ void DumpConstants::run(std::ostream &os, const circle::Model *model, const std:
}

} // namespace circleinspect

namespace circleinspect
{

void DumpTensorShape::run(std::ostream &os, const circle::Model *model,
const std::vector<char> *data)
{
mio::circle::Reader reader(model, data);

const uint32_t subgraph_size = reader.num_subgraph();

for (uint32_t g = 0; g < subgraph_size; g++)
{
reader.select_subgraph(g);
auto tensors = reader.tensors();

for (uint32_t i = 0; i < tensors->size(); ++i)
{
const auto tensor = tensors->Get(i);
auto shape = tensor->shape_signature() ? tensor->shape_signature() : tensor->shape();
os << reader.tensor_name(tensor) << " [";
for (uint32_t i = 0; i < shape->size(); i++)
{
os << shape->Get(i);
if (i != shape->size() - 1)
{
os << ",";
}
}
os << "]" << std::endl;
}
}
}

} // namespace circleinspect
9 changes: 9 additions & 0 deletions compiler/circle-inspect/src/Dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ class DumpConstants final : public DumpInterface
void run(std::ostream &os, const circle::Model *model, const std::vector<char> *data);
};

class DumpTensorShape final : public DumpInterface
{
public:
DumpTensorShape() = default;

public:
void run(std::ostream &os, const circle::Model *model, const std::vector<char> *data);
};

} // namespace circleinspect

#endif // __DUMP_H__

0 comments on commit a0c0391

Please sign in to comment.