printSafetensorsStructure function
void
printSafetensorsStructure(
)
Implementation
void printSafetensorsStructure(String filePath) {
File file = File(filePath);
Uint8List rawBytes = file.readAsBytesSync();
ByteData byteData = ByteData.sublistView(rawBytes);
int headerSize = byteData.getUint64(0, Endian.little);
Uint8List headerBytes = Uint8List(headerSize);
for (int i = 0; i < headerSize; i = i + 1) {
headerBytes[i] = rawBytes[8 + i];
}
String headerString = utf8.decode(headerBytes);
Map<String, dynamic> header = json.decode(headerString);
List<String> keys = header.keys.toList();
for (int i = 0; i < keys.length; i = i + 1) {
String key = keys[i];
if (key == '__metadata__') {
continue;
}
Map<String, dynamic> layerInfo = header[key];
List<dynamic> shape = layerInfo['shape'];
String dtype = layerInfo['dtype'];
Logger.log(key);
Logger.log("$shape");
Logger.log(dtype);
}
}