Ejemplo n.º 1
0
def MCU_output():
    '''
    输出混淆矩阵
    :return:
    '''
    dir = MCU_dir
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    model.LBCNN('Adam')
    path = dir + 'LBCNN_model.h5'
    model.run_model(path)
Ejemplo n.º 2
0
def load_img():
    '''
    载入图片,只需要做一次
    :return:
    '''
    # MCU
    dir = MCU_dir
    model = My_CNN(64, 17, 1000, dir, channel=1)  # 初始化模型
    #img_dir = ''  # 图片保存路径
    model.read_img(img_dir)  # 初次使用需要载入图片
Ejemplo n.º 3
0
def Lenet_MCU():
    '''
            :return:
    '''
    dir = MCU_dir  # 数据集保存路径,之后就可以不用重新载入图片
    model = My_CNN(64, 17, 1000, dir, channel=1)  # 初始化模型
    model.LeNet_5('Adam', lr=1e-3)
    hist_path = dir + 'LeNet_'
    path = dir + 'LeNet_model.h5'
    model.train_model(1000, 512, model_path=path, hist_path=hist_path, early_save=True, patience=10)
Ejemplo n.º 4
0
def LBCNN_MFPT():
    '''
    使用LBCNN完整地训练数据集,保存最优结果
    :return:
    '''
    dir = MFPT_dir
    model = My_CNN(40, 16, 1000, dir)  # 初始化模型
    model.LBCNN('Adam')
    hist_path = dir + 'LBCNN_'
    path = dir + 'LBCNN_model.h5'
    model.train_model(1000,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=True)
Ejemplo n.º 5
0
def Lenet_MFPT():
    '''
        使用Lenet完整地训练数据集,保存最优结果
        :return:
    '''
    dir = MFPT_dir
    model = My_CNN(40, 16, 1000, dir)  # 初始化模型
    model.LeNet_5('Adam', lr=1e-3)
    hist_path = dir + 'LeNet_'
    path = dir + 'LeNet_model.h5'
    model.train_model(1000,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=True)
Ejemplo n.º 6
0
def Lenet_MCU():
    '''
            使用Lenet完整地训练数据集,保存最优结果
            :return:
    '''
    dir = MCU_dir  # 数据集保存路径
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    model.LeNet_5('Adam', lr=1e-4)
    hist_path = dir + 'LeNet_'
    path = dir + 'LeNet_model.h5'
    model.train_model(1000,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=True,
                      patience=100)
Ejemplo n.º 7
0
def LBCNN_MCU():
    '''
        使用LBCNN完整地训练数据集,保存最优结果
        :return:
    '''
    dir = MCU_dir
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    model.LBCNN('Adam', lr=1e-4)
    hist_path = dir + 'LBCNN_'
    path = dir + 'LBCNN_model.h5'
    model.train_model(1000,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=True,
                      patience=100)
Ejemplo n.º 8
0
def load_img():
    '''
    载入图片,只需要做一次
    :return:
    '''
    # MFPT
    dir = MFPT_dir
    model = My_CNN(40, 16, 1000, dir)  # 初始化模型
    img_dir = 'imgs\\'  # 图片保存路径
    model.read_img(img_dir)

    # MCU
    dir = MCU_dir
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    img_dir = 'F:\毕业设计\MCU\时频图\imgs\\'  # 图片保存路径
    model.read_img(img_dir)
Ejemplo n.º 9
0
def MCU_race():
    '''
        比较LBCNN和Lenet在数据集中的表现
        :return:
    '''
    dir = MCU_dir  # 数据集保存路径
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    model.LeNet_5('Adam', lr=1e-4)
    hist_path = dir + 'RLeNet_'
    path = dir + 'RLeNet_model.h5'
    model.train_model(30,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=False)
    model.LBCNN('Adam', lr=1e-4)
    hist_path = dir + 'RLBCNN_'
    path = dir + 'RLBCNN_model.h5'
    model.train_model(30,
                      512,
                      model_path=path,
                      hist_path=hist_path,
                      early_save=False)
