第5章:基于EfficientNet 网络实现的图像分类任务:104种花种类识别

发布于:2024-12-21 ⋅ 阅读:(13) ⋅ 点赞:(0)

目录

1. EfficientNet

2. EfficientNet 实现的花分类

2.1 花数据集

2.2 训练脚本

2.3 训练结果

2.4 推理

3. 下载


1. EfficientNet

EfficientNet是一种卷积神经网络(CNN)架构,由谷歌的研究人员于2019年推出。它以高效利用计算资源而闻名,同时在各种计算机视觉任务(如图像分类和对象检测)上实现了最先进的性能。

EfficientNet背后的关键思想是通过优化三个维度(深度、宽度和分辨率)以更平衡的方式扩展模型架构。通常,当放大CNN时,研究人员会增加层数(深度)、每层中的滤波器数量(宽度)和输入图像分辨率。然而,这可能会迅速导致计算要求的增加,而性能没有相应的提高。

为了解决这个问题,研究人员引入了一种复合缩放方法,该方法使用复合系数同时缩放网络深度、宽度和分辨率。该系数允许有效的模型缩放,因为它根据计算效率和精度之间的预定义权衡来确定每个维度增加多少。

EfficientNet通过结合使用众所周知的技术来实现高效率,例如深度可分离卷积,它减少了计算次数,以及挤压和激励块,这有助于网络专注于重要特征。此外,它利用神经架构搜索(NAS)算法在给定固定资源约束的情况下自动发现最优架构。

总体而言,EfficientNet在各种图像分类基准测试(如ImageNet)上表现出了卓越的性能,同时与以前最先进的模型相比,需要更少的参数和计算。其高效的设计使其非常适合资源受限的应用程序,如移动设备和边缘计算。

其中,EfficientNet 网络结构如下:

2. EfficientNet 实现的花分类

