Issue when trying to parse json
mikegazzaruso opened this issue · 3 comments
Hi, parser gives me the following error:
std::ifstream jsonStream("adaptivo_ac_weights.json", std::ifstream::binary);
auto model = RTNeural::json_parser::parseJson(jsonStream); <----- breaks here
JUCE v7.0.5
libc++abi: terminating with uncaught exception of type nlohmann::json_v3_11_1::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
terminating with uncaught exception of type nlohmann::json_v3_11_1::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
(lldb)
My model json was created with your script, it's a common dense / relu / softmax model created with tensorflow and keras.
It says error on line 1, I will past first lines:
{
"in_shape": [
null,
40
],
"layers": [
{
"type": "dense",
"activation": "",
"shape": [
null,
100
],
"weights": [
[
[
-0.04106162488460541,
-0.008081752806901932,
0.05740608274936676,
0.0283
---- continue ----
Solved, ifstream gives no warning when file is not found, I erroneusly mispelled a character.
Using if(myFile.fail) I was able to properly catch that.
Sorry and thanks for your marvellous work.
Ah yes, that particular exception usually means that the JSON parser was passed an empty stream.
In practice, if you need to be able to dynamically load models at run-time, it's possible to wrap the model loading process in a try/catch block, to avoid a crash in case an invalid or non-existent file is passed in.
Thanks for the comment! Yes you are right. I'm experimenting other problems but I opened a separate issue, thanks for your help