Pytorch环境下基于Transformer的滚动轴承故障诊断

news2024/11/29 18:24:58

关于python的集成环境,我一般Anaconda 和 winpython 都用,windows下主要用Winpython,IDE为spyder(类MATLAB界面)。

 

winpython脱胎于pythonxy,面向科学计算兼顾数据分析与挖掘;Anaconda主要面向数据分析与挖掘方面,在大数据处理方面有自己特色的一些包;winpython强调便携性,被做成绿色软件,不写入注册表,安装其实就是解压到某个文件夹,移动文件夹甚至放到U盘里在其他电脑上也能用;Anaconda则算是传统的软件模式。winpython是由个人维护;Anaconda由数据分析服务公司维护,意味着Winpython在很多方面都从简,而Anaconda会提供一些人性化设置。Winpython 只能在windows上用,Anaconda则有linux的版本。

抛开软件包的差异,我个人也推荐初学者用winpython,正因为其简单,问题也少点,由于便携性的特点系统坏了,重装后也能直接用。

请直接安装、使用winPython:WinPython download因为很多模块以及集成的模块

可以选择版本,不一定要用最新版本,否则可能出现不兼容问题。

下载、解压后如下

打开spyder就可以用了,里面自带pytorch.

开始步入正题,进行基于Transformer的滚动轴承故障诊断,Transformer模型就不多说了,很多论文都有介绍。

用的数据集是简单的西储大学数据集

 为了便于处理,转换为csv文件类型

 

加载相关模块

import torch
import torch.nn as nn
import torch.optim as optim
from model import DSCTransformer
from tqdm import tqdm
from data_set import MyDataset
from torch.utils.data import DataLoader

定于训练函数

def train(epochs=100):
    #定义参数
    N = 4 #编码器个数
    input_dim = 1024
    seq_len = 16 #句子长度
    d_model = 64 #词嵌入维度
    d_ff = 256 #全连接层维度
    head = 4 #注意力头数
    dropout = 0.1
    lr = 5E-5 #学习率
    batch_size = 32

    #加载数据
    train_path = r'data\train\train.csv'
    val_path = r'data\val\val.csv'
    train_dataset = MyDataset(train_path, 'fd')
    val_dataset = MyDataset(val_path, 'fd')
    train_loader = DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True, drop_last=True)
    val_loader = DataLoader(dataset=val_dataset, batch_size=batch_size, shuffle=True, drop_last=True)

    #定义模型
    model = DSCTransformer(input_dim=input_dim, num_classes=10, dim=d_model, depth=N,
                           heads=head, mlp_dim=d_ff, dim_head=d_model, emb_dropout=dropout, dropout=dropout)
    criterion = nn.CrossEntropyLoss()
    params = [p for p in model.parameters() if p.requires_grad]
    optimizer = optim.Adam(params, lr=lr)
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
    print("using {} device.".format(device))
    model.to(device)

    #训练
    for epoch in range(epochs):
        #train
        train_loss = []
        train_acc = []
        model.train()
        train_bar = tqdm(train_loader)
        for datas, labels in train_bar:
            optimizer.zero_grad()
            outputs = model(datas.float().to(device))
            loss = criterion(outputs, labels.type(torch.LongTensor).to(device))
            loss.backward()
            optimizer.step()

            # torch.argmax(dim=-1), 求每一行最大的列序号
            acc = (outputs.argmax(dim=-1) == labels.to(device)).float().mean()
            # Record the loss and accuracy
            train_loss.append(loss.item())
            train_acc.append(acc)
            train_bar.desc = "train epoch[{}/{}] loss:{:.3f}".format(epoch + 1, epochs, loss.item())

        #val
        model.eval()
        valid_loss = []
        valid_acc = []
        val_bar = tqdm(val_loader)
        for datas, labels in val_bar:
            with torch.no_grad():
                outputs = model(datas.float().to(device))
            loss = criterion(outputs, labels.type(torch.LongTensor).to(device))

            acc = (outputs.argmax(dim=-1) == labels.to(device)).float().mean()
            # Record the loss and accuracy
            valid_loss.append(loss.item())
            valid_acc.append(acc)
            val_bar.desc = "valid epoch[{}/{}]".format(epoch + 1, epochs)

        print(f"[{epoch + 1:02d}/{epochs:02d}] train loss = "
              f"{sum(train_loss) / len(train_loss):.5f}, train acc = {sum(train_acc) / len(train_acc):.5f}", end="  ")
        print(f"valid loss = {sum(valid_loss) / len(valid_loss):.5f}, valid acc = {sum(valid_acc) / len(valid_acc):.5f}")

关于Transformer模型,部分截图如下

训练

if __name__ == '__main__':
    train()

结果如下

using cpu device.

train epoch[1/100] loss:2.256: 100%|██████████| 37/37 [00:03<00:00, 12.25it/s]

valid epoch[1/100]: 100%|██████████| 12/12 [00:00<00:00, 22.20it/s]

[01/100] train loss = 2.34002, train acc = 0.15456 valid loss = 2.20410, valid acc = 0.22917

train epoch[2/100] loss:2.124: 100%|██████████| 37/37 [00:02<00:00, 17.70it/s]

valid epoch[2/100]: 100%|██████████| 12/12 [00:00<00:00, 72.03it/s]

[02/100] train loss = 2.17655, train acc = 0.26943 valid loss = 2.02880, valid acc = 0.36198

train epoch[3/100] loss:2.024: 100%|██████████| 37/37 [00:01<00:00, 19.73it/s]

valid epoch[3/100]: 100%|██████████| 12/12 [00:00<00:00, 70.79it/s]

[03/100] train loss = 1.97657, train acc = 0.37838 valid loss = 1.77005, valid acc = 0.42448

train epoch[4/100] loss:1.533: 100%|██████████| 37/37 [00:01<00:00, 21.36it/s]

