2021-08-21 07:40:12 +00:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
import sqlite3
|
2023-03-24 22:29:03 +00:00
|
|
|
|
2021-08-21 07:40:12 +00:00
|
|
|
import onnx
|
|
|
|
|
from onnx import numpy_helper
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
connection = sqlite3.connect("<path-to-sqldb-from-tracing>", detect_types=sqlite3.PARSE_DECLTYPES)
|
|
|
|
|
|
2021-08-21 07:40:12 +00:00
|
|
|
|
|
|
|
|
def convert_tensor_proto_to_numpy_array(blob):
|
|
|
|
|
tensor_proto = onnx.TensorProto()
|
|
|
|
|
tensor_proto.ParseFromString(blob)
|
|
|
|
|
return numpy_helper.to_array(tensor_proto)
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
|
2021-08-21 07:40:12 +00:00
|
|
|
sqlite3.register_converter("TensorProto", convert_tensor_proto_to_numpy_array)
|
|
|
|
|
|
2023-03-24 22:29:03 +00:00
|
|
|
for step, name, value, _device, _producer, consumers in connection.execute(
|
2022-04-26 16:35:16 +00:00
|
|
|
"Select Step, Name, Value, DeviceType, TracedProducer, TracedConsumers from Tensors"
|
|
|
|
|
):
|
2021-08-21 07:40:12 +00:00
|
|
|
print(step, name, value.shape, consumers)
|