Skip to content
Snippets Groups Projects
Commit 0b234462 authored by Enric Tejedor Saavedra's avatar Enric Tejedor Saavedra
Browse files

Ensure JSON is sorted when dumping it in the notebook.

In Python2, the dumps function of the json module always returns the
same JSON string for a given Python dictionary across different runs.
In Python3, the returned JSON changes across runs, in particular the
order in which dictionary keys are shown, which complicates the
notebook tests of the interactive neural networks. Only with a sorted
JSON we can compare the newly generated notebook with a reference notebook.
parent 33332384
No related branches found
No related tags found
No related merge requests found
...@@ -152,7 +152,7 @@ def GetDeepNetworkOld(xml_file, returnObj=False): ...@@ -152,7 +152,7 @@ def GetDeepNetworkOld(xml_file, returnObj=False):
network["synapses"] = synapses network["synapses"] = synapses
if returnObj: if returnObj:
return network return network
return json.dumps(network) return json.dumps(network, sort_keys = True)
## Reads deep neural network weights from file and returns it in JSON format. ## Reads deep neural network weights from file and returns it in JSON format.
# @param xml_file path to DNN weight file # @param xml_file path to DNN weight file
...@@ -196,7 +196,7 @@ def GetDeepNetwork(xml_file, returnObj=False): ...@@ -196,7 +196,7 @@ def GetDeepNetwork(xml_file, returnObj=False):
network["layers"] = layers network["layers"] = layers
if returnObj: if returnObj:
return network return network
return json.dumps(network) return json.dumps(network, sort_keys = True)
## Reads neural network weights from file and returns it in JSON format ## Reads neural network weights from file and returns it in JSON format
# @param xml_file path to weight file # @param xml_file path to weight file
...@@ -231,7 +231,7 @@ def GetNetwork(xml_file): ...@@ -231,7 +231,7 @@ def GetNetwork(xml_file):
neurons[label]["weights"] = weights neurons[label]["weights"] = weights
net["layer_"+str(layer.get('Index'))] = neurons net["layer_"+str(layer.get('Index'))] = neurons
network["layout"] = net network["layout"] = net
return json.dumps(network) return json.dumps(network, sort_keys = True)
## Helper class for reading decision tree from XML file ## Helper class for reading decision tree from XML file
class TreeReader: class TreeReader:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment