예제 #1
0
def save_model(model: Model,
               path: str,
               include_optimizer: bool = False,
               meta: Optional[Dict[str, object]] = None):
    if not meta:
        meta = {}
    meta["include_optimizer"] = include_optimizer

    os.makedirs(path + "/assets", exist_ok=True)
    with open(f"{path}/assets/saved_model.json", "w") as f:
        json.dump(json.loads(model.to_json()), f, indent=2)
    with open(f"{path}/meta.json", "w") as f:
        json.dump(meta, f, indent=2)

    model.save(path, include_optimizer=include_optimizer)
예제 #2
0
def writeCSV2(variator: Variator, model: Model, counter=[0, 0]):
    history = variator.histories[-1]
    score = model.evaluate(tX, tY, verbose=0)

    acc = history.history['acc'][-1]
    val_acc = history.history['val_acc'][-1]
    print("counter: " + str(counter[1]))
    if score[1] > counter[1]:
        counter[1] = score[1]
        model_json = model.to_json()
        with open("Models/JSON/modelEvCluster_Architecure.json",
                  "w") as json_file:
            json_file.write(model_json)
        # serialize weights to HDF5
        model.save("Models/Weights/bestEvModelCluster.hd5")
    with open("Logs/modelStats.csv", "a") as f:
        if counter[0] == 0:
            counter[0] += 1
            f.write("Model,acc,val_acc,test_acc\n")
        f.write(variator.currentParameters['modelName'] + "," + str(acc) +
                "," + str(val_acc) + "," + str(score[1]))
        f.write("\n")
예제 #3
0
def save_model_json(model: Model, log_dir):
    filename = "{0}_config.json".format(model.name)
    filename = os.path.join(log_dir, filename)
    with open(filename, "w") as file:
        file.write(model.to_json())