question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import/Export of JSON for model is not working

See original GitHub issue

What is wrong?

Export/Import functionality of the library is not working, the JSON is not in the correct format to be considered JSON.

Where does it happen?

Windows 10 node version 8

How do we replicate the issue?

`const brain = require('brain.js);

var net = new brain.recurrent.RNN();

net.train([{input: [0, 0], output: [0]}, {input: [0, 1], output: [1]}, {input: [1, 0], output: [1]}, {input: [1, 1], output: [0]}]);

var output = net.run([0, 0]); // [0] output = net.run([0, 1]); // [1] output = net.run([1, 0]); // [1] output = net.run([1, 1]); // [0]

console.log(net.toJSON()) // JSON is in incorrect format, am i missing something? `

How important is this (1-5)?

4 - love this library but can’t use it for Production use cases until i can export/import

Expected behavior (i.e. solution)

JSON is exported in valid format

Other Comments

N/A - love this Library tho

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
robertleeplummerjrcommented, Mar 28, 2018

net.fromJSON(JSON.parse("input-output-trainedmodel.json"));

May be the problem. JSON.parse reads a string in, you want to pass the string of the source of input-output-trainedmodel.json

Is there a trick to reading it in from an external source?

Yea, just use

const fs = require('fs');

and then later:

console.log(json) // JSON is in different format
fs.writeFileSync("input-output-trainedmodel.json", JSON.stringify(json));
var net = new brain.recurrent.RNN();
net.fromJSON(
  JSON.parse(
    fs.readFileSync("input-output-trainedmodel.json").toString()
  )
);
1reaction
jusso-devcommented, Mar 28, 2018

Yes you are correct. Thanks so much! Sorry, I knew that the reading in was a javascript issue not a brain js issue I just didn’t know how to achieve it. I’m a .NET developer by trade so little rusty with the ol’ JS side of things.

Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make import-export save JSONField not as string
I tried to create a Field with the JSONWidget widget, but doesn't work. models.py @receiver(post_save, sender=Governorate) def ...
Read more >
Import/export from json - Self Hosted Retool
I used to export an app as a json file on my dev environment and then import json on production environment, which works...
Read more >
importing json OR csv with blank id column still results in ...
Same problem here. The resource and admin classes are setup according to the documentation, and export is working fine.
Read more >
Import Export JSON Model - PlayCanvas Forum
Hi, I'm trying to copy JSON Models from Project A to Project B, ... I upload json model files, editor recognizes as JSON...
Read more >
Refactor Import/Export JSON load/dumping - Issues - GitLab
Currently, we load the JSON in batches, freeing objects from memory per batch and committing to the DB after each batch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found