Exemple #1
0
@理解:
"""
import pickle

from src.base.config import save_model, model_file_path, model_file_prefix
from src.base.tools import beep_end, show_title


# ----------------------------------------------------------------------
def main():
    pass


if __name__ == '__main__':
    main()
    beep_end()


def save_model_m0(model):
    if save_model:
        show_title("保存网络模型")
        file_name = model_file_path + model_file_prefix + 'm0.h5'
        print("保存原始模型:{} →".format(file_name), end='')
        model.save(file_name)
        print("模型保存成功。")


def save_model_m1(history, model):
    if save_model:
        show_title("保存网络模型")
        file_name = model_file_path + model_file_prefix + 'm1.bin'
from src.base.tools import beep_end, show_title


# ----------------------------------------------------------------------
def main():
    show_title("数据清洗开始...")
    from src.data.export_data import export_base_data
    x_data, y_data = export_base_data()
    # from src.data.load_data import load_base_data
    # x_data, y_data = load_base_data()

    from src.data.export_data import export_train_test_data
    x_train, y_train = export_train_test_data(x_data, y_data)
    # from src.data.load_data import load_train_data
    # x_train, y_train = load_train_data()
    # export_train_balance(x_train, y_train)

    from src.data.export_data import export_val_data
    x_train_val, y_train_val = export_val_data(x_train, y_train)
    # from src.data.load_data import load_val_data
    # x_train_val, y_train_val = load_val_data()
    # export_val_balance(x_train_val, y_train_val)

    show_title("数据清洗完成!")


# ----------------------------------------------------------------------
if __name__ == '__main__':
    main()
    beep_end()  # 运行结束的提醒
    from src.model.save_model import save_model_m1
    save_model_m1(history, model)

    from src.data.load_data import load_test_data
    show_title("加载与填充测试数据集")
    x_test, y_test = load_test_data()
    x_test = single_data_reshape(day_feature_idx, x_test, y_test.shape[0])
    results = model.evaluate(x_test, y_test, verbose=0)
    predictions = model.predict(x_test).squeeze()
    show_result(results, predictions, y_test)

    show_title("没有验证集训练网络模型,训练次数减半")
    from src.data.load_data import load_train_data
    show_title("加载与填充{}".format(train_data_type))
    x_train, y_train = load_train_data()
    x_train = single_data_reshape(day_feature_idx, x_train, y_train.shape[0])

    history = model.fit(x_train, y_train, epochs=epochs // 2, batch_size=batch_size, verbose=2)
    from src.model.save_model import save_model_m2
    save_model_m2(history, model)

    results = model.evaluate(x_test, y_test, verbose=0)
    predictions = model.predict(x_test).squeeze()
    show_result(results, predictions, y_test)
    pass


if __name__ == '__main__':
    # 运行结束的提醒
    tools.beep_end()