示例#1
0
def findPreviouslyTrainedModel(model_name):

    model_path = models_path(model_name + zipped_pickle_extension)

    if os.path.isfile(model_path):
        return model_name, 0

    epoch_string = "_e_"

    base_name, number_of_epochs = model_name.split(epoch_string)
    number_of_epochs = int(number_of_epochs)

    previous_model_names = [
        m.replace(zipped_pickle_extension, "")
        for m in os.listdir(models_path()) if base_name in m
    ]
    previous_numbers_of_epochs = [
        int(m.split(epoch_string)[-1]) for m in previous_model_names
    ]
    previous_numbers_of_epochs = [
        e for e in previous_numbers_of_epochs if e <= number_of_epochs
    ]
    previous_model_names = previous_model_names[:len(previous_numbers_of_epochs
                                                     )]

    if len(previous_model_names) == 0:
        return None, number_of_epochs

    previous_model_epochs_trained, previous_model_name = \
        sorted(zip(previous_numbers_of_epochs, previous_model_names))[-1]

    epochs_still_to_train = number_of_epochs - previous_model_epochs_trained

    return previous_model_name, epochs_still_to_train
示例#2
0
def saveModel(model, model_name):

    model_path = models_path(model_name + zipped_pickle_extension)

    print("Saving model parameters and metadata.")

    with gzip.open(model_path, "wb") as model_file:
        pickle.dump(model, model_file)

    print("Model parameters and metadata saved in {}.".format(model_path))
示例#3
0
def loadModel(model_name):

    epoch = model_name.split("_e_")[-1]

    model_path = models_path(model_name + zipped_pickle_extension)

    print("Loading model parameters for epoch {} and metadata.".format(epoch))

    with gzip.open(model_path, "rb") as model_file:
        model = pickle.load(model_file)

    print("Model parameters and metadata loaded.")

    return model
示例#4
0
def modelTrained(model_name):

    model_path = models_path(model_name + zipped_pickle_extension)

    return os.path.isfile(model_path)