diff --git a/src/model/model.cpp b/src/model/model.cpp index c18142a..07c721d 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -43,6 +43,7 @@ float* Model::predict(const float* input) { float* d_input = inputLayer->forward(input); for (auto& layer : layers) { + std::cout << layer << std::endl; d_input = layer->forward(d_input); } diff --git a/test/resources/model.bin b/test/resources/model.bin index d796950..d58f27a 100644 Binary files a/test/resources/model.bin and b/test/resources/model.bin differ diff --git a/tools/utils.py b/tools/utils.py index 73dbb2c..6c4f689 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -1,6 +1,8 @@ import torch import struct +import numpy as np + def print_cpp_vector(vector, name="expected"): print("std::vector " + name + " = {", end="") @@ -16,27 +18,25 @@ def export_model_weights(model: torch.nn.Module, filename): header = "" offset = 0 - + tensor_data = b"" for name, param in model.named_parameters(): if 'weight' not in name and 'bias' not in name: continue - tensor_values = param.flatten().tolist() - tensor_bytes = struct.pack('f' * len(tensor_values), *tensor_values) - + tensor_bytes = param.type(torch.float32).detach().numpy().tobytes() tensor_size = param.numel() - header += f"{name},{tensor_size},{offset}\n" - + header += f"{name},{tensor_size},{offset}\n" offset += len(tensor_bytes) - f.write(tensor_bytes) + tensor_data += tensor_bytes f.seek(0) - f.write(struct.pack('q', len(header))) + f.write(struct.pack('q', len(header))) f.write(header.encode('utf-8')) + f.write(tensor_data) def print_model_parameters(model: torch.nn.Module): for name, param in model.named_parameters(): - print(name, param.numel()) \ No newline at end of file + print(name, param.numel())