EfficientNet 实现的model部分代码如下面所示,这里如果采用官方预训练权重的话,会自动导入官方提供的最新版本的权重

    if model == 'b0':
        net = m.efficientnet_b0(weights=m.EfficientNet_B0_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b1':
        net = m.efficientnet_b1(weights=m.EfficientNet_B1_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b2':
        net = m.efficientnet_b2(weights=m.EfficientNet_B2_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b3':
        net = m.efficientnet_b3(weights=m.EfficientNet_B3_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b4':
        net = m.efficientnet_b4(weights=m.EfficientNet_B4_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b5':
        net = m.efficientnet_b5(weights=m.EfficientNet_B5_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b6':
        net = m.efficientnet_b6(weights=m.EfficientNet_B6_Weights.DEFAULT if weights else False,progress=True)
    elif model == 'b7':
        net = m.efficientnet_b7(weights=m.EfficientNet_B7_Weights.DEFAULT if weights else False,progress=True)
    else:
        print('模型选择错误!!')
        return None

2.1 花数据集

数据集文件如下:

标签如下:这里没找到对应的中文标签....

{
    "0": "0",
    "1": "1",
    "2": "10",
    "3": "100",
    "4": "101",
    "5": "102",
    "6": "103",
    "7": "11",
    "8": "12",
    "9": "13",
    "10": "14",
    "11": "15",
    "12": "16",
    "13": "17",
    "14": "18",
    "15": "19",
    "16": "2",
    "17": "20",
    "18": "21",
    "19": "22",
    "20": "23",
    "21": "24",
    "22": "25",
    "23": "26",
    "24": "27",
    "25": "28",
    "26": "29",
    "27": "3",
    "28": "30",
    "29": "31",
    "30": "32",
    "31": "33",
    "32": "34",
    "33": "35",
    "34": "36",
    "35": "37",
    "36": "38",
    "37": "39",
    "38": "4",
    "39": "40",
    "40": "41",
    "41": "42",
    "42": "43",
    "43": "44",
    "44": "45",
    "45": "46",
    "46": "47",
    "47": "48",
    "48": "49",
    "49": "5",
    "50": "50",
    "51": "51",
    "52": "52",
    "53": "53",
    "54": "54",
    "55": "55",
    "56": "56",
    "57": "57",
    "58": "58",
    "59": "59",
    "60": "6",
    "61": "60",
    "62": "61",
    "63": "62",
    "64": "63",
    "65": "64",
    "66": "65",
    "67": "66",
    "68": "67",
    "69": "68",
    "70": "69",
    "71": "7",
    "72": "70",
    "73": "71",
    "74": "72",
    "75": "73",
    "76": "74",
    "77": "75",
    "78": "76",
    "79": "77",
    "80": "78",
    "81": "79",
    "82": "8",
    "83": "80",
    "84": "81",
    "85": "82",
    "86": "83",
    "87": "84",
    "88": "85",
    "89": "86",
    "90": "87",
    "91": "88",
    "92": "89",
    "93": "9",
    "94": "90",
    "95": "91",
    "96": "92",
    "97": "93",
    "98": "94",
    "99": "95",
    "100": "96",
    "101": "97",
    "102": "98",
    "103": "99"
}

其中,训练集的总数为12750,验证集的总数为3712

2.2 训练脚本

训练的参数如下:

    parser.add_argument("--model", default='b0', type=str,help='b0,b1,b2,b3,b4,b5,b6,b7')
    parser.add_argument("--pretrained", default=True, type=bool)       # 采用官方权重
    parser.add_argument("--freeze_layers", default=True, type=bool)    # 冻结权重

    parser.add_argument("--batch-size", default=32, type=int)
    parser.add_argument("--epochs", default=100, type=int)

    parser.add_argument("--optim", default='SGD', type=str,help='SGD,Adam,AdamW')         # 优化器选择

    parser.add_argument('--lr', default=0.01, type=float)
    parser.add_argument('--lrf',default=0.0001,type=float)                  # 最终学习率 = lr * lrf

    parser.add_argument('--save_ret', default='runs', type=str)             # 保存结果
    parser.add_argument('--data_train',default='./data/train',type=str)           # 训练集路径
    parser.add_argument('--data_val',default='./data/val',type=str)               # 测试集路径

网络分类的个数不需要指定,摆放好数据集后,代码会根据数据集自动生成!

2.3 训练结果

所有的结果都保存在 save_ret 目录下,这里是 runs 

weights 下有最好和最后的权重,在训练完成后控制台会打印最好的epoch

这里只展示部分结果:好像过拟合了...

训练日志:

    "epoch:99": {
        "train info": {
            "accuracy": 0.9091764705875222,
            "0": {
                "Precision": 0.8942,
                "Recall": 0.9108,
                "Specificity": 0.9977,
                "F1 score": 0.9024
            },
            "1": {
                "Precision": 1.0,
                "Recall": 0.9615,
                "Specificity": 1.0,
                "F1 score": 0.9804
            },
            "10": {
                "Precision": 0.8357,
                "Recall": 0.8603,
                "Specificity": 0.9982,
                "F1 score": 0.8478
            },
            "100": {
                "Precision": 0.9091,
                "Recall": 0.9677,
                "Specificity": 0.9998,
                "F1 score": 0.9375
            },
            "101": {
                "Precision": 0.9615,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.9804
            },
            "102": {
                "Precision": 0.8049,
                "Recall": 0.8359,
                "Specificity": 0.9936,
                "F1 score": 0.8201
            },
            "103": {
                "Precision": 0.8625,
                "Recall": 0.9031,
                "Specificity": 0.9911,
                "F1 score": 0.8823
            },
            "11": {
                "Precision": 0.9767,
                "Recall": 0.9767,
                "Specificity": 0.9999,
                "F1 score": 0.9767
            },
            "12": {
                "Precision": 0.9783,
                "Recall": 0.9783,
                "Specificity": 0.9998,
                "F1 score": 0.9783
            },
            "13": {
                "Precision": 0.8959,
                "Recall": 0.9163,
                "Specificity": 0.9978,
                "F1 score": 0.906
            },
            "14": {
                "Precision": 0.9386,
                "Recall": 0.9427,
                "Specificity": 0.9989,
                "F1 score": 0.9406
            },
            "15": {
                "Precision": 0.913,
                "Recall": 1.0,
                "Specificity": 0.9998,
                "F1 score": 0.9545
            },
            "16": {
                "Precision": 0.9483,
                "Recall": 1.0,
                "Specificity": 0.9998,
                "F1 score": 0.9735
            },
            "17": {
                "Precision": 0.9792,
                "Recall": 0.94,
                "Specificity": 0.9999,
                "F1 score": 0.9592
            },
            "18": {
                "Precision": 0.9412,
                "Recall": 0.8889,
                "Specificity": 0.9996,
                "F1 score": 0.9143
            },
            "19": {
                "Precision": 0.9615,
                "Recall": 0.9615,
                "Specificity": 0.9999,
                "F1 score": 0.9615
            },
            "2": {
                "Precision": 1.0,
                "Recall": 0.8,
                "Specificity": 1.0,
                "F1 score": 0.8889
            },
            "20": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "21": {
                "Precision": 0.9535,
                "Recall": 0.8542,
                "Specificity": 0.9997,
                "F1 score": 0.9011
            },
            "22": {
                "Precision": 0.9388,
                "Recall": 0.9583,
                "Specificity": 0.9998,
                "F1 score": 0.9484
            },
            "23": {
                "Precision": 1.0,
                "Recall": 0.9474,
                "Specificity": 1.0,
                "F1 score": 0.973
            },
            "24": {
                "Precision": 0.9535,
                "Recall": 0.9647,
                "Specificity": 0.9997,
                "F1 score": 0.9591
            },
            "25": {
                "Precision": 0.9359,
                "Recall": 0.8795,
                "Specificity": 0.9996,
                "F1 score": 0.9068
            },
            "26": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "27": {
                "Precision": 1.0,
                "Recall": 0.9706,
                "Specificity": 1.0,
                "F1 score": 0.9851
            },
            "28": {
                "Precision": 0.9421,
                "Recall": 0.958,
                "Specificity": 0.9994,
                "F1 score": 0.95
            },
            "29": {
                "Precision": 0.8932,
                "Recall": 0.844,
                "Specificity": 0.9991,
                "F1 score": 0.8679
            },
            "3": {
                "Precision": 1.0,
                "Recall": 0.5714,
                "Specificity": 1.0,
                "F1 score": 0.7272
            },
            "30": {
                "Precision": 0.8911,
                "Recall": 0.8571,
                "Specificity": 0.9991,
                "F1 score": 0.8738
            },
            "31": {
                "Precision": 0.875,
                "Recall": 0.875,
                "Specificity": 0.9998,
                "F1 score": 0.875
            },
            "32": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "33": {
                "Precision": 0.9524,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.9756
            },
            "34": {
                "Precision": 0.9474,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.973
            },
            "35": {
                "Precision": 1.0,
                "Recall": 0.9444,
                "Specificity": 1.0,
                "F1 score": 0.9714
            },
            "36": {
                "Precision": 0.9828,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.9913
            },
            "37": {
                "Precision": 0.9286,
                "Recall": 1.0,
                "Specificity": 0.9998,
                "F1 score": 0.963
            },
            "38": {
                "Precision": 0.9412,
                "Recall": 0.8421,
                "Specificity": 0.9999,
                "F1 score": 0.8889
            },
            "39": {
                "Precision": 0.971,
                "Recall": 0.9178,
                "Specificity": 0.9998,
                "F1 score": 0.9437
            },
            "4": {
                "Precision": 0.8583,
                "Recall": 0.8791,
                "Specificity": 0.9915,
                "F1 score": 0.8686
            },
            "40": {
                "Precision": 0.9846,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.9922
            },
            "41": {
                "Precision": 0.9348,
                "Recall": 0.8958,
                "Specificity": 0.9995,
                "F1 score": 0.9149
            },
            "42": {
                "Precision": 0.9508,
                "Recall": 0.9206,
                "Specificity": 0.9998,
                "F1 score": 0.9355
            },
            "43": {
                "Precision": 0.9545,
                "Recall": 0.9545,
                "Specificity": 0.9996,
                "F1 score": 0.9545
            },
            "44": {
                "Precision": 0.9474,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.973
            },
            "45": {
                "Precision": 0.9349,
                "Recall": 0.9186,
                "Specificity": 0.9991,
                "F1 score": 0.9267
            },
            "46": {
                "Precision": 0.9661,
                "Recall": 0.912,
                "Specificity": 0.9997,
                "F1 score": 0.9383
            },
            "47": {
                "Precision": 0.9219,
                "Recall": 0.9502,
                "Specificity": 0.9983,
                "F1 score": 0.9358
            },
            "48": {
                "Precision": 0.9147,
                "Recall": 0.9147,
                "Specificity": 0.9971,
                "F1 score": 0.9147
            },
            "49": {
                "Precision": 0.9139,
                "Recall": 0.9432,
                "Specificity": 0.9959,
                "F1 score": 0.9283
            },
            "5": {
                "Precision": 0.9524,
                "Recall": 0.9195,
                "Specificity": 0.9997,
                "F1 score": 0.9357
            },
            "50": {
                "Precision": 0.8966,
                "Recall": 0.9055,
                "Specificity": 0.9983,
                "F1 score": 0.901
            },
            "51": {
                "Precision": 0.9208,
                "Recall": 0.8857,
                "Specificity": 0.9994,
                "F1 score": 0.9029
            },
            "52": {
                "Precision": 0.9109,
                "Recall": 0.8,
                "Specificity": 0.9993,
                "F1 score": 0.8519
            },
            "53": {
                "Precision": 0.9531,
                "Recall": 0.9283,
                "Specificity": 0.9983,
                "F1 score": 0.9405
            },
            "54": {
                "Precision": 0.9474,
                "Recall": 0.973,
                "Specificity": 0.9998,
                "F1 score": 0.96
            },
            "55": {
                "Precision": 1.0,
                "Recall": 0.9655,
                "Specificity": 1.0,
                "F1 score": 0.9824
            },
            "56": {
                "Precision": 0.8925,
                "Recall": 0.9326,
                "Specificity": 0.9992,
                "F1 score": 0.9121
            },
            "57": {
                "Precision": 0.9839,
                "Recall": 0.9683,
                "Specificity": 0.9999,
                "F1 score": 0.976
            },
            "58": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "59": {
                "Precision": 1.0,
                "Recall": 0.9828,
                "Specificity": 1.0,
                "F1 score": 0.9913
            },
            "6": {
                "Precision": 0.9474,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.973
            },
            "60": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "61": {
                "Precision": 0.9286,
                "Recall": 0.8966,
                "Specificity": 0.9998,
                "F1 score": 0.9123
            },
            "62": {
                "Precision": 0.9462,
                "Recall": 0.9462,
                "Specificity": 0.9996,
                "F1 score": 0.9462
            },
            "63": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "64": {
                "Precision": 1.0,
                "Recall": 0.9818,
                "Specificity": 1.0,
                "F1 score": 0.9908
            },
            "65": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "66": {
                "Precision": 1.0,
                "Recall": 0.9048,
                "Specificity": 1.0,
                "F1 score": 0.95
            },
            "67": {
                "Precision": 0.935,
                "Recall": 0.9386,
                "Specificity": 0.9957,
                "F1 score": 0.9368
            },
            "68": {
                "Precision": 0.81,
                "Recall": 0.8692,
                "Specificity": 0.9958,
                "F1 score": 0.8386
            },
            "69": {
                "Precision": 0.9271,
                "Recall": 0.9468,
                "Specificity": 0.9994,
                "F1 score": 0.9368
            },
            "7": {
                "Precision": 0.9712,
                "Recall": 0.9619,
                "Specificity": 0.9998,
                "F1 score": 0.9665
            },
            "70": {
                "Precision": 0.9619,
                "Recall": 0.9712,
                "Specificity": 0.9997,
                "F1 score": 0.9665
            },
            "71": {
                "Precision": 0.7763,
                "Recall": 0.8613,
                "Specificity": 0.9973,
                "F1 score": 0.8166
            },
            "72": {
                "Precision": 0.9277,
                "Recall": 0.9222,
                "Specificity": 0.999,
                "F1 score": 0.9249
            },
            "73": {
                "Precision": 0.8358,
                "Recall": 0.8522,
                "Specificity": 0.9937,
                "F1 score": 0.8439
            },
            "74": {
                "Precision": 0.871,
                "Recall": 0.864,
                "Specificity": 0.9987,
                "F1 score": 0.8675
            },
            "75": {
                "Precision": 0.9051,
                "Recall": 0.8725,
                "Specificity": 0.9977,
                "F1 score": 0.8885
            },
            "76": {
                "Precision": 1.0,
                "Recall": 0.9916,
                "Specificity": 1.0,
                "F1 score": 0.9958
            },
            "77": {
                "Precision": 0.9225,
                "Recall": 0.8561,
                "Specificity": 0.9992,
                "F1 score": 0.8881
            },
            "78": {
                "Precision": 0.9398,
                "Recall": 0.907,
                "Specificity": 0.9996,
                "F1 score": 0.9231
            },
            "79": {
                "Precision": 0.9576,
                "Recall": 0.9576,
                "Specificity": 0.9996,
                "F1 score": 0.9576
            },
            "8": {
                "Precision": 0.9048,
                "Recall": 0.8736,
                "Specificity": 0.9994,
                "F1 score": 0.8889
            },
            "80": {
                "Precision": 0.9803,
                "Recall": 0.9739,
                "Specificity": 0.9998,
                "F1 score": 0.9771
            },
            "81": {
                "Precision": 0.9032,
                "Recall": 0.8317,
                "Specificity": 0.9993,
                "F1 score": 0.866
            },
            "82": {
                "Precision": 0.9244,
                "Recall": 0.8209,
                "Specificity": 0.9993,
                "F1 score": 0.8696
            },
            "83": {
                "Precision": 0.9151,
                "Recall": 0.8661,
                "Specificity": 0.9993,
                "F1 score": 0.8899
            },
            "84": {
                "Precision": 0.9394,
                "Recall": 1.0,
                "Specificity": 0.9998,
                "F1 score": 0.9688
            },
            "85": {
                "Precision": 0.9062,
                "Recall": 1.0,
                "Specificity": 0.9998,
                "F1 score": 0.9508
            },
            "86": {
                "Precision": 0.7812,
                "Recall": 0.8333,
                "Specificity": 0.9978,
                "F1 score": 0.8064
            },
            "87": {
                "Precision": 0.8725,
                "Recall": 0.8904,
                "Specificity": 0.9985,
                "F1 score": 0.8814
            },
            "88": {
                "Precision": 0.95,
                "Recall": 0.9896,
                "Specificity": 0.9996,
                "F1 score": 0.9694
            },
            "89": {
                "Precision": 0.8776,
                "Recall": 0.9348,
                "Specificity": 0.9995,
                "F1 score": 0.9053
            },
            "9": {
                "Precision": 0.9213,
                "Recall": 0.9762,
                "Specificity": 0.9994,
                "F1 score": 0.948
            },
            "90": {
                "Precision": 0.9505,
                "Recall": 0.9057,
                "Specificity": 0.9996,
                "F1 score": 0.9276
            },
            "91": {
                "Precision": 0.9292,
                "Recall": 0.9459,
                "Specificity": 0.9994,
                "F1 score": 0.9375
            },
            "92": {
                "Precision": 0.9565,
                "Recall": 0.9167,
                "Specificity": 0.9999,
                "F1 score": 0.9362
            },
            "93": {
                "Precision": 0.9773,
                "Recall": 0.9281,
                "Specificity": 0.9998,
                "F1 score": 0.9521
            },
            "94": {
                "Precision": 0.8571,
                "Recall": 0.8244,
                "Specificity": 0.9986,
                "F1 score": 0.8404
            },
            "95": {
                "Precision": 0.864,
                "Recall": 0.8504,
                "Specificity": 0.9987,
                "F1 score": 0.8571
            },
            "96": {
                "Precision": 0.8987,
                "Recall": 0.71,
                "Specificity": 0.9994,
                "F1 score": 0.7933
            },
            "97": {
                "Precision": 0.875,
                "Recall": 0.8537,
                "Specificity": 0.9996,
                "F1 score": 0.8642
            },
            "98": {
                "Precision": 0.9714,
                "Recall": 1.0,
                "Specificity": 0.9999,
                "F1 score": 0.9855
            },
            "99": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "mean precision": 0.9362067307692311,
            "mean recall": 0.9250490384615382,
            "mean specificity": 0.9990980769230762,
            "mean f1 score": 0.9293653846153844
        },
        "valid info": {
            "accuracy": 0.725484913791149,
            "0": {
                "Precision": 0.7955,
                "Recall": 0.8861,
                "Specificity": 0.995,
                "F1 score": 0.8384
            },
            "1": {
                "Precision": 1.0,
                "Recall": 0.8571,
                "Specificity": 1.0,
                "F1 score": 0.9231
            },
            "10": {
                "Precision": 0.6,
                "Recall": 0.6,
                "Specificity": 0.9956,
                "F1 score": 0.6
            },
            "100": {
                "Precision": 0.75,
                "Recall": 0.6667,
                "Specificity": 0.9995,
                "F1 score": 0.7059
            },
            "101": {
                "Precision": 1.0,
                "Recall": 0.8571,
                "Specificity": 1.0,
                "F1 score": 0.9231
            },
            "102": {
                "Precision": 0.5038,
                "Recall": 0.5877,
                "Specificity": 0.9817,
                "F1 score": 0.5425
            },
            "103": {
                "Precision": 0.6082,
                "Recall": 0.6898,
                "Specificity": 0.9725,
                "F1 score": 0.6464
            },
            "11": {
                "Precision": 0.9167,
                "Recall": 0.8462,
                "Specificity": 0.9997,
                "F1 score": 0.88
            },
            "12": {
                "Precision": 1.0,
                "Recall": 0.8148,
                "Specificity": 1.0,
                "F1 score": 0.898
            },
            "13": {
                "Precision": 0.8077,
                "Recall": 0.8182,
                "Specificity": 0.9959,
                "F1 score": 0.8129
            },
            "14": {
                "Precision": 0.871,
                "Recall": 0.8182,
                "Specificity": 0.9978,
                "F1 score": 0.8438
            },
            "15": {
                "Precision": 0.5714,
                "Recall": 0.6667,
                "Specificity": 0.9992,
                "F1 score": 0.6154
            },
            "16": {
                "Precision": 0.9333,
                "Recall": 0.875,
                "Specificity": 0.9997,
                "F1 score": 0.9032
            },
            "17": {
                "Precision": 0.9,
                "Recall": 0.6429,
                "Specificity": 0.9997,
                "F1 score": 0.75
            },
            "18": {
                "Precision": 0.6071,
                "Recall": 0.6538,
                "Specificity": 0.997,
                "F1 score": 0.6296
            },
            "19": {
                "Precision": 0.625,
                "Recall": 0.625,
                "Specificity": 0.9992,
                "F1 score": 0.625
            },
            "2": {
                "Precision": 0.6667,
                "Recall": 0.3333,
                "Specificity": 0.9997,
                "F1 score": 0.4444
            },
            "20": {
                "Precision": 0.5,
                "Recall": 0.5,
                "Specificity": 0.9992,
                "F1 score": 0.5
            },
            "21": {
                "Precision": 0.6786,
                "Recall": 0.6786,
                "Specificity": 0.9976,
                "F1 score": 0.6786
            },
            "22": {
                "Precision": 0.8571,
                "Recall": 0.8571,
                "Specificity": 0.9995,
                "F1 score": 0.8571
            },
            "23": {
                "Precision": 1.0,
                "Recall": 0.6667,
                "Specificity": 1.0,
                "F1 score": 0.8
            },
            "24": {
                "Precision": 0.9,
                "Recall": 0.75,
                "Specificity": 0.9995,
                "F1 score": 0.8182
            },
            "25": {
                "Precision": 0.6667,
                "Recall": 0.75,
                "Specificity": 0.9976,
                "F1 score": 0.7059
            },
            "26": {
                "Precision": 0.8333,
                "Recall": 0.8333,
                "Specificity": 0.9997,
                "F1 score": 0.8333
            },
            "27": {
                "Precision": 1.0,
                "Recall": 0.9,
                "Specificity": 1.0,
                "F1 score": 0.9474
            },
            "28": {
                "Precision": 0.9615,
                "Recall": 0.7353,
                "Specificity": 0.9997,
                "F1 score": 0.8333
            },
            "29": {
                "Precision": 0.5833,
                "Recall": 0.6562,
                "Specificity": 0.9959,
                "F1 score": 0.6176
            },
            "3": {
                "Precision": 0.3333,
                "Recall": 0.1667,
                "Specificity": 0.9995,
                "F1 score": 0.2222
            },
            "30": {
                "Precision": 0.5357,
                "Recall": 0.4839,
                "Specificity": 0.9965,
                "F1 score": 0.5085
            },
            "31": {
                "Precision": 0.5714,
                "Recall": 0.5714,
                "Specificity": 0.9992,
                "F1 score": 0.5714
            },
            "32": {
                "Precision": 1.0,
                "Recall": 0.7143,
                "Specificity": 1.0,
                "F1 score": 0.8333
            },
            "33": {
                "Precision": 0.5714,
                "Recall": 0.6667,
                "Specificity": 0.9992,
                "F1 score": 0.6154
            },
            "34": {
                "Precision": 0.7143,
                "Recall": 1.0,
                "Specificity": 0.9995,
                "F1 score": 0.8333
            },
            "35": {
                "Precision": 1.0,
                "Recall": 0.7273,
                "Specificity": 1.0,
                "F1 score": 0.8421
            },
            "36": {
                "Precision": 0.8947,
                "Recall": 1.0,
                "Specificity": 0.9995,
                "F1 score": 0.9444
            },
            "37": {
                "Precision": 0.875,
                "Recall": 0.875,
                "Specificity": 0.9997,
                "F1 score": 0.875
            },
            "38": {
                "Precision": 1.0,
                "Recall": 0.4,
                "Specificity": 1.0,
                "F1 score": 0.5714
            },
            "39": {
                "Precision": 0.8571,
                "Recall": 0.5714,
                "Specificity": 0.9995,
                "F1 score": 0.6857
            },
            "4": {
                "Precision": 0.6858,
                "Recall": 0.7561,
                "Specificity": 0.9798,
                "F1 score": 0.7192
            },
            "40": {
                "Precision": 0.7059,
                "Recall": 0.6667,
                "Specificity": 0.9986,
                "F1 score": 0.6857
            },
            "41": {
                "Precision": 0.6774,
                "Recall": 0.75,
                "Specificity": 0.9973,
                "F1 score": 0.7119
            },
            "42": {
                "Precision": 1.0,
                "Recall": 0.4444,
                "Specificity": 1.0,
                "F1 score": 0.6153
            },
            "43": {
                "Precision": 0.8636,
                "Recall": 0.5937,
                "Specificity": 0.9992,
                "F1 score": 0.7037
            },
            "44": {
                "Precision": 0.8333,
                "Recall": 1.0,
                "Specificity": 0.9997,
                "F1 score": 0.9091
            },
            "45": {
                "Precision": 0.8085,
                "Recall": 0.76,
                "Specificity": 0.9975,
                "F1 score": 0.7835
            },
            "46": {
                "Precision": 0.7778,
                "Recall": 0.7568,
                "Specificity": 0.9978,
                "F1 score": 0.7672
            },
            "47": {
                "Precision": 0.7308,
                "Recall": 0.75,
                "Specificity": 0.9942,
                "F1 score": 0.7403
            },
            "48": {
                "Precision": 0.7627,
                "Recall": 0.7317,
                "Specificity": 0.9922,
                "F1 score": 0.7469
            },
            "49": {
                "Precision": 0.6789,
                "Recall": 0.7866,
                "Specificity": 0.9828,
                "F1 score": 0.7288
            },
            "5": {
                "Precision": 0.9,
                "Recall": 0.72,
                "Specificity": 0.9995,
                "F1 score": 0.8
            },
            "50": {
                "Precision": 0.5846,
                "Recall": 0.6552,
                "Specificity": 0.9926,
                "F1 score": 0.6179
            },
            "51": {
                "Precision": 0.75,
                "Recall": 0.6,
                "Specificity": 0.9984,
                "F1 score": 0.6667
            },
            "52": {
                "Precision": 0.5385,
                "Recall": 0.6364,
                "Specificity": 0.9951,
                "F1 score": 0.5834
            },
            "53": {
                "Precision": 0.8649,
                "Recall": 0.7164,
                "Specificity": 0.9958,
                "F1 score": 0.7837
            },
            "54": {
                "Precision": 0.8462,
                "Recall": 1.0,
                "Specificity": 0.9995,
                "F1 score": 0.9167
            },
            "55": {
                "Precision": 0.8421,
                "Recall": 0.9412,
                "Specificity": 0.9992,
                "F1 score": 0.8889
            },
            "56": {
                "Precision": 0.7727,
                "Recall": 0.6538,
                "Specificity": 0.9986,
                "F1 score": 0.7083
            },
            "57": {
                "Precision": 0.9444,
                "Recall": 0.9444,
                "Specificity": 0.9997,
                "F1 score": 0.9444
            },
            "58": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "59": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "6": {
                "Precision": 0.8,
                "Recall": 0.8,
                "Specificity": 0.9997,
                "F1 score": 0.8
            },
            "60": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "61": {
                "Precision": 0.5714,
                "Recall": 0.5,
                "Specificity": 0.9992,
                "F1 score": 0.5333
            },
            "62": {
                "Precision": 0.76,
                "Recall": 0.7037,
                "Specificity": 0.9984,
                "F1 score": 0.7308
            },
            "63": {
                "Precision": 0.8889,
                "Recall": 1.0,
                "Specificity": 0.9997,
                "F1 score": 0.9412
            },
            "64": {
                "Precision": 0.9375,
                "Recall": 0.9375,
                "Specificity": 0.9997,
                "F1 score": 0.9375
            },
            "65": {
                "Precision": 1.0,
                "Recall": 1.0,
                "Specificity": 1.0,
                "F1 score": 1.0
            },
            "66": {
                "Precision": 0.6667,
                "Recall": 0.3333,
                "Specificity": 0.9997,
                "F1 score": 0.4444
            },
            "67": {
                "Precision": 0.7661,
                "Recall": 0.7325,
                "Specificity": 0.9854,
                "F1 score": 0.7489
            },
            "68": {
                "Precision": 0.5421,
                "Recall": 0.7632,
                "Specificity": 0.9865,
                "F1 score": 0.6339
            },
            "69": {
                "Precision": 0.9048,
                "Recall": 0.7037,
                "Specificity": 0.9995,
                "F1 score": 0.7917
            },
            "7": {
                "Precision": 0.8667,
                "Recall": 0.8387,
                "Specificity": 0.9989,
                "F1 score": 0.8525
            },
            "70": {
                "Precision": 0.7407,
                "Recall": 0.6667,
                "Specificity": 0.9981,
                "F1 score": 0.7018
            },
            "71": {
                "Precision": 0.6316,
                "Recall": 0.6,
                "Specificity": 0.9962,
                "F1 score": 0.6154
            },
            "72": {
                "Precision": 0.7321,
                "Recall": 0.8367,
                "Specificity": 0.9959,
                "F1 score": 0.7809
            },
            "73": {
                "Precision": 0.5443,
                "Recall": 0.6418,
                "Specificity": 0.9799,
                "F1 score": 0.589
            },
            "74": {
                "Precision": 0.7105,
                "Recall": 0.75,
                "Specificity": 0.997,
                "F1 score": 0.7297
            },
            "75": {
                "Precision": 0.7412,
                "Recall": 0.7079,
                "Specificity": 0.9939,
                "F1 score": 0.7242
            },
            "76": {
                "Precision": 1.0,
                "Recall": 0.8857,
                "Specificity": 1.0,
                "F1 score": 0.9394
            },
            "77": {
                "Precision": 0.7568,
                "Recall": 0.6829,
                "Specificity": 0.9975,
                "F1 score": 0.718
            },
            "78": {
                "Precision": 0.9048,
                "Recall": 0.76,
                "Specificity": 0.9995,
                "F1 score": 0.8261
            },
            "79": {
                "Precision": 0.8889,
                "Recall": 0.7059,
                "Specificity": 0.9992,
                "F1 score": 0.7869
            },
            "8": {
                "Precision": 0.6897,
                "Recall": 0.8,
                "Specificity": 0.9976,
                "F1 score": 0.7408
            },
            "80": {
                "Precision": 0.9444,
                "Recall": 0.7556,
                "Specificity": 0.9995,
                "F1 score": 0.8395
            },
            "81": {
                "Precision": 0.8235,
                "Recall": 0.4828,
                "Specificity": 0.9992,
                "F1 score": 0.6087
            },
            "82": {
                "Precision": 0.6585,
                "Recall": 0.6923,
                "Specificity": 0.9962,
                "F1 score": 0.675
            },
            "83": {
                "Precision": 0.6786,
                "Recall": 0.5758,
                "Specificity": 0.9976,
                "F1 score": 0.623
            },
            "84": {
                "Precision": 1.0,
                "Recall": 0.6667,
                "Specificity": 1.0,
                "F1 score": 0.8
            },
            "85": {
                "Precision": 1.0,
                "Recall": 0.8889,
                "Specificity": 1.0,
                "F1 score": 0.9412
            },
            "86": {
                "Precision": 0.7407,
                "Recall": 0.5714,
                "Specificity": 0.9981,
                "F1 score": 0.6451
            },
            "87": {
                "Precision": 0.6957,
                "Recall": 0.7442,
                "Specificity": 0.9962,
                "F1 score": 0.7191
            },
            "88": {
                "Precision": 0.9259,
                "Recall": 0.8929,
                "Specificity": 0.9995,
                "F1 score": 0.9091
            },
            "89": {
                "Precision": 0.8182,
                "Recall": 0.6923,
                "Specificity": 0.9995,
                "F1 score": 0.75
            },
            "9": {
                "Precision": 0.84,
                "Recall": 0.875,
                "Specificity": 0.9989,
                "F1 score": 0.8571
            },
            "90": {
                "Precision": 0.875,
                "Recall": 0.4516,
                "Specificity": 0.9995,
                "F1 score": 0.5957
            },
            "91": {
                "Precision": 0.7576,
                "Recall": 0.7812,
                "Specificity": 0.9978,
                "F1 score": 0.7692
            },
            "92": {
                "Precision": 0.8571,
                "Recall": 0.8571,
                "Specificity": 0.9997,
                "F1 score": 0.8571
            },
            "93": {
                "Precision": 0.7255,
                "Recall": 0.9024,
                "Specificity": 0.9962,
                "F1 score": 0.8043
            },
            "94": {
                "Precision": 0.6512,
                "Recall": 0.7368,
                "Specificity": 0.9959,
                "F1 score": 0.6914
            },
            "95": {
                "Precision": 0.6286,
                "Recall": 0.5946,
                "Specificity": 0.9965,
                "F1 score": 0.6111
            },
            "96": {
                "Precision": 0.5714,
                "Recall": 0.5517,
                "Specificity": 0.9967,
                "F1 score": 0.5614
            },
            "97": {
                "Precision": 0.7778,
                "Recall": 0.5833,
                "Specificity": 0.9995,
                "F1 score": 0.6667
            },
            "98": {
                "Precision": 0.8333,
                "Recall": 1.0,
                "Specificity": 0.9995,
                "F1 score": 0.9091
            },
            "99": {
                "Precision": 0.7778,
                "Recall": 1.0,
                "Specificity": 0.9995,
                "F1 score": 0.875
            },
            "mean precision": 0.7854182692307694,
            "mean recall": 0.7331990384615386,
            "mean specificity": 0.9972884615384617,
            "mean f1 score": 0.7497365384615383
        }
    }

训练集和测试集的混淆矩阵:这里类别太多了,显示的有点密集

2.4 推理

推理是指没有标签,只有图片数据的情况下对数据的预测,这里直接运行predict脚本即可

需要把待推理的数据放在 inference/img 

3. 下载

关于本项目代码和数据集、训练结果的下载:图像分类实战:EfficientNet轻量级网络实现的迁移学习、图像识别项目:大型104种常见花种类识别资源-CSDN文库

关于图像分类网络的改进可以参考:

改进系列_Ai 医学图像分割的博客-CSDN博客

图像分类网络改进_Ai 医学图像分割的博客-CSDN博客


网站公告

今日签到

点亮在社区的每一天
去签到