16#include <nlohmann/json.hpp>
18#include "trg/cdc/dataobjects/CDCTriggerHoughMLP.h"
23int main(
int argc,
const char* argv[])
26 std::cout <<
"Program requires the following 3 arguments:\n"
27 <<
" 1: json weights\n"
28 <<
" 2: configuration file\n"
29 <<
" 3: root output file name\n";
32 const std::string jsonWeights = argv[1];
33 const std::string configFile = argv[2];
34 const std::string outputFile = argv[3];
38 std::ifstream netfile(jsonWeights, std::ifstream::binary);
39 nlohmann::json network;
42 std::vector<float> floatWeights;
43 const size_t nLayers = neuroParameters3DH.nHidden.size();
44 const size_t layerIndices = (nLayers + 1) * 2;
45 for (
size_t layerIdx = 0; layerIdx < layerIndices; layerIdx += 2) {
47 const std::string layerWeightName =
"model." + std::to_string(layerIdx) +
".weight";
48 const std::string layerBiasName =
"model." + std::to_string(layerIdx) +
".bias";
49 for (
const auto& node : network[layerWeightName]) {
50 for (
float weight : node) {
51 floatWeights.push_back(weight);
53 float bias = network[layerBiasName][nodeIdx];
54 floatWeights.push_back(bias);
58 mlp.setFloatWeights(floatWeights);
60 std::cout <<
"Writing " << floatWeights.size() <<
" weights\n";
61 mlp.saveMLPToFile(outputFile,
"MLP");
63 float minFloatWeight = *std::min_element(floatWeights.begin(), floatWeights.end());
64 float maxFloatWeight = *std::max_element(floatWeights.begin(), floatWeights.end());
65 std::cout <<
"Max weight: " << maxFloatWeight <<
", Min weight: " << minFloatWeight << std::endl;
Abstract base class for different kinds of events.