# Path: tupa/model_util.py
# def load_json(filename):
#     """
#     Load dictionary from JSON file
#     :param filename: file to read from
#     """
#     print("Loading from '%s'." % filename)
#     with open(filename, "r") as h:
#         d = json.load(h)
#     return d
# 
# def save_json(filename, d):
#     """
#     Save dictionary to JSON file
#     :param filename: file to write to
#     :param d: dictionary to save
#     """
#     remove_existing(filename)
#     print("Saving to '%s'." % filename)
#     with open(filename, "w") as h:
#         json.dump(d, h, default=jsonify)


from collections import OrderedDict
from ..model_util import load_json, save_json

    def load(self, filename):
        """
        Load all parameters from file
        """
        d = self.load_file(filename, clear=True)
        model_type = d.get("type")
        assert model_type is None or model_type == self.model_type, "Model type does not match: %s" % model_type
        self.labels_t = OrderedDict((a, l["labels"]) for a, l in sorted(d["axes"].items(), key=lambda x: x[1]["index"]))
        self.is_frozen = d["is_frozen"]
        self.config.args.learning_rate = self.learning_rate = d["learning_rate"]
        self.config.args.learning_rate_decay = self.learning_rate_decay = d["learning_rate_decay"]
        self.updates = d.get("updates", 0)
        self.epoch = d.get("epoch", 0)
        self.best_score = d.get("best_score", 0)
        self.load_model(filename, d)

    def load_model(self, filename, d):
        pass

    @classmethod
    def get_property(cls, filename, prop):
        return cls.load_file(filename).get(prop, None)

    LOADED = {}  # Cache for loaded JSON files

    @classmethod
    def load_file(cls, filename, clear=False):
        d = cls.LOADED.get(filename)
        if d is None:

# Path: tupa/model_util.py
# def load_json(filename):
#     """
#     Load dictionary from JSON file
#     :param filename: file to read from
#     """
#     print("Loading from '%s'." % filename)
#     with open(filename, "r") as h:
#         d = json.load(h)
#     return d
# 
# def save_json(filename, d):
#     """
#     Save dictionary to JSON file
#     :param filename: file to write to
#     :param d: dictionary to save
#     """
#     remove_existing(filename)
#     print("Saving to '%s'." % filename)
#     with open(filename, "w") as h:
#         json.dump(d, h, default=jsonify)


# Path: tupa/classifiers/classifier.py
from collections import OrderedDict
from ..model_util import load_json, save_json


    def load(self, filename):
        """
        Load all parameters from file
        """
        d = self.load_file(filename, clear=True)
        model_type = d.get("type")
        assert model_type is None or model_type == self.model_type, "Model type does not match: %s" % model_type
        self.labels_t = OrderedDict((a, l["labels"]) for a, l in sorted(d["axes"].items(), key=lambda x: x[1]["index"]))
        self.is_frozen = d["is_frozen"]
        self.config.args.learning_rate = self.learning_rate = d["learning_rate"]
        self.config.args.learning_rate_decay = self.learning_rate_decay = d["learning_rate_decay"]
        self.updates = d.get("updates", 0)
        self.epoch = d.get("epoch", 0)
        self.best_score = d.get("best_score", 0)
        self.load_model(filename, d)

    def load_model(self, filename, d):
        pass

    @classmethod
    def get_property(cls, filename, prop):
        return cls.load_file(filename).get(prop, None)

    LOADED = {}  # Cache for loaded JSON files

    @classmethod
    def load_file(cls, filename, clear=False):
        d = cls.LOADED.get(filename)
        if d is None:

            d = load_json(filename + ".json")