Ejemplo n.º 10
0
def plot():
    '''
    画图
    :return:
    '''
    dir = MCU_dir  # 数据集保存路径
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    hist_path = dir + 'Adam_'
    history = model.load_data(hist_path, 'history')
    plt.figure()
    plt.plot(history['acc'])
    hist_path = dir + 'SGD_'
    history = model.load_data(hist_path, 'history')
    plt.plot(history['acc'])
    hist_path = dir + 'Adadelta_'
    history = model.load_data(hist_path, 'history')
    plt.plot(history['acc'])
    hist_path = dir + 'Adagrad_'
    history = model.load_data(hist_path, 'history')
    plt.plot(history['acc'])
    plt.legend(['Adam', 'SGD', 'Adadelta', 'Adagrad'])
    plt.show()
Ejemplo n.º 11
0
def OP_MCU():
    '''
        对数据集,比较不同优化器下的LBCNN网络的效果
        :return: 模型会自动保存为H5格式,训练历史数据会自动保存为二进制格式
    '''
    dir = MCU_dir
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型

    # Adam
    model.LBCNN('Adam')
    hist_path = dir + 'Adam_'
    path = dir + 'Adam_model.h5'
    model.train_model(30, 512, model_path=path, hist_path=hist_path)

    # SGD
    model.LBCNN('SGD')
    hist_path = dir + 'SGD_'
    path = dir + 'SGD_model.h5'
    model.train_model(30, 512, model_path=path, hist_path=hist_path)

    # Adagrad
    model.LBCNN('Adagrad')
    hist_path = dir + 'Adagrad_'
    path = dir + 'Adagrad_model.h5'
    model.train_model(30, 512, model_path=path, hist_path=hist_path)

    # Adadelta
    model.LBCNN('Adadelta')
    hist_path = dir + 'Adadelta_'
    path = dir + 'Adadelta_model.h5'
    model.train_model(30, 512, model_path=path, hist_path=hist_path)
Ejemplo n.º 12
0
def write():
    # 将二进制文件写为csv格式,方便之后用MATLAB画图
    # MFPT
    dir = MFPT_dir  # 数据集保存路径
    model = My_CNN(40, 16, 1000, dir)  # 初始化模型

    # LBCNN+Adam
    hist_path = dir + 'Adam_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adam.csv'
    csv_trans(history, filename)

    # LBCNN+SGD
    hist_path = dir + 'SGD_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'SGD.csv'
    csv_trans(history, filename)

    # LBCNN+Adagrad
    hist_path = dir + 'Adagrad_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adagrad.csv'
    csv_trans(history, filename)

    # LBCNN+Adadelta
    hist_path = dir + 'Adadelta_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adadelta.csv'
    csv_trans(history, filename)

    #LBCNN
    hist_path = dir + 'LBCNN_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'LBCNN.csv'
    csv_trans(history, filename)

    # Lenet
    hist_path = dir + 'Lenet_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Lenet.csv'
    csv_trans(history, filename)

    # race
    hist_path = dir + 'RLenet_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'RLenet.csv'
    csv_trans(history, filename)
    hist_path = dir + 'RLBCNN_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'RLBCNN.csv'
    csv_trans(history, filename)

    # MCU
    dir = MCU_dir  # 数据集保存路径
    model = My_CNN(40, 17, 1000, dir)  # 初始化模型
    # LBCNN+Adam
    hist_path = dir + 'Adam_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adam.csv'
    csv_trans(history, filename)
    # LBCNN+SGD
    hist_path = dir + 'SGD_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'SGD.csv'
    csv_trans(history, filename)
    # LBCNN+Adagrad
    hist_path = dir + 'Adagrad_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adagrad.csv'
    csv_trans(history, filename)
    # LBCNN+Adadelta
    hist_path = dir + 'Adadelta_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Adadelta.csv'
    csv_trans(history, filename)
    # LBCNN
    hist_path = dir + 'LBCNN_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'LBCNN.csv'
    csv_trans(history, filename)
    # Lenet
    hist_path = dir + 'Lenet_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'Lenet.csv'
    csv_trans(history, filename)
    # race
    hist_path = dir + 'RLenet_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'RLenet.csv'
    csv_trans(history, filename)
    hist_path = dir + 'RLBCNN_'
    history = model.load_data(hist_path, 'history')
    filename = dir + 'RLBCNN.csv'
    csv_trans(history, filename)