valid epoch[4/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[04/100] train loss = 1.72868, train acc = 0.44679 valid loss = 1.45628, valid acc = 0.57031

train epoch[5/100] loss:1.324: 100%|██████████| 37/37 [00:01<00:00, 21.43it/s]

valid epoch[5/100]: 100%|██████████| 12/12 [00:00<00:00, 73.37it/s]

[05/100] train loss = 1.43806, train acc = 0.57855 valid loss = 1.14773, valid acc = 0.70833

train epoch[6/100] loss:0.977: 100%|██████████| 37/37 [00:01<00:00, 21.53it/s]

valid epoch[6/100]: 100%|██████████| 12/12 [00:00<00:00, 81.85it/s]

[06/100] train loss = 1.20136, train acc = 0.68919 valid loss = 0.93165, valid acc = 0.71875

train epoch[7/100] loss:0.918: 100%|██████████| 37/37 [00:01<00:00, 20.55it/s]

valid epoch[7/100]: 100%|██████████| 12/12 [00:00<00:00, 76.62it/s]

[07/100] train loss = 1.01878, train acc = 0.76014 valid loss = 0.78236, valid acc = 0.79167

train epoch[8/100] loss:0.837: 100%|██████████| 37/37 [00:01<00:00, 21.41it/s]

valid epoch[8/100]: 100%|██████████| 12/12 [00:00<00:00, 81.85it/s]

[08/100] train loss = 0.88433, train acc = 0.80743 valid loss = 0.67526, valid acc = 0.85156

train epoch[9/100] loss:0.866: 100%|██████████| 37/37 [00:01<00:00, 18.51it/s]

valid epoch[9/100]: 100%|██████████| 12/12 [00:00<00:00, 75.20it/s]

[09/100] train loss = 0.77536, train acc = 0.85304 valid loss = 0.61958, valid acc = 0.84375

train epoch[10/100] loss:0.650: 100%|██████████| 37/37 [00:01<00:00, 21.53it/s]

valid epoch[10/100]: 100%|██████████| 12/12 [00:00<00:00, 83.54it/s]

[10/100] train loss = 0.68927, train acc = 0.87838 valid loss = 0.53588, valid acc = 0.88802

train epoch[11/100] loss:0.554: 100%|██████████| 37/37 [00:01<00:00, 21.03it/s]

valid epoch[11/100]: 100%|██████████| 12/12 [00:00<00:00, 75.18it/s]

[11/100] train loss = 0.63142, train acc = 0.89780 valid loss = 0.50332, valid acc = 0.89583

train epoch[12/100] loss:0.491: 100%|██████████| 37/37 [00:01<00:00, 21.66it/s]

valid epoch[12/100]: 100%|██████████| 12/12 [00:00<00:00, 74.73it/s]

[12/100] train loss = 0.56722, train acc = 0.91470 valid loss = 0.47348, valid acc = 0.90885

train epoch[13/100] loss:0.474: 100%|██████████| 37/37 [00:01<00:00, 21.36it/s]

valid epoch[13/100]: 100%|██████████| 12/12 [00:00<00:00, 74.71it/s]

[13/100] train loss = 0.51700, train acc = 0.93328 valid loss = 0.42631, valid acc = 0.91667

train epoch[14/100] loss:0.532: 100%|██████████| 37/37 [00:01<00:00, 21.64it/s]

valid epoch[14/100]: 100%|██████████| 12/12 [00:00<00:00, 74.27it/s]

[14/100] train loss = 0.48976, train acc = 0.93581 valid loss = 0.41196, valid acc = 0.93490

train epoch[15/100] loss:0.418: 100%|██████████| 37/37 [00:01<00:00, 21.76it/s]

valid epoch[15/100]: 100%|██████████| 12/12 [00:00<00:00, 84.14it/s]

[15/100] train loss = 0.44979, train acc = 0.94003 valid loss = 0.38338, valid acc = 0.93229

train epoch[16/100] loss:0.365: 100%|██████████| 37/37 [00:01<00:00, 21.68it/s]

valid epoch[16/100]: 100%|██████████| 12/12 [00:00<00:00, 74.27it/s]

[16/100] train loss = 0.41998, train acc = 0.95439 valid loss = 0.34409, valid acc = 0.93750

train epoch[17/100] loss:0.374: 100%|██████████| 37/37 [00:01<00:00, 21.87it/s]

valid epoch[17/100]: 100%|██████████| 12/12 [00:00<00:00, 78.64it/s]

[17/100] train loss = 0.38335, train acc = 0.95777 valid loss = 0.33143, valid acc = 0.94531

train epoch[18/100] loss:0.304: 100%|██████████| 37/37 [00:01<00:00, 21.56it/s]

valid epoch[18/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[18/100] train loss = 0.36607, train acc = 0.95777 valid loss = 0.29637, valid acc = 0.95312

train epoch[19/100] loss:0.273: 100%|██████████| 37/37 [00:01<00:00, 21.38it/s]

valid epoch[19/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[19/100] train loss = 0.33524, train acc = 0.96791 valid loss = 0.28047, valid acc = 0.95052

train epoch[20/100] loss:0.265: 100%|██████████| 37/37 [00:01<00:00, 21.98it/s]

valid epoch[20/100]: 100%|██████████| 12/12 [00:00<00:00, 77.63it/s]

[20/100] train loss = 0.31162, train acc = 0.96875 valid loss = 0.26248, valid acc = 0.96094

train epoch[21/100] loss:0.198: 100%|██████████| 37/37 [00:01<00:00, 21.58it/s]

valid epoch[21/100]: 100%|██████████| 12/12 [00:00<00:00, 70.78it/s]

[21/100] train loss = 0.29139, train acc = 0.97382 valid loss = 0.25048, valid acc = 0.95833

train epoch[22/100] loss:0.260: 100%|██████████| 37/37 [00:01<00:00, 21.07it/s]

valid epoch[22/100]: 100%|██████████| 12/12 [00:00<00:00, 81.30it/s]

[22/100] train loss = 0.27686, train acc = 0.97889 valid loss = 0.23296, valid acc = 0.95833

train epoch[23/100] loss:0.210: 100%|██████████| 37/37 [00:01<00:00, 21.26it/s]

valid epoch[23/100]: 100%|██████████| 12/12 [00:00<00:00, 73.37it/s]

[23/100] train loss = 0.24999, train acc = 0.98480 valid loss = 0.22225, valid acc = 0.96354

train epoch[24/100] loss:0.268: 100%|██████████| 37/37 [00:01<00:00, 21.44it/s]

valid epoch[24/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[24/100] train loss = 0.23558, train acc = 0.98057 valid loss = 0.20795, valid acc = 0.96354

train epoch[25/100] loss:0.168: 100%|██████████| 37/37 [00:01<00:00, 21.56it/s]

valid epoch[25/100]: 100%|██████████| 12/12 [00:00<00:00, 69.95it/s]

[25/100] train loss = 0.21769, train acc = 0.98480 valid loss = 0.18703, valid acc = 0.96615

train epoch[26/100] loss:0.274: 100%|██████████| 37/37 [00:01<00:00, 21.75it/s]

valid epoch[26/100]: 100%|██████████| 12/12 [00:00<00:00, 73.82it/s]

[26/100] train loss = 0.20820, train acc = 0.98057 valid loss = 0.17861, valid acc = 0.97135

train epoch[27/100] loss:0.185: 100%|██████████| 37/37 [00:01<00:00, 21.49it/s]

valid epoch[27/100]: 100%|██████████| 12/12 [00:00<00:00, 76.15it/s]

[27/100] train loss = 0.19181, train acc = 0.99071 valid loss = 0.16663, valid acc = 0.97396

train epoch[28/100] loss:0.181: 100%|██████████| 37/37 [00:01<00:00, 21.00it/s]

valid epoch[28/100]: 100%|██████████| 12/12 [00:00<00:00, 67.22it/s]

[28/100] train loss = 0.17669, train acc = 0.99324 valid loss = 0.16026, valid acc = 0.97135

train epoch[29/100] loss:0.171: 100%|██████████| 37/37 [00:01<00:00, 19.92it/s]

valid epoch[29/100]: 100%|██████████| 12/12 [00:00<00:00, 71.62it/s]

[29/100] train loss = 0.16942, train acc = 0.98818 valid loss = 0.14299, valid acc = 0.98698

train epoch[30/100] loss:0.113: 100%|██████████| 37/37 [00:01<00:00, 21.47it/s]

valid epoch[30/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[30/100] train loss = 0.15469, train acc = 0.99240 valid loss = 0.13816, valid acc = 0.98177

train epoch[31/100] loss:0.142: 100%|██████████| 37/37 [00:01<00:00, 20.68it/s]

valid epoch[31/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[31/100] train loss = 0.14401, train acc = 0.99071 valid loss = 0.13443, valid acc = 0.97917

train epoch[32/100] loss:0.109: 100%|██████████| 37/37 [00:01<00:00, 21.16it/s]

valid epoch[32/100]: 100%|██████████| 12/12 [00:00<00:00, 70.78it/s]

[32/100] train loss = 0.14164, train acc = 0.99071 valid loss = 0.12356, valid acc = 0.98698

train epoch[33/100] loss:0.097: 100%|██████████| 37/37 [00:01<00:00, 20.21it/s]

valid epoch[33/100]: 100%|██████████| 12/12 [00:00<00:00, 74.27it/s]

[33/100] train loss = 0.13008, train acc = 0.99240 valid loss = 0.11986, valid acc = 0.98177

train epoch[34/100] loss:0.154: 100%|██████████| 37/37 [00:01<00:00, 21.04it/s]

valid epoch[34/100]: 100%|██████████| 12/12 [00:00<00:00, 74.27it/s]

[34/100] train loss = 0.11819, train acc = 0.99155 valid loss = 0.11186, valid acc = 0.98958

train epoch[35/100] loss:0.113: 100%|██████████| 37/37 [00:01<00:00, 21.00it/s]

valid epoch[35/100]: 100%|██████████| 12/12 [00:00<00:00, 71.62it/s]

[35/100] train loss = 0.11408, train acc = 0.99409 valid loss = 0.10467, valid acc = 0.99219

train epoch[36/100] loss:0.081: 100%|██████████| 37/37 [00:01<00:00, 21.57it/s]

valid epoch[36/100]: 100%|██████████| 12/12 [00:00<00:00, 71.18it/s]

[36/100] train loss = 0.10629, train acc = 0.99493 valid loss = 0.10322, valid acc = 0.98698

train epoch[37/100] loss:0.068: 100%|██████████| 37/37 [00:01<00:00, 21.14it/s]

valid epoch[37/100]: 100%|██████████| 12/12 [00:00<00:00, 73.37it/s]

[37/100] train loss = 0.10024, train acc = 0.99662 valid loss = 0.08967, valid acc = 0.99219

train epoch[38/100] loss:0.088: 100%|██████████| 37/37 [00:01<00:00, 21.76it/s]

valid epoch[38/100]: 100%|██████████| 12/12 [00:00<00:00, 75.20it/s]

[38/100] train loss = 0.09357, train acc = 0.99578 valid loss = 0.09180, valid acc = 0.98698

train epoch[39/100] loss:0.090: 100%|██████████| 37/37 [00:01<00:00, 21.30it/s]

valid epoch[39/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[39/100] train loss = 0.08565, train acc = 0.99747 valid loss = 0.08579, valid acc = 0.99219

train epoch[40/100] loss:0.094: 100%|██████████| 37/37 [00:01<00:00, 21.52it/s]

valid epoch[40/100]: 100%|██████████| 12/12 [00:00<00:00, 75.67it/s]

[40/100] train loss = 0.07875, train acc = 0.99916 valid loss = 0.07779, valid acc = 0.99479

train epoch[41/100] loss:0.078: 100%|██████████| 37/37 [00:01<00:00, 21.30it/s]

valid epoch[41/100]: 100%|██████████| 12/12 [00:00<00:00, 71.19it/s]

[41/100] train loss = 0.08110, train acc = 0.99662 valid loss = 0.07521, valid acc = 0.99219

train epoch[42/100] loss:0.069: 100%|██████████| 37/37 [00:01<00:00, 20.63it/s]

valid epoch[42/100]: 100%|██████████| 12/12 [00:00<00:00, 75.20it/s]

[42/100] train loss = 0.07253, train acc = 1.00000 valid loss = 0.06846, valid acc = 0.99479

train epoch[43/100] loss:0.069: 100%|██████████| 37/37 [00:01<00:00, 20.83it/s]

valid epoch[43/100]: 100%|██████████| 12/12 [00:00<00:00, 71.62it/s]

[43/100] train loss = 0.07062, train acc = 0.99831 valid loss = 0.06661, valid acc = 0.99479

train epoch[44/100] loss:0.060: 100%|██████████| 37/37 [00:01<00:00, 20.80it/s]

valid epoch[44/100]: 100%|██████████| 12/12 [00:00<00:00, 73.37it/s]

[44/100] train loss = 0.06295, train acc = 0.99916 valid loss = 0.06407, valid acc = 0.99219

train epoch[45/100] loss:0.058: 100%|██████████| 37/37 [00:01<00:00, 20.61it/s]

valid epoch[45/100]: 100%|██████████| 12/12 [00:00<00:00, 57.85it/s]

[45/100] train loss = 0.06356, train acc = 0.99916 valid loss = 0.06337, valid acc = 0.99479

train epoch[46/100] loss:0.048: 100%|██████████| 37/37 [00:01<00:00, 20.41it/s]

valid epoch[46/100]: 100%|██████████| 12/12 [00:00<00:00, 70.35it/s]

[46/100] train loss = 0.05736, train acc = 1.00000 valid loss = 0.05693, valid acc = 0.99479

train epoch[47/100] loss:0.046: 100%|██████████| 37/37 [00:01<00:00, 20.67it/s]

valid epoch[47/100]: 100%|██████████| 12/12 [00:00<00:00, 73.82it/s]

[47/100] train loss = 0.05598, train acc = 0.99831 valid loss = 0.05114, valid acc = 0.99740

train epoch[48/100] loss:0.048: 100%|██████████| 37/37 [00:01<00:00, 20.45it/s]

valid epoch[48/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[48/100] train loss = 0.05222, train acc = 0.99831 valid loss = 0.05625, valid acc = 0.99219

train epoch[49/100] loss:0.060: 100%|██████████| 37/37 [00:01<00:00, 21.32it/s]

valid epoch[49/100]: 100%|██████████| 12/12 [00:00<00:00, 73.82it/s]

[49/100] train loss = 0.04794, train acc = 1.00000 valid loss = 0.05231, valid acc = 0.99479

train epoch[50/100] loss:0.043: 100%|██████████| 37/37 [00:01<00:00, 21.07it/s]

valid epoch[50/100]: 100%|██████████| 12/12 [00:00<00:00, 67.98it/s]

[50/100] train loss = 0.04888, train acc = 0.99916 valid loss = 0.05647, valid acc = 0.99219

train epoch[51/100] loss:0.040: 100%|██████████| 37/37 [00:01<00:00, 21.05it/s]

valid epoch[51/100]: 100%|██████████| 12/12 [00:00<00:00, 73.80it/s]

[51/100] train loss = 0.04834, train acc = 0.99916 valid loss = 0.04408, valid acc = 0.99740

train epoch[52/100] loss:0.041: 100%|██████████| 37/37 [00:01<00:00, 20.77it/s]

valid epoch[52/100]: 100%|██████████| 12/12 [00:00<00:00, 71.20it/s]

[52/100] train loss = 0.04667, train acc = 0.99916 valid loss = 0.04379, valid acc = 0.99479

train epoch[53/100] loss:0.055: 100%|██████████| 37/37 [00:01<00:00, 20.91it/s]

valid epoch[53/100]: 100%|██████████| 12/12 [00:00<00:00, 72.05it/s]

[53/100] train loss = 0.04231, train acc = 0.99916 valid loss = 0.04204, valid acc = 0.99219

train epoch[54/100] loss:0.032: 100%|██████████| 37/37 [00:01<00:00, 19.92it/s]

valid epoch[54/100]: 100%|██████████| 12/12 [00:00<00:00, 65.73it/s]

[54/100] train loss = 0.03975, train acc = 0.99916 valid loss = 0.04106, valid acc = 0.99479

train epoch[55/100] loss:0.031: 100%|██████████| 37/37 [00:01<00:00, 19.72it/s]

valid epoch[55/100]: 100%|██████████| 12/12 [00:00<00:00, 61.08it/s]

[55/100] train loss = 0.04146, train acc = 0.99831 valid loss = 0.03957, valid acc = 0.99740

train epoch[56/100] loss:0.035: 100%|██████████| 37/37 [00:02<00:00, 16.76it/s]

valid epoch[56/100]: 100%|██████████| 12/12 [00:00<00:00, 48.52it/s]

[56/100] train loss = 0.03479, train acc = 1.00000 valid loss = 0.03582, valid acc = 0.99740

train epoch[57/100] loss:0.027: 100%|██████████| 37/37 [00:02<00:00, 14.98it/s]

valid epoch[57/100]: 100%|██████████| 12/12 [00:00<00:00, 69.95it/s]

[57/100] train loss = 0.03489, train acc = 0.99916 valid loss = 0.03444, valid acc = 1.00000

train epoch[58/100] loss:0.032: 100%|██████████| 37/37 [00:01<00:00, 19.35it/s]

valid epoch[58/100]: 100%|██████████| 12/12 [00:00<00:00, 57.85it/s]

[58/100] train loss = 0.03554, train acc = 0.99916 valid loss = 0.03774, valid acc = 0.99219

train epoch[59/100] loss:0.026: 100%|██████████| 37/37 [00:01<00:00, 18.50it/s]

valid epoch[59/100]: 100%|██████████| 12/12 [00:00<00:00, 77.63it/s]

[59/100] train loss = 0.03194, train acc = 1.00000 valid loss = 0.03534, valid acc = 0.99740

train epoch[60/100] loss:0.026: 100%|██████████| 37/37 [00:01<00:00, 19.12it/s]

valid epoch[60/100]: 100%|██████████| 12/12 [00:00<00:00, 67.20it/s]

[60/100] train loss = 0.03171, train acc = 1.00000 valid loss = 0.03281, valid acc = 0.99740

train epoch[61/100] loss:0.038: 100%|██████████| 37/37 [00:02<00:00, 17.62it/s]

valid epoch[61/100]: 100%|██████████| 12/12 [00:00<00:00, 60.77it/s]

[61/100] train loss = 0.03192, train acc = 0.99916 valid loss = 0.03807, valid acc = 0.99219

train epoch[62/100] loss:0.028: 100%|██████████| 37/37 [00:01<00:00, 18.79it/s]

valid epoch[62/100]: 100%|██████████| 12/12 [00:00<00:00, 81.30it/s]

[62/100] train loss = 0.03033, train acc = 0.99916 valid loss = 0.03123, valid acc = 0.99740

train epoch[63/100] loss:0.034: 100%|██████████| 37/37 [00:01<00:00, 18.68it/s]

valid epoch[63/100]: 100%|██████████| 12/12 [00:00<00:00, 53.01it/s]

[63/100] train loss = 0.02704, train acc = 1.00000 valid loss = 0.03206, valid acc = 0.99740

train epoch[64/100] loss:0.024: 100%|██████████| 37/37 [00:01<00:00, 19.03it/s]

valid epoch[64/100]: 100%|██████████| 12/12 [00:00<00:00, 70.36it/s]

[64/100] train loss = 0.02689, train acc = 0.99831 valid loss = 0.02918, valid acc = 0.99740

train epoch[65/100] loss:0.020: 100%|██████████| 37/37 [00:02<00:00, 18.43it/s]

valid epoch[65/100]: 100%|██████████| 12/12 [00:00<00:00, 62.34it/s]

[65/100] train loss = 0.02567, train acc = 0.99916 valid loss = 0.02967, valid acc = 0.99479

train epoch[66/100] loss:0.024: 100%|██████████| 37/37 [00:01<00:00, 19.01it/s]

valid epoch[66/100]: 100%|██████████| 12/12 [00:00<00:00, 65.75it/s]

[66/100] train loss = 0.02429, train acc = 1.00000 valid loss = 0.02723, valid acc = 0.99740

train epoch[67/100] loss:0.023: 100%|██████████| 37/37 [00:01<00:00, 20.66it/s]

valid epoch[67/100]: 100%|██████████| 12/12 [00:00<00:00, 68.36it/s]

[67/100] train loss = 0.02462, train acc = 0.99916 valid loss = 0.02666, valid acc = 0.99740

train epoch[68/100] loss:0.025: 100%|██████████| 37/37 [00:01<00:00, 20.51it/s]

valid epoch[68/100]: 100%|██████████| 12/12 [00:00<00:00, 71.62it/s]

[68/100] train loss = 0.02393, train acc = 1.00000 valid loss = 0.02665, valid acc = 0.99740

train epoch[69/100] loss:0.025: 100%|██████████| 37/37 [00:02<00:00, 17.41it/s]

valid epoch[69/100]: 100%|██████████| 12/12 [00:00<00:00, 66.48it/s]

[69/100] train loss = 0.02368, train acc = 1.00000 valid loss = 0.02783, valid acc = 0.99740

train epoch[70/100] loss:0.023: 100%|██████████| 37/37 [00:01<00:00, 20.67it/s]

valid epoch[70/100]: 100%|██████████| 12/12 [00:00<00:00, 68.75it/s]

[70/100] train loss = 0.02227, train acc = 1.00000 valid loss = 0.02939, valid acc = 0.99479

train epoch[71/100] loss:0.023: 100%|██████████| 37/37 [00:01<00:00, 21.13it/s]

valid epoch[71/100]: 100%|██████████| 12/12 [00:00<00:00, 73.82it/s]

[71/100] train loss = 0.02293, train acc = 0.99916 valid loss = 0.03210, valid acc = 0.99479

train epoch[72/100] loss:0.019: 100%|██████████| 37/37 [00:01<00:00, 21.08it/s]

valid epoch[72/100]: 100%|██████████| 12/12 [00:00<00:00, 67.98it/s]

[72/100] train loss = 0.02295, train acc = 0.99831 valid loss = 0.02529, valid acc = 0.99479

train epoch[73/100] loss:0.017: 100%|██████████| 37/37 [00:01<00:00, 20.52it/s]

valid epoch[73/100]: 100%|██████████| 12/12 [00:00<00:00, 75.20it/s]

[73/100] train loss = 0.01929, train acc = 1.00000 valid loss = 0.02114, valid acc = 0.99740

train epoch[74/100] loss:0.014: 100%|██████████| 37/37 [00:01<00:00, 18.94it/s]

valid epoch[74/100]: 100%|██████████| 12/12 [00:00<00:00, 72.05it/s]

[74/100] train loss = 0.01884, train acc = 1.00000 valid loss = 0.01829, valid acc = 1.00000

train epoch[75/100] loss:0.017: 100%|██████████| 37/37 [00:01<00:00, 21.02it/s]

valid epoch[75/100]: 100%|██████████| 12/12 [00:00<00:00, 72.03it/s]

[75/100] train loss = 0.01927, train acc = 1.00000 valid loss = 0.02181, valid acc = 0.99479

train epoch[76/100] loss:0.015: 100%|██████████| 37/37 [00:01<00:00, 20.97it/s]

valid epoch[76/100]: 100%|██████████| 12/12 [00:00<00:00, 71.60it/s]

[76/100] train loss = 0.01836, train acc = 1.00000 valid loss = 0.02229, valid acc = 0.99479

train epoch[77/100] loss:0.014: 100%|██████████| 37/37 [00:02<00:00, 17.26it/s]

valid epoch[77/100]: 100%|██████████| 12/12 [00:00<00:00, 70.78it/s]

[77/100] train loss = 0.01834, train acc = 1.00000 valid loss = 0.02153, valid acc = 0.99479

train epoch[78/100] loss:0.020: 100%|██████████| 37/37 [00:01<00:00, 20.81it/s]

valid epoch[78/100]: 100%|██████████| 12/12 [00:00<00:00, 68.35it/s]

[78/100] train loss = 0.01873, train acc = 0.99916 valid loss = 0.02506, valid acc = 0.99479

train epoch[79/100] loss:0.014: 100%|██████████| 37/37 [00:01<00:00, 21.67it/s]

valid epoch[79/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[79/100] train loss = 0.01737, train acc = 1.00000 valid loss = 0.01964, valid acc = 0.99740

train epoch[80/100] loss:0.027: 100%|██████████| 37/37 [00:01<00:00, 21.11it/s]

valid epoch[80/100]: 100%|██████████| 12/12 [00:00<00:00, 72.05it/s]

[80/100] train loss = 0.01733, train acc = 1.00000 valid loss = 0.01674, valid acc = 1.00000

train epoch[81/100] loss:0.013: 100%|██████████| 37/37 [00:01<00:00, 21.31it/s]

valid epoch[81/100]: 100%|██████████| 12/12 [00:00<00:00, 77.61it/s]

[81/100] train loss = 0.01643, train acc = 1.00000 valid loss = 0.01542, valid acc = 1.00000

train epoch[82/100] loss:0.015: 100%|██████████| 37/37 [00:01<00:00, 20.96it/s]

valid epoch[82/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[82/100] train loss = 0.01495, train acc = 1.00000 valid loss = 0.01967, valid acc = 0.99479

train epoch[83/100] loss:0.016: 100%|██████████| 37/37 [00:01<00:00, 21.32it/s]

valid epoch[83/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[83/100] train loss = 0.01611, train acc = 0.99916 valid loss = 0.01737, valid acc = 0.99479

train epoch[84/100] loss:0.013: 100%|██████████| 37/37 [00:01<00:00, 21.37it/s]

valid epoch[84/100]: 100%|██████████| 12/12 [00:00<00:00, 76.15it/s]

[84/100] train loss = 0.01402, train acc = 1.00000 valid loss = 0.01789, valid acc = 0.99740

train epoch[85/100] loss:0.011: 100%|██████████| 37/37 [00:01<00:00, 21.59it/s]

valid epoch[85/100]: 100%|██████████| 12/12 [00:00<00:00, 72.92it/s]

[85/100] train loss = 0.01373, train acc = 1.00000 valid loss = 0.02572, valid acc = 0.99479

train epoch[86/100] loss:0.020: 100%|██████████| 37/37 [00:01<00:00, 21.49it/s]

valid epoch[86/100]: 100%|██████████| 12/12 [00:00<00:00, 72.03it/s]

[86/100] train loss = 0.01379, train acc = 1.00000 valid loss = 0.01887, valid acc = 0.99740

train epoch[87/100] loss:0.014: 100%|██████████| 37/37 [00:01<00:00, 19.90it/s]

valid epoch[87/100]: 100%|██████████| 12/12 [00:00<00:00, 72.48it/s]

[87/100] train loss = 0.01300, train acc = 1.00000 valid loss = 0.01850, valid acc = 0.99740

train epoch[88/100] loss:0.011: 100%|██████████| 37/37 [00:01<00:00, 18.70it/s]

valid epoch[88/100]: 100%|██████████| 12/12 [00:00<00:00, 53.01it/s]

[88/100] train loss = 0.01252, train acc = 1.00000 valid loss = 0.01938, valid acc = 0.99479

train epoch[89/100] loss:0.012: 100%|██████████| 37/37 [00:01<00:00, 19.00it/s]

valid epoch[89/100]: 100%|██████████| 12/12 [00:00<00:00, 75.20it/s]

[89/100] train loss = 0.01472, train acc = 0.99747 valid loss = 0.02491, valid acc = 0.99479

train epoch[90/100] loss:0.011: 100%|██████████| 37/37 [00:01<00:00, 20.91it/s]

valid epoch[90/100]: 100%|██████████| 12/12 [00:00<00:00, 70.78it/s]

[90/100] train loss = 0.01350, train acc = 1.00000 valid loss = 0.01387, valid acc = 1.00000

train epoch[91/100] loss:0.012: 100%|██████████| 37/37 [00:01<00:00, 21.16it/s]

valid epoch[91/100]: 100%|██████████| 12/12 [00:00<00:00, 69.55it/s]

[91/100] train loss = 0.01305, train acc = 1.00000 valid loss = 0.03113, valid acc = 0.99479

train epoch[92/100] loss:0.011: 100%|██████████| 37/37 [00:01<00:00, 20.76it/s]

valid epoch[92/100]: 100%|██████████| 12/12 [00:00<00:00, 70.36it/s]

[92/100] train loss = 0.01209, train acc = 1.00000 valid loss = 0.04791, valid acc = 0.98958

train epoch[93/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 21.03it/s]

valid epoch[93/100]: 100%|██████████| 12/12 [00:00<00:00, 72.05it/s]

[93/100] train loss = 0.01593, train acc = 0.99831 valid loss = 0.04162, valid acc = 0.98958

train epoch[94/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 21.75it/s]

valid epoch[94/100]: 100%|██████████| 12/12 [00:00<00:00, 76.15it/s]

[94/100] train loss = 0.01366, train acc = 0.99916 valid loss = 0.03043, valid acc = 0.99479

train epoch[95/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 19.49it/s]

valid epoch[95/100]: 100%|██████████| 12/12 [00:00<00:00, 55.70it/s]

[95/100] train loss = 0.01159, train acc = 1.00000 valid loss = 0.01456, valid acc = 0.99479

train epoch[96/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 19.23it/s]

valid epoch[96/100]: 100%|██████████| 12/12 [00:00<00:00, 53.71it/s]

[96/100] train loss = 0.01044, train acc = 1.00000 valid loss = 0.01179, valid acc = 1.00000

train epoch[97/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 19.80it/s]

valid epoch[97/100]: 100%|██████████| 12/12 [00:00<00:00, 77.63it/s]

[97/100] train loss = 0.01049, train acc = 1.00000 valid loss = 0.01203, valid acc = 1.00000

train epoch[98/100] loss:0.011: 100%|██████████| 37/37 [00:01<00:00, 19.81it/s]

valid epoch[98/100]: 100%|██████████| 12/12 [00:00<00:00, 76.64it/s]

[98/100] train loss = 0.01043, train acc = 1.00000 valid loss = 0.01578, valid acc = 0.99740

train epoch[99/100] loss:0.010: 100%|██████████| 37/37 [00:01<00:00, 19.14it/s]

valid epoch[99/100]: 100%|██████████| 12/12 [00:00<00:00, 64.00it/s]

[99/100] train loss = 0.01027, train acc = 1.00000 valid loss = 0.01219, valid acc = 0.99740

train epoch[100/100] loss:0.007: 100%|██████████| 37/37 [00:01<00:00, 20.18it/s]

valid epoch[100/100]: 100%|██████████| 12/12 [00:00<00:00, 78.13it/s]

[100/100] train loss = 0.00954, train acc = 1.00000 valid loss = 0.01715, valid acc = 0.99479

完整代码如下:
https://mbd.pub/o/bread/mbd-ZJialpxy

相关的文章参考

几种信号降噪算法(第一部分)

https://www.toutiao.com/article/7190201924820402721/

几种信号降噪算法(第二部分)

https://www.toutiao.com/article/7190270349236683264/

机械故障诊断及工业工程故障诊断若干例子(第一篇)

https://www.toutiao.com/article/7193957227231855163/

知乎咨询:哥廷根数学学派

算法代码地址:mbd.pub/o/GeBENHAGEN

擅长现代信号处理(改进小波分析系列,改进变分模态分解,改进经验小波变换,改进辛几何模态分解等等),改进机器学习,改进深度学习,机械故障诊断,改进时间序列分析(金融信号,心电信号,振动信号等)

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/512388.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何恢复数据?数据恢复,5个实用方法!

案例&#xff1a;如何恢复数据 【我是个比较粗心的人&#xff0c;总是会莫名奇妙的就丢失各种电脑的数据&#xff0c;想问下大家在使用电脑时&#xff0c;如果有数据的丢失&#xff0c;是如何恢复数据的呢&#xff1f;】 在使用Windows电脑时&#xff0c;数据丢失或删除是非常…

支付系统设计二:统一开发框架

文章目录 前言一、项目分层二、模块职责简介1. API层2. Service层2.1 操作执行服务2.2 操作器2.3 操作执行器2.4 参数校验2.5 操作器实现 3. Domain层4. Infrastructure层4.1 Dal层 三、对应类图四、开发内容3.1 约定请求报文格式3.2 新增交易码与操作器映射枚举类3.3 配置参数…

2 # 函数柯里化

什么是函数柯里化 函数柯里化&#xff08;Currying&#xff09;是一种将接受多个参数的函数转换为一系列接受单一参数的函数的技术。 通过函数柯里化&#xff0c;我们可以将原来接受多个参数的函数&#xff0c;转换为一系列只接受单一参数的函数&#xff0c;每个函数接收一个…

前端面试题总结(初级前端:HTML + CSS + JavaScript + Ajax + Vue2全家桶)

theme: channing-cyan 求关注&#x1f62d; 壹、HTML CSS 1. 对HTML语义化的理解 去掉或者丢失样式的时候能够让页面呈现出清晰的结构&#xff1b;代码结构清晰&#xff0c;方便团队的管理和维护&#xff0c;并且语义化更具可读性&#xff1b;提升用户体验&#xff0c;在…

什么是daemon与服务(service)

什么是daemon与服务(service) 在Linux系统中&#xff0c;daemon是指一类在后台运行的服务进程&#xff0c;通常以d结尾。它们不与用户进行交互&#xff0c;也不接受用户的输入&#xff0c;而是在系统启动时自动启动并一直运行&#xff0c;为操作系统、应用程序和其他服务提供支…

Julia入门-3、Julia包管理工具

文章目录 0、Julia 的包管理工具是Pkg1、使用Julia包管理工具过慢 0、Julia 的包管理工具是Pkg Julia 的包管理工具是Pkg&#xff0c;可以用于安装、更新、卸载和管理 Julia 中的软件包。以下是一些常用的 Pkg命令&#xff1a; Pkg.add("Package")&#xff1a;安装一…

Node.js 与 WebAssembly

目录 1、简介 2、关键概念 3、生成WebAssembly模块 4、如何使用它 5、与操作系统交互 1、简介 首先&#xff0c;让我们了解为什么WebAssembly是一个很棒的工具&#xff0c;并学会自己使用它。 WebAssembly是一种类似汇编的高性能语言&#xff0c;可以从各种语言编译&…

深度学习 - 47.DIN 深度兴趣网络保姆级实现 By Keras

目录 一.引言 二.DIN 模型分析 1.Input 输入 2.Embedding & Concat 嵌入与合并 3.DIN 深度兴趣网络 4.MLP 全连接 三.DIN 模型实现 1.Input 2.DIN Layer 2.1 init 初始化 2.2 build 构建 2.3 call 调用 3.Dice Layer 3.1 init 初始化 3.2 build 构建 3.3 …

网络安全:渗透神器 kali 的安装.

网络安全&#xff1a;渗透神器 kali 的安装. Kali Linux是一款基于Debian的Linux发行版&#xff0c;专门用于渗透测试和网络安全评估。它包含了大量的渗透测试工具和网络安全工具&#xff0c;适用于各种不同的渗透测试场景和需求。 目录&#xff1a; 网络安全&#xff1a;渗透…

MS5814可选内置基准、四通道数模转换器

MS5814/5814T 是一款 12bit 四通道输出的电压型 DAC&#xff0c;集成可选内部基准&#xff0c;接口采用四线串口模式&#xff0c;可以兼容 TMS320、SPI、QSPI 和 Microwire 串口。MS5814/5814T 控制数据有 16bit&#xff0c;包括 DAC 地址&#xff0c;控制字节和 12bitDAC 数据…

MySQL——BasicKnowledge

1. Mysql Version ​​​​​​​​​​​​ 2.install & uninstall 2.1 Linux My Content 3.Configure 3.1 设置IP访问 参考链接 3.1.1 方法一&#xff1a;改表法 --登入mysql后&#xff0c;更改"mysql"数据库中"user"表里的 "host&quo…

“三问五步”落地医疗行业数据安全建设体系|盾见

个 文|龚磊 2021年6月10日&#xff0c;我国《数据安全法》颁布&#xff0c;并于2021年9月1日正式施行&#xff0c;作为数据领域的纲领性和基础性法律&#xff0c;以准确定义数据、数据处理、数据安全为出发点&#xff0c;提出解决数据全生命周期中的数据安全问题&#xff0c;达…

深入浅出,理解知识图谱技术及其应用

知识图谱是一个将各种实体之间的关系以图谱的形式呈现出来的技术。这些实体可以是人、地点、组织或任何其他类型的实体。知识图谱将这些实体与它们之间的关系链接在一起&#xff0c;从而形成一个表示知识的图形结构。本文将介绍知识图谱的基础知识&#xff0c;包括它的定义、应…

【TA100】渲染管线

粗粒度剔除&#xff1a;根据物体之间的遮挡关系&#xff0c;剔除遮挡的物体。 多顶点分配到GPU不同单元执行&#xff0c;提升速度 1 应用阶段 1.1 场景阶段 ### 1.2 粗粒度剔除 剔除与摄像机与视锥体不相交的光源或者光线照射方向与与视角不重合的光源。 1.3 渲染设置 1.4 调用…

AVL树的插入

介绍: 在二叉搜索树的前提下,左右高度差(平衡因子)的绝对值不大于1 二叉搜索数->中序排序树->极端情况下时间复杂度高 ->我博客更过不了解去翻翻 (搜索二叉树——寻找节点&#xff0c;插入节点&#xff0c;删除节点_别想闲鱼了&#xff01;快去学习的博客-CSDN博客)…

硬核推荐!3款私藏的卡通头像在线生成网站,减少撞“头”率

现在各个软件应用都会有自己的头像设置&#xff0c;肯定有很多朋友经常喜欢换头像&#xff0c;我猜大家的头像要么就是明星&#xff0c;要么就是网图&#xff0c;总是出现和别人撞“头”的现象。今天就来给大家推荐几个在线制作头像的网站&#xff0c;保证让撞“头”率减少90%。…

【MYSQL】聚合函数和单表/多表查询练习、子查询、内外连接

目录 1.聚合函数 1.1.group by子句 1.2.having语句 2.单表查询 2.2单表查询 3.多表查询 3.2.子查询 5.内链接 6.外连接 1.聚合函数 函数说明count返回查询到的数据的数量sum返回查询到的数据的总和avg返回查询到的数据的平均值max返回查询到的数据的最大值min返回查询…

WPF MVVM基础教程(五)RelativeSource属性绑定

RelativeSource属性绑定 介绍RelativeSource属性介绍RelativeSource的Mode属性有四种模式&#xff1a; 四种模式用法Self模式FindAncestor模式使用规则&#xff1a; TemplatedParent模式PreviousData模式 特殊用法绑定到其他ViewModel上的命令 介绍 RelativeSource 是一个标记…

前端HTML学习(二)

1、列表标签 列表标签概述&#xff1a;能够使用无序列表、有序列表、自定义列表标签&#xff0c;实现网页中列表结构的搭建。列表应用在网页中按照行展示关联性的内容&#xff0c;如:新闻列表、排行榜、账单等。 特点&#xff1a;按照行的方式&#xff0c;整齐显示内容 种类&a…

大模型遭泄两月后 Meta意外变赢家

一份被意外泄露的谷歌内部文件&#xff0c;将Meta的LLaMA大模型“非故意开源”事件再次推到聚光灯前。 “泄密文件”的作者据悉是谷歌内部的一位研究员&#xff0c;他大胆指出&#xff0c;开源力量正在填平OpenAI与谷歌等大模型巨头们数年来筑起的护城河&#xff0c;而最大的受…