├── .idea ├── .gitignore ├── deployment.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── 项目页面.iml ├── README.md ├── UI ├── .idea │ ├── .gitignore │ ├── UI.iml │ ├── deployment.xml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── misc.xml │ └── modules.xml ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── cut_pcap.cpython-38.pyc │ ├── picture_rc.cpython-38.pyc │ ├── title.cpython-38.pyc │ └── ui2.cpython-38.pyc ├── cut_pcap.py └── resources │ ├── OCR-orange.png │ ├── OCR识别异常记录.png │ ├── camera.png │ ├── exit.png │ ├── label_pic.png │ ├── min.png │ ├── picture_rc.py │ ├── restore.png │ ├── short.png │ ├── ui2.py │ ├── ui2.ui │ ├── 停止.png │ ├── 出口.png │ ├── 图片.png │ ├── 执行.png │ ├── 拍照.png │ ├── 效果.png │ ├── 文字 (1).png │ ├── 文字.png │ ├── 极速响应.png │ ├── 极速识别.png │ ├── 相机.png │ ├── 识别.png │ ├── 识别图标.png │ └── 风车.png ├── __pycache__ ├── menu.cpython-37.pyc ├── menu.cpython-38.pyc ├── nets.cpython-38.pyc ├── picture_rc.cpython-38.pyc ├── predict.cpython-38.pyc ├── predict_c.cpython-38.pyc ├── predict_c_2.cpython-38.pyc ├── prepare.cpython-38.pyc ├── title.cpython-38.pyc └── ui2.cpython-38.pyc ├── benign.pkl ├── data ├── show_data.csv ├── show_data.xls ├── show_label.csv ├── shown.csv └── shown_finall.csv ├── dataprocess ├── NetDataPrcoess.py ├── __init__.py ├── __pycache__ │ ├── NetDataPrcoess.cpython-38.pyc │ ├── __init__.cpython-38.pyc │ └── datasave.cpython-38.pyc ├── datasave.py ├── test_data.csv └── test_data.xls ├── list.txt ├── menu.py ├── menu.spec ├── model ├── pridect │ └── model_best.pth.tar ├── pridect_Pccn │ └── model_best.pth.tar └── pridect_tpcnn │ └── model_best.pth.tar ├── nets.py ├── picture.qrc ├── picture_rc.py ├── predict_c_2.py ├── prepare.py ├── save.csv ├── save.pkl ├── sniff.py ├── test_data.csv ├── test_data.xls ├── title.py ├── ui2.py └── ui2.ui /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../../../:\seafile\downloadfile\project\项目页面\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/deployment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/项目页面.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Network-anomaly-detection-with-deep-learning-along-with-UI 2 | 3 | 2023年3/30 更新 4 | 5 | 更改了net.py 中 在view或reshape时,输入的模型形状,不再设置为一个定值64,而是用out.size(0)代替 6 | 7 | ``` 8 | 关于我项目的简要介绍可以看一下我的博客: 9 | https://blog.csdn.net/weixin_39032619/article/details/120337693 10 | ``` 11 | 12 | 项目基于pytorch,PyQt 13 | 14 | 在运行项目前,请先安装winpcap以对网络流量进行嗅探。 15 | 16 | ``` 17 | 安装目录:https://www.winpcap.org/ 18 | ``` 19 | 20 | # 文件夹功能 21 | 22 | dataprocess 文件夹负责对将pacp文件进行处理为我们所需要的源文件。 23 | 24 | UI 文件夹包含页面的图片资源。 25 | 26 | model包含我们所训练的三个模型 27 | 28 | NetData 中,我们将网络流量包切成多个数据流并保存在txt文件内 29 | 30 | # 文件功能的介绍 31 | 32 | - menu.py是项目主文件,主要是项目逻辑的运行和一些按钮功能的关联 33 | - ui.py 是基于ui.ui,使用QTdesigner生成的文件,不能改动。如果想改动需要在ui.ui上进行改动QTdesigner的部署可以自己上网搜一下,可以通过可视化界面完成一些简要的搭建 34 | 35 | - sniff.py负责读取当前网络流 36 | 37 | - prepare.py 是负责读取处理后的流量数据并转换为pytorch的tensor 38 | 39 | - net.py 是网络模型代码 40 | 41 | 这里只包含了模型结构还有训练好的模型,训练过程的代码还有数据集我之后再上传到github。 42 | 43 | 虽然代码写的稀烂,不过请大家不要吝啬自己的star,算是给我写代码的认可。 44 | 45 | 46 | 47 | 项目运行结果: 48 | 49 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/c7358132a5d24132a6a00073700cb9e2.gif#pic_center#pic_center) -------------------------------------------------------------------------------- /UI/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../../../../:\seafile\downloadfile\project\program\UI\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /UI/.idea/UI.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UI/.idea/deployment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /UI/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /UI/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UI/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UI/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__init__.py -------------------------------------------------------------------------------- /UI/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /UI/__pycache__/cut_pcap.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__pycache__/cut_pcap.cpython-38.pyc -------------------------------------------------------------------------------- /UI/__pycache__/picture_rc.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__pycache__/picture_rc.cpython-38.pyc -------------------------------------------------------------------------------- /UI/__pycache__/title.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__pycache__/title.cpython-38.pyc -------------------------------------------------------------------------------- /UI/__pycache__/ui2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/__pycache__/ui2.cpython-38.pyc -------------------------------------------------------------------------------- /UI/cut_pcap.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | import pandas as pd 3 | import numpy as np 4 | import multiprocessing as mp 5 | 6 | 7 | def cap_quinturple(p) : 8 | global srcip, dstip, proto, sport, dport 9 | data={} 10 | if p.haslayer('IP'): #6:TCP 17:UDP 1:ICMP 11 | srcip = p['IP'].src 12 | dstip = p['IP'].dst 13 | proto = p['IP'].proto 14 | if hasattr(p['IP'],'sport') and hasattr(p['IP'], 'dport'): 15 | sport = p['IP'].sport 16 | dport = p['IP'].dport 17 | else: 18 | sport = 0 19 | dport = 0 20 | 21 | data["srcip"] = srcip 22 | data["dstip"] = dstip 23 | data["proto"] = proto 24 | data["sport"] = sport 25 | data["dport"] = dport 26 | data['data'] = str(p) #将数据本身存入 27 | # 如果没有IP层 28 | else: 29 | data["srcip"] = 0 30 | data["dstip"] = 0 31 | data["proto"] = 0 32 | data["sport"] = 0 33 | data["dport"] = 0 34 | data['data'] = str(p) # 将数据本身存入 35 | 36 | return data 37 | 38 | def df2csv(df,fname,mats=[],sep=','): # 只追加前5列的数据,最后的data部分单独追加 39 | 40 | if len(df.columns) <= 0: 41 | return 42 | Nd = len(df.columns) 43 | Nd_1 = Nd - 1 44 | formats = mats[:] 45 | Nf = len(formats) 46 | # 确保对每个列都有对应的格式 47 | if Nf < Nd: 48 | for ii in range(Nf,Nd): 49 | coltype = df[df.columns[ii]].dtype 50 | ff = '%s' 51 | if coltype == np.int64: 52 | ff = '%d' 53 | elif coltype == np.float64: 54 | ff = '%f' 55 | formats.append(ff) 56 | fh=open(fname,'w') 57 | fh.write(','.join(df.columns) + '\n') 58 | for row in df.itertuples(index=False): 59 | ss = '' 60 | for ii in range(Nd): 61 | if ii==Nd_1: 62 | # 因为原本的data数据里面有非常多的逗号(,)会影响切割csv的判断,所以我们在data前面添加双引号, 63 | # 同时data内部的"可能影响整体的判定,所以将单个双引号替换为2个双引号,只保留其作为单纯双引号的意义 64 | ss += "\""+row[ii].replace("\"","\"\"")+"\"" 65 | continue 66 | ss += formats[ii] % row[ii] 67 | # ss += str(row[ii]) 68 | if ii < Nd_1: 69 | ss += sep 70 | fh.write(ss+'\n') 71 | fh.close() 72 | 73 | 74 | class pcap_cut(): 75 | def __init__(self,): 76 | super(pcap_cut, self).__init__() 77 | # self.filename = filename 78 | # self.pool = pool 79 | # insert_part[0].hide() 80 | # insert_part[1].setText('程序正在执行,请稍等') 81 | # insert_part[2].show() 82 | def cap_quinturple(self,p): 83 | global srcip, dstip, proto, sport, dport 84 | data = {} 85 | if p.haslayer('IP'): # 6:TCP 17:UDP 1:ICMP 86 | srcip = p['IP'].src 87 | dstip = p['IP'].dst 88 | proto = p['IP'].proto 89 | if hasattr(p['IP'], 'sport') and hasattr(p['IP'], 'dport'): 90 | sport = p['IP'].sport 91 | dport = p['IP'].dport 92 | else: 93 | sport = 0 94 | dport = 0 95 | 96 | data["srcip"] = srcip 97 | data["dstip"] = dstip 98 | data["proto"] = proto 99 | data["sport"] = sport 100 | data["dport"] = dport 101 | data['data'] = str(p) # 将数据本身存入 102 | # 如果没有IP层 103 | else: 104 | data["srcip"] = 0 105 | data["dstip"] = 0 106 | data["proto"] = 0 107 | data["sport"] = 0 108 | data["dport"] = 0 109 | data['data'] = str(p) # 将数据本身存入 110 | 111 | return data 112 | 113 | 114 | 115 | def judge(self, quinturple, sum): # 判断数据包的五元组是否符合异常流量的五元组 116 | 117 | sum[0].append(quinturple['srcip']) 118 | sum[1].append(quinturple['dstip']) 119 | sum[2].append(quinturple['sport']) 120 | sum[3].append(quinturple['dport']) 121 | sum[4].append(quinturple['proto']) 122 | sum[5].append(quinturple['data']) 123 | 124 | return True 125 | 126 | def spilt_pcap(self, spr, sum): # 根据五元组切割pcap 127 | ''' 128 | 129 | :param spr: 传入的检测流量 130 | :param sum: 异常流量集合 131 | :return: sum 132 | ''' 133 | length = len(spr) 134 | 135 | for i in range(0, length): 136 | quinturple = cap_quinturple(spr[i]) 137 | self.judge(quinturple, sum) # 步长为1,逐个提取当前流量 138 | print(i) 139 | return sum 140 | 141 | def read_pcap2(self,savename,pool,num=20): # 一次性全部读入 142 | # df = pd.read_excel('./csv_labels/TestbedSatJun12Flows.xlsx', sheet_name='attack2', 143 | # usecols=[4, 5, 6, 7, 8]) # 读取xlsx文件的attack页 144 | # df = pd.read_csv(self.csv_file) # 读取xlsx文件的attack页 145 | filterstr = "tcp || udp" 146 | pr = sniff(filter=filterstr, count=num) 147 | print('截取流量成功') 148 | # pr = rdpcap(self.filename) 149 | # print('读取pcap文件成功 \n') 150 | L = len(pr) 151 | sip = [] # 创建数组储存所有的源ip 152 | dst = [] # 创建数组储存所有目的ip 153 | sp = [] # 创建数组储存所有源端口 154 | dp = [] 155 | pro = [] 156 | store = [] 157 | label = [] 158 | sum1 = [[], [], [], [], [], [], []] 159 | 160 | sum2 = [sip, dst, sp, dp, pro, store, label] 161 | sum3 = [sip, dst, sp, dp, pro, store, label] 162 | 163 | count = 0 164 | param_dict = {'task1': pr[0:int(L / 10)], 165 | 'task2': pr[int(L / 10):int(2 * L / 10)], 166 | 'task3': pr[int(2 * L / 10):int(3 * L / 10)], 167 | 'task4': pr[int(3 * L / 10):int(4 * L / 10)], 168 | 'task5': pr[int(4 * L / 10):int(5 * L / 10)], 169 | 'task6': pr[int(5 * L / 10):int(6 * L / 10)], 170 | 'task7': pr[int(6 * L / 10):int(7 * L / 10)], 171 | 'task8': pr[int(7 * L / 10):int(8 * L / 10)], 172 | 'task9': pr[int(8 * L / 10):int(9 * L / 10)], 173 | 'task10': pr[int(9 * L / 10):L]} 174 | # 使用多进程处理数据集 175 | results = [pool.apply_async(self.spilt_pcap, args=( param, sum1.copy())) for name, param in param_dict.items()] 176 | sum2 = [p.get() for p in results] 177 | # print(sum2) 178 | # 将sum2里面所有数组合并到sum3内 179 | [sum3[j].extend(sum2[idx][j]) for idx, value in enumerate(sum2) for j in range(len(value))] 180 | df1 = pd.DataFrame({'srcip': sum3[0], 'dstip': sum3[1], 'sport': sum3[2], 'dport': sum3[3], 'proto': sum3[4], 181 | 'data': sum3[5], }, ) # 创建dataFrame储存,每一列储存对应的数值 182 | # df1.to_excel('Tuesday.xlsx', index=False) 183 | # df1.to_csv(savename, index=False) 184 | df1.to_pickle(savename) 185 | # df2csv(df1, 'junk4.csv',myformats=['%s', '%s', '%d', '%d','%d',"%s"]) # 7.5 sec 186 | df2csv(df1, 'save.csv',) # 187 | return df1 # 将函数返回 188 | 189 | 190 | 191 | 192 | if __name__ == '__main__': 193 | 194 | # file = './spilt/2017/Tuesday/' + os.listdir(r'./spilt/2017/Tuesday')[5] 195 | file = './new.pcap' 196 | # csv_file = r'./csv_labels/2017/extract/Friday.csv' 197 | print(file) 198 | # 在类中把进程池pool设为成员变量,即self.pool,同时把self作为参数传给线程池中的函数的时候会报错,所以尽量在外部定义pool 199 | num_cores = int(mp.cpu_count()) 200 | print("本地计算机有: " + str(num_cores) + " 核心") 201 | pool = mp.Pool(num_cores) 202 | 203 | start = time.time() 204 | a = pcap_cut(file) 205 | a.read_pcap2('benign.csv',pool) 206 | # read_pcap2(file) 207 | end = time.time() 208 | print("运行时间:%.2f" % (end - start)) 209 | 210 | # a=pd.read_pickle('benign.pkl') 211 | # a=pd.read_csv('junk3.csv') 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /UI/resources/OCR-orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/OCR-orange.png -------------------------------------------------------------------------------- /UI/resources/OCR识别异常记录.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/OCR识别异常记录.png -------------------------------------------------------------------------------- /UI/resources/camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/camera.png -------------------------------------------------------------------------------- /UI/resources/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/exit.png -------------------------------------------------------------------------------- /UI/resources/label_pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/label_pic.png -------------------------------------------------------------------------------- /UI/resources/min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/min.png -------------------------------------------------------------------------------- /UI/resources/restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/restore.png -------------------------------------------------------------------------------- /UI/resources/short.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/short.png -------------------------------------------------------------------------------- /UI/resources/ui2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'ui2.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.14.0 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | 10 | from PyQt5 import QtCore, QtGui, QtWidgets 11 | 12 | 13 | class Ui_Unframewindow(object): 14 | def setupUi(self, Unframewindow): 15 | Unframewindow.setObjectName("Unframewindow") 16 | Unframewindow.setWindowModality(QtCore.Qt.NonModal) 17 | Unframewindow.resize(973, 759) 18 | Unframewindow.setMouseTracking(True) 19 | Unframewindow.setStatusTip("") 20 | Unframewindow.setAutoFillBackground(False) 21 | Unframewindow.setStyleSheet("QListWidget, QListView, QTreeWidget, QTreeView {\n" 22 | " outline: 0px;\n" 23 | "}\n" 24 | "\n" 25 | "QListWidget {\n" 26 | " \n" 27 | " color: #cccccc;\n" 28 | " background: #2e2e36;\n" 29 | "}\n" 30 | "\n" 31 | "QListWidget::Item:selected {\n" 32 | " background: #26262e;\n" 33 | " color: #fd7e19;\n" 34 | " border-left: 5px solid #fd9536;\n" 35 | " \n" 36 | "}\n" 37 | "HistoryPanel:hover {\n" 38 | " background: rgb(52, 52, 52);\n" 39 | "}\n" 40 | "/**********Title**********/\n" 41 | "QTitleLabel{\n" 42 | " background-color: Gainsboro;\n" 43 | " font: 100 10pt;\n" 44 | "}\n" 45 | "\n" 46 | "\n" 47 | "/**********Button**********/\n" 48 | "QTitleButton{\n" 49 | " background-color: rgba(255, 255, 255, 0);\n" 50 | " color: black;\n" 51 | " border: 0px;\n" 52 | " font: 100 10pt;\n" 53 | "}\n" 54 | "QTitleButton#MinButton:hover,#MaxButton:hover{\n" 55 | " background-color: #D0D0D1;\n" 56 | " border: 0px;\n" 57 | " font: 100 10pt;\n" 58 | "\n" 59 | "\n" 60 | "}\n" 61 | "\n" 62 | "QTitleButton#CloseButton:hover{\n" 63 | " background-color: #D32424;\n" 64 | " color: white;\n" 65 | " border: 0px;\n" 66 | " font: 100 10pt;\n" 67 | " \n" 68 | "}\n" 69 | "\n" 70 | "QTitleButton#MinButton{\n" 71 | " image: url(./resource/short.png);\n" 72 | " \n" 73 | "}\n" 74 | "QTitleButton#CloseButton{\n" 75 | " image: url(./resource/exit.png);\n" 76 | "}\n" 77 | "QTitleButton#MaxButton{\n" 78 | " image: url(./resource/restore.png);\n" 79 | "}\n" 80 | "\n" 81 | "\n" 82 | "") 83 | Unframewindow.setUnifiedTitleAndToolBarOnMac(False) 84 | self.centralwidget = QtWidgets.QWidget(Unframewindow) 85 | self.centralwidget.setObjectName("centralwidget") 86 | self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget) 87 | self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) 88 | self.horizontalLayout_2.setSpacing(0) 89 | self.horizontalLayout_2.setObjectName("horizontalLayout_2") 90 | self.left = QtWidgets.QWidget(self.centralwidget) 91 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding) 92 | sizePolicy.setHorizontalStretch(0) 93 | sizePolicy.setVerticalStretch(0) 94 | sizePolicy.setHeightForWidth(self.left.sizePolicy().hasHeightForWidth()) 95 | self.left.setSizePolicy(sizePolicy) 96 | self.left.setMinimumSize(QtCore.QSize(150, 0)) 97 | self.left.setMaximumSize(QtCore.QSize(150, 16777215)) 98 | self.left.setMouseTracking(True) 99 | self.left.setStyleSheet("background: #2e2e36;") 100 | self.left.setObjectName("left") 101 | self.verticalLayout = QtWidgets.QVBoxLayout(self.left) 102 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 103 | self.verticalLayout.setSpacing(0) 104 | self.verticalLayout.setObjectName("verticalLayout") 105 | self.icon_1 = QtWidgets.QLabel(self.left) 106 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 107 | sizePolicy.setHorizontalStretch(0) 108 | sizePolicy.setVerticalStretch(0) 109 | sizePolicy.setHeightForWidth(self.icon_1.sizePolicy().hasHeightForWidth()) 110 | self.icon_1.setSizePolicy(sizePolicy) 111 | self.icon_1.setMinimumSize(QtCore.QSize(150, 100)) 112 | self.icon_1.setMaximumSize(QtCore.QSize(150, 100)) 113 | self.icon_1.setMouseTracking(True) 114 | self.icon_1.setStyleSheet("image: url(:/icon/res/OCR识别异常记录.png);\n" 115 | "\n" 116 | "background-color: #2e2e36;") 117 | self.icon_1.setText("") 118 | self.icon_1.setWordWrap(False) 119 | self.icon_1.setObjectName("icon_1") 120 | self.verticalLayout.addWidget(self.icon_1) 121 | self.icon_bottom_label = QtWidgets.QLabel(self.left) 122 | self.icon_bottom_label.setMinimumSize(QtCore.QSize(120, 50)) 123 | self.icon_bottom_label.setMaximumSize(QtCore.QSize(120, 50)) 124 | font = QtGui.QFont() 125 | font.setFamily("等线") 126 | font.setBold(True) 127 | font.setWeight(75) 128 | self.icon_bottom_label.setFont(font) 129 | self.icon_bottom_label.setStyleSheet("background: #2e2e36;\n" 130 | "color: #cccccc;\n" 131 | "border-bottom:0.5px solid rgb(240, 240, 240,30%);\n" 132 | "\n" 133 | "") 134 | self.icon_bottom_label.setFrameShape(QtWidgets.QFrame.NoFrame) 135 | self.icon_bottom_label.setFrameShadow(QtWidgets.QFrame.Plain) 136 | self.icon_bottom_label.setLineWidth(0) 137 | self.icon_bottom_label.setScaledContents(False) 138 | self.icon_bottom_label.setAlignment(QtCore.Qt.AlignCenter) 139 | self.icon_bottom_label.setObjectName("icon_bottom_label") 140 | self.verticalLayout.addWidget(self.icon_bottom_label, 0, QtCore.Qt.AlignHCenter) 141 | self.left_widget = QtWidgets.QListWidget(self.left) 142 | self.left_widget.setMinimumSize(QtCore.QSize(150, 0)) 143 | self.left_widget.setMaximumSize(QtCore.QSize(150, 16777215)) 144 | self.left_widget.setBaseSize(QtCore.QSize(0, 0)) 145 | self.left_widget.setMouseTracking(True) 146 | self.left_widget.setStyleSheet("QListWidget, QListView, QTreeWidget, QTreeView {\n" 147 | " outline: 0px;\n" 148 | "}\n" 149 | "\n" 150 | "QListWidget {\n" 151 | " \n" 152 | " color: #cccccc;\n" 153 | " background: #2e2e36;\n" 154 | "}\n" 155 | "\n" 156 | "QListWidget::Item:selected {\n" 157 | " background: #26262e;\n" 158 | " color: #fd7e19;\n" 159 | " border-left: 5px solid #fd9536;\n" 160 | " \n" 161 | "}\n" 162 | "HistoryPanel:hover {\n" 163 | " background: rgb(52, 52, 52);\n" 164 | "}") 165 | self.left_widget.setFrameShape(QtWidgets.QFrame.NoFrame) 166 | self.left_widget.setSelectionRectVisible(False) 167 | self.left_widget.setObjectName("left_widget") 168 | item = QtWidgets.QListWidgetItem() 169 | item.setTextAlignment(QtCore.Qt.AlignCenter) 170 | font = QtGui.QFont() 171 | font.setBold(True) 172 | font.setWeight(75) 173 | item.setFont(font) 174 | icon = QtGui.QIcon() 175 | icon.addPixmap(QtGui.QPixmap(":/icon/test/resource/极速识别.png"), QtGui.QIcon.Selected, QtGui.QIcon.Off) 176 | icon.addPixmap(QtGui.QPixmap(":/icon/test/resource/极速响应.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 177 | item.setIcon(icon) 178 | self.left_widget.addItem(item) 179 | item = QtWidgets.QListWidgetItem() 180 | item.setTextAlignment(QtCore.Qt.AlignCenter) 181 | font = QtGui.QFont() 182 | font.setBold(True) 183 | font.setWeight(75) 184 | item.setFont(font) 185 | icon1 = QtGui.QIcon() 186 | icon1.addPixmap(QtGui.QPixmap(":/icon/test/resource/文字 (1).png"), QtGui.QIcon.Selected, QtGui.QIcon.Off) 187 | icon1.addPixmap(QtGui.QPixmap(":/icon/test/resource/文字.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 188 | item.setIcon(icon1) 189 | self.left_widget.addItem(item) 190 | self.verticalLayout.addWidget(self.left_widget) 191 | self.horizontalLayout_2.addWidget(self.left) 192 | self.right_widget = QtWidgets.QWidget(self.centralwidget) 193 | self.right_widget.setObjectName("right_widget") 194 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.right_widget) 195 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 196 | self.verticalLayout_2.setSpacing(0) 197 | self.verticalLayout_2.setObjectName("verticalLayout_2") 198 | self.label_widget = QtWidgets.QWidget(self.right_widget) 199 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Preferred) 200 | sizePolicy.setHorizontalStretch(0) 201 | sizePolicy.setVerticalStretch(0) 202 | sizePolicy.setHeightForWidth(self.label_widget.sizePolicy().hasHeightForWidth()) 203 | self.label_widget.setSizePolicy(sizePolicy) 204 | self.label_widget.setMinimumSize(QtCore.QSize(0, 40)) 205 | self.label_widget.setMaximumSize(QtCore.QSize(16777215, 40)) 206 | self.label_widget.setMouseTracking(True) 207 | self.label_widget.setStyleSheet("QWidget#label_widget{\n" 208 | " background-color: rgb(255, 255, 255);\n" 209 | " \n" 210 | "\n" 211 | "\n" 212 | "}\n" 213 | "") 214 | self.label_widget.setObjectName("label_widget") 215 | self.horizontalLayout = QtWidgets.QHBoxLayout(self.label_widget) 216 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 217 | self.horizontalLayout.setSpacing(0) 218 | self.horizontalLayout.setObjectName("horizontalLayout") 219 | spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) 220 | self.horizontalLayout.addItem(spacerItem) 221 | self.MinButton = QTitleButton(self.label_widget) 222 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 223 | sizePolicy.setHorizontalStretch(0) 224 | sizePolicy.setVerticalStretch(0) 225 | sizePolicy.setHeightForWidth(self.MinButton.sizePolicy().hasHeightForWidth()) 226 | self.MinButton.setSizePolicy(sizePolicy) 227 | self.MinButton.setMaximumSize(QtCore.QSize(40, 16777215)) 228 | self.MinButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 229 | self.MinButton.setMouseTracking(True) 230 | self.MinButton.setStyleSheet("") 231 | self.MinButton.setText("") 232 | self.MinButton.setFlat(True) 233 | self.MinButton.setObjectName("MinButton") 234 | self.horizontalLayout.addWidget(self.MinButton) 235 | self.MaxButton = QTitleButton(self.label_widget) 236 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 237 | sizePolicy.setHorizontalStretch(0) 238 | sizePolicy.setVerticalStretch(0) 239 | sizePolicy.setHeightForWidth(self.MaxButton.sizePolicy().hasHeightForWidth()) 240 | self.MaxButton.setSizePolicy(sizePolicy) 241 | self.MaxButton.setMinimumSize(QtCore.QSize(40, 0)) 242 | self.MaxButton.setMaximumSize(QtCore.QSize(40, 16777215)) 243 | self.MaxButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 244 | self.MaxButton.setMouseTracking(True) 245 | self.MaxButton.setText("") 246 | self.MaxButton.setFlat(True) 247 | self.MaxButton.setObjectName("MaxButton") 248 | self.horizontalLayout.addWidget(self.MaxButton) 249 | self.CloseButton = QTitleButton(self.label_widget) 250 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 251 | sizePolicy.setHorizontalStretch(0) 252 | sizePolicy.setVerticalStretch(0) 253 | sizePolicy.setHeightForWidth(self.CloseButton.sizePolicy().hasHeightForWidth()) 254 | self.CloseButton.setSizePolicy(sizePolicy) 255 | self.CloseButton.setMinimumSize(QtCore.QSize(40, 0)) 256 | self.CloseButton.setMaximumSize(QtCore.QSize(40, 16777215)) 257 | self.CloseButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 258 | self.CloseButton.setMouseTracking(True) 259 | self.CloseButton.setText("") 260 | self.CloseButton.setFlat(True) 261 | self.CloseButton.setObjectName("CloseButton") 262 | self.horizontalLayout.addWidget(self.CloseButton) 263 | self.verticalLayout_2.addWidget(self.label_widget) 264 | self.stack_page = QtWidgets.QStackedWidget(self.right_widget) 265 | self.stack_page.setMinimumSize(QtCore.QSize(0, 0)) 266 | self.stack_page.setObjectName("stack_page") 267 | self.page = QtWidgets.QWidget() 268 | self.page.setStyleSheet("QWidget#page{\n" 269 | " background-color: rgb(245, 249, 252);\n" 270 | "}\n" 271 | "\n" 272 | "\n" 273 | "\n" 274 | "") 275 | self.page.setObjectName("page") 276 | self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.page) 277 | self.verticalLayout_7.setObjectName("verticalLayout_7") 278 | self.label_show_camera = QtWidgets.QLabel(self.page) 279 | self.label_show_camera.setStyleSheet("background-color: rgb(255, 255, 255);\n" 280 | "image: url(:/icon/test/resource/camera.png);") 281 | self.label_show_camera.setScaledContents(False) 282 | self.label_show_camera.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft) 283 | self.label_show_camera.setObjectName("label_show_camera") 284 | self.verticalLayout_7.addWidget(self.label_show_camera) 285 | 286 | 287 | self.gridLayout = QtWidgets.QGridLayout() 288 | self.gridLayout.setHorizontalSpacing(15) 289 | self.gridLayout.setVerticalSpacing(0) 290 | self.gridLayout.setObjectName("gridLayout") 291 | self.cam_photo = QtWidgets.QPushButton(self.page) 292 | self.cam_photo.setMinimumSize(QtCore.QSize(180, 30)) 293 | self.cam_photo.setMaximumSize(QtCore.QSize(180, 30)) 294 | self.cam_photo.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 295 | self.cam_photo.setStyleSheet("\n" 296 | "QPushButton:hover\n" 297 | "{\n" 298 | " /*背景颜色*/ \n" 299 | " background-color: rgb(253, 149, 54);\n" 300 | " \n" 301 | "}\n" 302 | "QPushButton\n" 303 | "{\n" 304 | " background-color: rgb(255, 161, 75);\n" 305 | " border-radius:10px;\n" 306 | " color: rgb(255, 255, 255);\n" 307 | " border: 0px;\n" 308 | " font: 9pt \"微软雅黑\" ;\n" 309 | "}\n" 310 | "") 311 | self.cam_photo.setObjectName("cam_photo") 312 | self.gridLayout.addWidget(self.cam_photo, 0, 0, 1, 1) 313 | self.cam_project = QtWidgets.QPushButton(self.page) 314 | self.cam_project.setMinimumSize(QtCore.QSize(180, 30)) 315 | self.cam_project.setMaximumSize(QtCore.QSize(180, 30)) 316 | font = QtGui.QFont() 317 | font.setFamily("微软雅黑") 318 | font.setPointSize(9) 319 | font.setBold(False) 320 | font.setItalic(False) 321 | font.setWeight(50) 322 | self.cam_project.setFont(font) 323 | self.cam_project.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 324 | self.cam_project.setStyleSheet("\n" 325 | "QPushButton:hover\n" 326 | "{\n" 327 | " /*背景颜色*/ \n" 328 | " background-color: rgb(253, 149, 54);\n" 329 | " \n" 330 | "}\n" 331 | "QPushButton\n" 332 | "{\n" 333 | " background-color: rgb(255, 161, 75);\n" 334 | " border-radius:10px;\n" 335 | " color: rgb(255, 255, 255);\n" 336 | " border: 0px;\n" 337 | " font: 9pt \"微软雅黑\" ;\n" 338 | "}\n" 339 | "") 340 | self.cam_project.setObjectName("cam_project") 341 | self.gridLayout.addWidget(self.cam_project, 0, 3, 1, 1) 342 | self.cam_deal = QtWidgets.QPushButton(self.page) 343 | self.cam_deal.setMinimumSize(QtCore.QSize(180, 30)) 344 | self.cam_deal.setMaximumSize(QtCore.QSize(180, 30)) 345 | self.cam_deal.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 346 | self.cam_deal.setStyleSheet("\n" 347 | "QPushButton:hover\n" 348 | "{\n" 349 | " /*背景颜色*/ \n" 350 | " background-color: rgb(253, 149, 54);\n" 351 | " \n" 352 | "}\n" 353 | "QPushButton\n" 354 | "{\n" 355 | " background-color: rgb(255, 161, 75);\n" 356 | " border-radius:10px;\n" 357 | " color: rgb(255, 255, 255);\n" 358 | " border: 0px;\n" 359 | " font: 9pt \"微软雅黑\" ;\n" 360 | "}\n" 361 | "") 362 | self.cam_deal.setObjectName("cam_deal") 363 | self.gridLayout.addWidget(self.cam_deal, 0, 2, 1, 1) 364 | self.cam_open = QtWidgets.QPushButton(self.page) 365 | self.cam_open.setMinimumSize(QtCore.QSize(180, 30)) 366 | self.cam_open.setMaximumSize(QtCore.QSize(180, 30)) 367 | self.cam_open.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 368 | self.cam_open.setStyleSheet("\n" 369 | "QPushButton:hover\n" 370 | "{\n" 371 | " /*背景颜色*/ \n" 372 | " background-color: rgb(253, 149, 54);\n" 373 | " \n" 374 | "}\n" 375 | "QPushButton\n" 376 | "{\n" 377 | " background-color: rgb(255, 161, 75);\n" 378 | " border-radius:10px;\n" 379 | " color: rgb(255, 255, 255);\n" 380 | " border: 0px;\n" 381 | " font: 9pt \"微软雅黑\" ;\n" 382 | "}\n" 383 | "") 384 | self.cam_open.setObjectName("cam_open") 385 | self.gridLayout.addWidget(self.cam_open, 0, 1, 1, 1) 386 | self.verticalLayout_7.addLayout(self.gridLayout) 387 | self.cam_pic = QtWidgets.QPushButton(self.page) 388 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 389 | sizePolicy.setHorizontalStretch(20) 390 | sizePolicy.setVerticalStretch(20) 391 | sizePolicy.setHeightForWidth(self.cam_pic.sizePolicy().hasHeightForWidth()) 392 | self.cam_pic.setSizePolicy(sizePolicy) 393 | self.cam_pic.setMinimumSize(QtCore.QSize(20, 20)) 394 | self.cam_pic.setMaximumSize(QtCore.QSize(20, 20)) 395 | self.cam_pic.setText("") 396 | icon2 = QtGui.QIcon() 397 | icon2.addPixmap(QtGui.QPixmap(":/icon/图片.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 398 | self.cam_pic.setIcon(icon2) 399 | self.cam_pic.setFlat(True) 400 | self.cam_pic.setObjectName("cam_pic") 401 | self.verticalLayout_7.addWidget(self.cam_pic, 0, QtCore.Qt.AlignRight) 402 | self.verticalLayout_7.setStretch(0, 1) 403 | self.stack_page.addWidget(self.page) 404 | self.page_2 = QtWidgets.QWidget() 405 | self.page_2.setStyleSheet("QWidget{\n" 406 | " background-color: rgb(245, 249, 252);\n" 407 | "}\n" 408 | "") 409 | self.page_2.setObjectName("page_2") 410 | self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.page_2) 411 | self.verticalLayout_6.setContentsMargins(-1, -1, -1, 20) 412 | self.verticalLayout_6.setSpacing(20) 413 | self.verticalLayout_6.setObjectName("verticalLayout_6") 414 | self.widget = QtWidgets.QWidget(self.page_2) 415 | self.widget.setObjectName("widget") 416 | self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.widget) 417 | self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) 418 | self.verticalLayout_3.setSpacing(0) 419 | self.verticalLayout_3.setObjectName("verticalLayout_3") 420 | self.r_bottom_widget = QtWidgets.QWidget(self.widget) 421 | self.r_bottom_widget.setStyleSheet("") 422 | self.r_bottom_widget.setObjectName("r_bottom_widget") 423 | self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.r_bottom_widget) 424 | self.horizontalLayout_3.setContentsMargins(14, 14, 14, 14) 425 | self.horizontalLayout_3.setSpacing(15) 426 | self.horizontalLayout_3.setObjectName("horizontalLayout_3") 427 | self.pic_widget = QtWidgets.QWidget(self.r_bottom_widget) 428 | self.pic_widget.setEnabled(True) 429 | self.pic_widget.setStyleSheet("QWidget#pic_widget{\n" 430 | " border:0.5px solid lightgray; \n" 431 | " background-color: rgb(255, 255, 255);\n" 432 | "}\n" 433 | "\n" 434 | "") 435 | self.pic_widget.setObjectName("pic_widget") 436 | self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.pic_widget) 437 | self.verticalLayout_4.setSpacing(0) 438 | self.verticalLayout_4.setObjectName("verticalLayout_4") 439 | self.delete_pic = QtWidgets.QPushButton(self.pic_widget) 440 | self.delete_pic.setEnabled(True) 441 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 442 | sizePolicy.setHorizontalStretch(0) 443 | sizePolicy.setVerticalStretch(0) 444 | sizePolicy.setHeightForWidth(self.delete_pic.sizePolicy().hasHeightForWidth()) 445 | self.delete_pic.setSizePolicy(sizePolicy) 446 | self.delete_pic.setMinimumSize(QtCore.QSize(70, 30)) 447 | self.delete_pic.setMaximumSize(QtCore.QSize(70, 30)) 448 | font = QtGui.QFont() 449 | font.setFamily("微软雅黑") 450 | font.setPointSize(9) 451 | font.setBold(False) 452 | font.setItalic(False) 453 | font.setWeight(50) 454 | font.setKerning(True) 455 | self.delete_pic.setFont(font) 456 | self.delete_pic.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 457 | self.delete_pic.setStyleSheet("\n" 458 | "QPushButton:hover\n" 459 | "{\n" 460 | " /*背景颜色*/ \n" 461 | " background-color:rgb(240, 240, 240);\n" 462 | " \n" 463 | "}\n" 464 | "QPushButton\n" 465 | "{\n" 466 | " background-color: rgb(255, 255, 255);\n" 467 | " \n" 468 | " color: rgb(253, 149, 54);\n" 469 | " border: 1px solid rgb(253, 149, 54) ;\n" 470 | " border-radius:7px;\n" 471 | " font: 9pt \"微软雅黑\" ;\n" 472 | "}\n" 473 | "") 474 | self.delete_pic.setFlat(False) 475 | self.delete_pic.setObjectName("delete_pic") 476 | self.verticalLayout_4.addWidget(self.delete_pic, 0, QtCore.Qt.AlignRight) 477 | self.pic_label_1 = QtWidgets.QLabel(self.pic_widget) 478 | self.pic_label_1.setEnabled(True) 479 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 480 | sizePolicy.setHorizontalStretch(0) 481 | sizePolicy.setVerticalStretch(0) 482 | sizePolicy.setHeightForWidth(self.pic_label_1.sizePolicy().hasHeightForWidth()) 483 | self.pic_label_1.setSizePolicy(sizePolicy) 484 | self.pic_label_1.setStyleSheet("\n" 485 | "image: url(:/icon/test/resource/label_pic.png);\n" 486 | "background-color: rgb(255, 255, 255);") 487 | self.pic_label_1.setText("") 488 | self.pic_label_1.setObjectName("pic_label_1") 489 | self.verticalLayout_4.addWidget(self.pic_label_1) 490 | self.pic_label_2 = QtWidgets.QLabel(self.pic_widget) 491 | self.pic_label_2.setEnabled(True) 492 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 493 | sizePolicy.setHorizontalStretch(0) 494 | sizePolicy.setVerticalStretch(0) 495 | sizePolicy.setHeightForWidth(self.pic_label_2.sizePolicy().hasHeightForWidth()) 496 | self.pic_label_2.setSizePolicy(sizePolicy) 497 | self.pic_label_2.setMaximumSize(QtCore.QSize(16777215, 200)) 498 | self.pic_label_2.setStyleSheet("font: 9pt \"微软雅黑\";\n" 499 | "background-color: rgb(255, 255, 255);") 500 | self.pic_label_2.setObjectName("pic_label_2") 501 | self.verticalLayout_4.addWidget(self.pic_label_2) 502 | self.upload_pic = QtWidgets.QPushButton(self.pic_widget) 503 | self.upload_pic.setEnabled(True) 504 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 505 | sizePolicy.setHorizontalStretch(0) 506 | sizePolicy.setVerticalStretch(0) 507 | sizePolicy.setHeightForWidth(self.upload_pic.sizePolicy().hasHeightForWidth()) 508 | self.upload_pic.setSizePolicy(sizePolicy) 509 | self.upload_pic.setMinimumSize(QtCore.QSize(200, 50)) 510 | self.upload_pic.setMaximumSize(QtCore.QSize(200, 50)) 511 | font = QtGui.QFont() 512 | font.setFamily("微软雅黑") 513 | font.setPointSize(12) 514 | font.setBold(False) 515 | font.setItalic(False) 516 | font.setWeight(50) 517 | font.setKerning(True) 518 | self.upload_pic.setFont(font) 519 | self.upload_pic.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 520 | self.upload_pic.setStyleSheet("\n" 521 | "QPushButton:hover\n" 522 | "{\n" 523 | " /*背景颜色*/ \n" 524 | " background-color: rgb(253, 149, 54);\n" 525 | " \n" 526 | "}\n" 527 | "QPushButton\n" 528 | "{\n" 529 | " background-color: rgb(255, 161, 75);\n" 530 | " \n" 531 | " color: rgb(255, 255, 255);\n" 532 | " border: 0px;\n" 533 | " font: 11.5pt \"微软雅黑\" ;\n" 534 | "}\n" 535 | "") 536 | self.upload_pic.setFlat(False) 537 | self.upload_pic.setObjectName("upload_pic") 538 | self.verticalLayout_4.addWidget(self.upload_pic, 0, QtCore.Qt.AlignHCenter) 539 | self.spaceitem = QtWidgets.QLabel(self.pic_widget) 540 | self.spaceitem.setMinimumSize(QtCore.QSize(0, 50)) 541 | self.spaceitem.setStyleSheet("background-color: rgb(255, 255, 255);") 542 | self.spaceitem.setText("") 543 | self.spaceitem.setObjectName("spaceitem") 544 | self.verticalLayout_4.addWidget(self.spaceitem) 545 | self.verticalLayout_4.setStretch(1, 3) 546 | self.verticalLayout_4.setStretch(2, 1) 547 | self.horizontalLayout_3.addWidget(self.pic_widget) 548 | self.text_widget = QtWidgets.QWidget(self.r_bottom_widget) 549 | self.text_widget.setStyleSheet("QWidget#text_widget{\n" 550 | " border:0.5px solid lightgray; \n" 551 | " background-color: rgb(255, 255, 255);\n" 552 | "}\n" 553 | "\n" 554 | "\n" 555 | "") 556 | self.text_widget.setObjectName("text_widget") 557 | self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.text_widget) 558 | self.verticalLayout_5.setObjectName("verticalLayout_5") 559 | self.label_3 = QtWidgets.QLabel(self.text_widget) 560 | self.label_3.setStyleSheet("font: 9pt \"微软雅黑\";\n" 561 | "background-color: rgb(255, 255, 255);\n" 562 | "border-top:2px;\n" 563 | "border-bottom:1px solid lightgray;\n" 564 | "padding-bottom:8px ;") 565 | self.label_3.setObjectName("label_3") 566 | self.verticalLayout_5.addWidget(self.label_3) 567 | self.textEdit = QtWidgets.QTextEdit(self.text_widget) 568 | self.textEdit.setStyleSheet("border:0px;\n" 569 | "background-color: rgb(255, 255, 255);") 570 | self.textEdit.setFrameShadow(QtWidgets.QFrame.Sunken) 571 | self.textEdit.setLineWidth(0) 572 | self.textEdit.setLineWrapMode(QtWidgets.QTextEdit.NoWrap) 573 | self.textEdit.setCursorWidth(0) 574 | self.textEdit.setObjectName("textEdit") 575 | self.verticalLayout_5.addWidget(self.textEdit) 576 | self.horizontalLayout_3.addWidget(self.text_widget) 577 | self.horizontalLayout_3.setStretch(0, 2) 578 | self.horizontalLayout_3.setStretch(1, 1) 579 | self.verticalLayout_3.addWidget(self.r_bottom_widget) 580 | self.verticalLayout_3.setStretch(0, 3) 581 | self.verticalLayout_6.addWidget(self.widget) 582 | self.upload_pic_4 = QtWidgets.QPushButton(self.page_2) 583 | self.upload_pic_4.setEnabled(False) 584 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 585 | sizePolicy.setHorizontalStretch(0) 586 | sizePolicy.setVerticalStretch(0) 587 | sizePolicy.setHeightForWidth(self.upload_pic_4.sizePolicy().hasHeightForWidth()) 588 | self.upload_pic_4.setSizePolicy(sizePolicy) 589 | self.upload_pic_4.setMinimumSize(QtCore.QSize(250, 45)) 590 | self.upload_pic_4.setMaximumSize(QtCore.QSize(250, 45)) 591 | font = QtGui.QFont() 592 | font.setFamily("微软雅黑") 593 | font.setPointSize(12) 594 | font.setBold(False) 595 | font.setItalic(False) 596 | font.setWeight(50) 597 | font.setKerning(True) 598 | self.upload_pic_4.setFont(font) 599 | self.upload_pic_4.setStyleSheet("QPushButton:enabled\n" 600 | "{\n" 601 | " background-color: rgb(255, 161, 75);\n" 602 | " color: rgb(255, 255, 255);\n" 603 | " border: 0px;\n" 604 | " font: 11.5pt \"微软雅黑\" ;\n" 605 | "}\n" 606 | "\n" 607 | "QPushButton:hover\n" 608 | "{\n" 609 | " /*背景颜色*/ \n" 610 | " background-color: rgb(253, 149, 54);\n" 611 | " \n" 612 | "}\n" 613 | "\n" 614 | "QPushButton:disabled\n" 615 | "{\n" 616 | " /*背景颜色*/ \n" 617 | " background-color: lightgray;\n" 618 | " color: rgb(255, 255, 255);\n" 619 | " border: 0px;\n" 620 | " font: 11.5pt \"微软雅黑\" ;\n" 621 | " \n" 622 | "}") 623 | self.upload_pic_4.setFlat(False) 624 | self.upload_pic_4.setObjectName("upload_pic_4") 625 | self.verticalLayout_6.addWidget(self.upload_pic_4, 0, QtCore.Qt.AlignRight) 626 | self.stack_page.addWidget(self.page_2) 627 | self.verticalLayout_2.addWidget(self.stack_page) 628 | self.horizontalLayout_2.addWidget(self.right_widget) 629 | Unframewindow.setCentralWidget(self.centralwidget) 630 | self.menubar = QtWidgets.QMenuBar(Unframewindow) 631 | self.menubar.setGeometry(QtCore.QRect(0, 0, 973, 26)) 632 | self.menubar.setObjectName("menubar") 633 | Unframewindow.setMenuBar(self.menubar) 634 | self.pic_label_2.setBuddy(self.upload_pic) 635 | 636 | self.retranslateUi(Unframewindow) 637 | self.stack_page.setCurrentIndex(0) 638 | # self.upload_pic_4.clicked.connect(Unframewindow.recognize) 639 | QtCore.QMetaObject.connectSlotsByName(Unframewindow) 640 | 641 | def retranslateUi(self, Unframewindow): 642 | _translate = QtCore.QCoreApplication.translate 643 | Unframewindow.setWindowTitle(_translate("Unframewindow", "MainWindow")) 644 | self.icon_bottom_label.setText(_translate("Unframewindow", "

OCR文字识别软件

")) 645 | __sortingEnabled = self.left_widget.isSortingEnabled() 646 | self.left_widget.setSortingEnabled(False) 647 | item = self.left_widget.item(0) 648 | item.setText(_translate("Unframewindow", "文字拍摄")) 649 | item = self.left_widget.item(1) 650 | item.setText(_translate("Unframewindow", "文字识别")) 651 | self.left_widget.setSortingEnabled(__sortingEnabled) 652 | self.MinButton.setToolTip(_translate("Unframewindow", "最小化")) 653 | self.MaxButton.setToolTip(_translate("Unframewindow", "最大化")) 654 | self.CloseButton.setToolTip(_translate("Unframewindow", "关闭窗口")) 655 | self.label_show_camera.setText(_translate("Unframewindow", "


")) 656 | self.cam_photo.setText(_translate("Unframewindow", "打开相机")) 657 | self.cam_project.setText(_translate("Unframewindow", "识别")) 658 | self.cam_deal.setText(_translate("Unframewindow", "效果处理")) 659 | self.cam_open.setText(_translate("Unframewindow", "拍照")) 660 | self.delete_pic.setText(_translate("Unframewindow", "删除")) 661 | self.pic_label_2.setText(_translate("Unframewindow", "

支持JPG, PNG格式图片

")) 662 | self.upload_pic.setText(_translate("Unframewindow", "上传图片")) 663 | self.label_3.setText(_translate("Unframewindow", "识别结果")) 664 | self.textEdit.setHtml(_translate("Unframewindow", "\n" 665 | "\n" 668 | "


")) 669 | self.upload_pic_4.setText(_translate("Unframewindow", "开始识别")) 670 | from title import QTitleButton 671 | import picture_rc 672 | 673 | 674 | if __name__ == "__main__": 675 | import sys 676 | app = QtWidgets.QApplication(sys.argv) 677 | Unframewindow = QtWidgets.QMainWindow() 678 | ui = Ui_Unframewindow() 679 | ui.setupUi(Unframewindow) 680 | Unframewindow.show() 681 | sys.exit(app.exec_()) 682 | -------------------------------------------------------------------------------- /UI/resources/ui2.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Unframewindow 4 | 5 | 6 | Qt::NonModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 973 13 | 759 14 | 15 | 16 | 17 | true 18 | 19 | 20 | MainWindow 21 | 22 | 23 | 24 | 25 | 26 | false 27 | 28 | 29 | QListWidget, QListView, QTreeWidget, QTreeView { 30 | outline: 0px; 31 | } 32 | 33 | QListWidget { 34 | 35 | color: #cccccc; 36 | background: #2e2e36; 37 | } 38 | 39 | QListWidget::Item:selected { 40 | background: #26262e; 41 | color: #fd7e19; 42 | border-left: 5px solid #fd9536; 43 | 44 | } 45 | HistoryPanel:hover { 46 | background: rgb(52, 52, 52); 47 | } 48 | /**********Title**********/ 49 | QTitleLabel{ 50 | background-color: Gainsboro; 51 | font: 100 10pt; 52 | } 53 | 54 | 55 | /**********Button**********/ 56 | QTitleButton{ 57 | background-color: rgba(255, 255, 255, 0); 58 | color: black; 59 | border: 0px; 60 | font: 100 10pt; 61 | } 62 | QTitleButton#MinButton:hover,#MaxButton:hover{ 63 | background-color: #D0D0D1; 64 | border: 0px; 65 | font: 100 10pt; 66 | 67 | 68 | } 69 | 70 | QTitleButton#CloseButton:hover{ 71 | background-color: #D32424; 72 | color: white; 73 | border: 0px; 74 | font: 100 10pt; 75 | 76 | } 77 | 78 | QTitleButton#MinButton{ 79 | image: url(./resource/short.png); 80 | 81 | } 82 | QTitleButton#CloseButton{ 83 | image: url(./resource/exit.png); 84 | } 85 | QTitleButton#MaxButton{ 86 | image: url(./resource/restore.png); 87 | } 88 | 89 | 90 | 91 | 92 | 93 | false 94 | 95 | 96 | 97 | 98 | 0 99 | 100 | 101 | 0 102 | 103 | 104 | 0 105 | 106 | 107 | 0 108 | 109 | 110 | 0 111 | 112 | 113 | 114 | 115 | 116 | 0 117 | 0 118 | 119 | 120 | 121 | 122 | 150 123 | 0 124 | 125 | 126 | 127 | 128 | 150 129 | 16777215 130 | 131 | 132 | 133 | true 134 | 135 | 136 | background: #2e2e36; 137 | 138 | 139 | 140 | 0 141 | 142 | 143 | 0 144 | 145 | 146 | 0 147 | 148 | 149 | 0 150 | 151 | 152 | 0 153 | 154 | 155 | 156 | 157 | 158 | 0 159 | 0 160 | 161 | 162 | 163 | 164 | 150 165 | 100 166 | 167 | 168 | 169 | 170 | 150 171 | 100 172 | 173 | 174 | 175 | true 176 | 177 | 178 | image: url(:/icon/res/OCR识别异常记录.png); 179 | 180 | background-color: #2e2e36; 181 | 182 | 183 | 184 | 185 | 186 | false 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 120 198 | 50 199 | 200 | 201 | 202 | 203 | 120 204 | 50 205 | 206 | 207 | 208 | 209 | 等线 210 | 75 211 | true 212 | 213 | 214 | 215 | background: #2e2e36; 216 | color: #cccccc; 217 | border-bottom:0.5px solid rgb(240, 240, 240,30%); 218 | 219 | 220 | 221 | 222 | QFrame::NoFrame 223 | 224 | 225 | QFrame::Plain 226 | 227 | 228 | 0 229 | 230 | 231 | <html><head/><body><p><span style=" font-weight:600;">OCR文字识别软件</span></p></body></html> 232 | 233 | 234 | false 235 | 236 | 237 | Qt::AlignCenter 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 150 246 | 0 247 | 248 | 249 | 250 | 251 | 150 252 | 16777215 253 | 254 | 255 | 256 | 257 | 0 258 | 0 259 | 260 | 261 | 262 | true 263 | 264 | 265 | QListWidget, QListView, QTreeWidget, QTreeView { 266 | outline: 0px; 267 | } 268 | 269 | QListWidget { 270 | 271 | color: #cccccc; 272 | background: #2e2e36; 273 | } 274 | 275 | QListWidget::Item:selected { 276 | background: #26262e; 277 | color: #fd7e19; 278 | border-left: 5px solid #fd9536; 279 | 280 | } 281 | HistoryPanel:hover { 282 | background: rgb(52, 52, 52); 283 | } 284 | 285 | 286 | QFrame::NoFrame 287 | 288 | 289 | false 290 | 291 | 292 | 293 | 文字拍摄 294 | 295 | 296 | 297 | 75 298 | true 299 | 300 | 301 | 302 | AlignCenter 303 | 304 | 305 | 306 | :/icon/test/resource/极速响应.png 307 | :/icon/test/resource/极速识别.png:/icon/test/resource/极速响应.png 308 | 309 | 310 | 311 | 312 | 文字识别 313 | 314 | 315 | 316 | 75 317 | true 318 | 319 | 320 | 321 | AlignCenter 322 | 323 | 324 | 325 | :/icon/test/resource/文字.png 326 | :/icon/test/resource/文字 (1).png:/icon/test/resource/文字.png 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 0 339 | 340 | 341 | 0 342 | 343 | 344 | 0 345 | 346 | 347 | 0 348 | 349 | 350 | 0 351 | 352 | 353 | 354 | 355 | 356 | 0 357 | 0 358 | 359 | 360 | 361 | 362 | 0 363 | 40 364 | 365 | 366 | 367 | 368 | 16777215 369 | 40 370 | 371 | 372 | 373 | true 374 | 375 | 376 | QWidget#label_widget{ 377 | background-color: rgb(255, 255, 255); 378 | 379 | 380 | 381 | } 382 | 383 | 384 | 385 | 386 | 0 387 | 388 | 389 | 0 390 | 391 | 392 | 0 393 | 394 | 395 | 0 396 | 397 | 398 | 0 399 | 400 | 401 | 402 | 403 | Qt::Horizontal 404 | 405 | 406 | QSizePolicy::Expanding 407 | 408 | 409 | 410 | 40 411 | 20 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 0 421 | 0 422 | 423 | 424 | 425 | 426 | 40 427 | 16777215 428 | 429 | 430 | 431 | PointingHandCursor 432 | 433 | 434 | true 435 | 436 | 437 | 最小化 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | true 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 0 455 | 0 456 | 457 | 458 | 459 | 460 | 40 461 | 0 462 | 463 | 464 | 465 | 466 | 40 467 | 16777215 468 | 469 | 470 | 471 | PointingHandCursor 472 | 473 | 474 | true 475 | 476 | 477 | 最大化 478 | 479 | 480 | 481 | 482 | 483 | true 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 0 492 | 0 493 | 494 | 495 | 496 | 497 | 40 498 | 0 499 | 500 | 501 | 502 | 503 | 40 504 | 16777215 505 | 506 | 507 | 508 | PointingHandCursor 509 | 510 | 511 | true 512 | 513 | 514 | 关闭窗口 515 | 516 | 517 | 518 | 519 | 520 | true 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 0 532 | 0 533 | 534 | 535 | 536 | 0 537 | 538 | 539 | 540 | QWidget#page{ 541 | background-color: rgb(245, 249, 252); 542 | } 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | background-color: rgb(255, 255, 255); 553 | image: url(:/icon/test/resource/camera.png); 554 | 555 | 556 | <html><head/><body><p align="center"><br/></p></body></html> 557 | 558 | 559 | false 560 | 561 | 562 | Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft 563 | 564 | 565 | 566 | 567 | 568 | 569 | 15 570 | 571 | 572 | 0 573 | 574 | 575 | 576 | 577 | 578 | 180 579 | 30 580 | 581 | 582 | 583 | 584 | 180 585 | 30 586 | 587 | 588 | 589 | PointingHandCursor 590 | 591 | 592 | 593 | QPushButton:hover 594 | { 595 | /*背景颜色*/ 596 | background-color: rgb(253, 149, 54); 597 | 598 | } 599 | QPushButton 600 | { 601 | background-color: rgb(255, 161, 75); 602 | border-radius:10px; 603 | color: rgb(255, 255, 255); 604 | border: 0px; 605 | font: 9pt "微软雅黑" ; 606 | } 607 | 608 | 609 | 610 | 打开相机 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 180 619 | 30 620 | 621 | 622 | 623 | 624 | 180 625 | 30 626 | 627 | 628 | 629 | 630 | 微软雅黑 631 | 9 632 | 50 633 | false 634 | false 635 | 636 | 637 | 638 | PointingHandCursor 639 | 640 | 641 | 642 | QPushButton:hover 643 | { 644 | /*背景颜色*/ 645 | background-color: rgb(253, 149, 54); 646 | 647 | } 648 | QPushButton 649 | { 650 | background-color: rgb(255, 161, 75); 651 | border-radius:10px; 652 | color: rgb(255, 255, 255); 653 | border: 0px; 654 | font: 9pt "微软雅黑" ; 655 | } 656 | 657 | 658 | 659 | 识别 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 180 668 | 30 669 | 670 | 671 | 672 | 673 | 180 674 | 30 675 | 676 | 677 | 678 | PointingHandCursor 679 | 680 | 681 | 682 | QPushButton:hover 683 | { 684 | /*背景颜色*/ 685 | background-color: rgb(253, 149, 54); 686 | 687 | } 688 | QPushButton 689 | { 690 | background-color: rgb(255, 161, 75); 691 | border-radius:10px; 692 | color: rgb(255, 255, 255); 693 | border: 0px; 694 | font: 9pt "微软雅黑" ; 695 | } 696 | 697 | 698 | 699 | 效果处理 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 180 708 | 30 709 | 710 | 711 | 712 | 713 | 180 714 | 30 715 | 716 | 717 | 718 | PointingHandCursor 719 | 720 | 721 | 722 | QPushButton:hover 723 | { 724 | /*背景颜色*/ 725 | background-color: rgb(253, 149, 54); 726 | 727 | } 728 | QPushButton 729 | { 730 | background-color: rgb(255, 161, 75); 731 | border-radius:10px; 732 | color: rgb(255, 255, 255); 733 | border: 0px; 734 | font: 9pt "微软雅黑" ; 735 | } 736 | 737 | 738 | 739 | 拍照 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 20 750 | 20 751 | 752 | 753 | 754 | 755 | 20 756 | 20 757 | 758 | 759 | 760 | 761 | 20 762 | 20 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | :/icon/图片.png:/icon/图片.png 771 | 772 | 773 | true 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | QWidget{ 782 | background-color: rgb(245, 249, 252); 783 | } 784 | 785 | 786 | 787 | 788 | 20 789 | 790 | 791 | 20 792 | 793 | 794 | 795 | 796 | 797 | 0 798 | 799 | 800 | 0 801 | 802 | 803 | 0 804 | 805 | 806 | 0 807 | 808 | 809 | 0 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 15 819 | 820 | 821 | 14 822 | 823 | 824 | 14 825 | 826 | 827 | 14 828 | 829 | 830 | 14 831 | 832 | 833 | 834 | 835 | true 836 | 837 | 838 | QWidget#pic_widget{ 839 | border:0.5px solid lightgray; 840 | background-color: rgb(255, 255, 255); 841 | } 842 | 843 | 844 | 845 | 846 | 847 | 0 848 | 849 | 850 | 851 | 852 | true 853 | 854 | 855 | 856 | 0 857 | 0 858 | 859 | 860 | 861 | 862 | 70 863 | 30 864 | 865 | 866 | 867 | 868 | 70 869 | 30 870 | 871 | 872 | 873 | 874 | 微软雅黑 875 | 9 876 | 50 877 | false 878 | false 879 | true 880 | 881 | 882 | 883 | PointingHandCursor 884 | 885 | 886 | 887 | QPushButton:hover 888 | { 889 | /*背景颜色*/ 890 | background-color:rgb(240, 240, 240); 891 | 892 | } 893 | QPushButton 894 | { 895 | background-color: rgb(255, 255, 255); 896 | 897 | color: rgb(253, 149, 54); 898 | border: 1px solid rgb(253, 149, 54) ; 899 | border-radius:7px; 900 | font: 9pt "微软雅黑" ; 901 | } 902 | 903 | 904 | 905 | 删除 906 | 907 | 908 | false 909 | 910 | 911 | 912 | 913 | 914 | 915 | true 916 | 917 | 918 | 919 | 0 920 | 0 921 | 922 | 923 | 924 | 925 | image: url(:/icon/test/resource/label_pic.png); 926 | background-color: rgb(255, 255, 255); 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | true 937 | 938 | 939 | 940 | 0 941 | 0 942 | 943 | 944 | 945 | 946 | 16777215 947 | 200 948 | 949 | 950 | 951 | font: 9pt "微软雅黑"; 952 | background-color: rgb(255, 255, 255); 953 | 954 | 955 | <html><head/><body><p align="center"><span style=" font-size:12pt;">支持JPG, PNG格式图片</span></p></body></html> 956 | 957 | 958 | upload_pic 959 | 960 | 961 | 962 | 963 | 964 | 965 | true 966 | 967 | 968 | 969 | 0 970 | 0 971 | 972 | 973 | 974 | 975 | 200 976 | 50 977 | 978 | 979 | 980 | 981 | 200 982 | 50 983 | 984 | 985 | 986 | 987 | 微软雅黑 988 | 12 989 | 50 990 | false 991 | false 992 | true 993 | 994 | 995 | 996 | PointingHandCursor 997 | 998 | 999 | 1000 | QPushButton:hover 1001 | { 1002 | /*背景颜色*/ 1003 | background-color: rgb(253, 149, 54); 1004 | 1005 | } 1006 | QPushButton 1007 | { 1008 | background-color: rgb(255, 161, 75); 1009 | 1010 | color: rgb(255, 255, 255); 1011 | border: 0px; 1012 | font: 11.5pt "微软雅黑" ; 1013 | } 1014 | 1015 | 1016 | 1017 | 上传图片 1018 | 1019 | 1020 | false 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 0 1029 | 50 1030 | 1031 | 1032 | 1033 | background-color: rgb(255, 255, 255); 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | QWidget#text_widget{ 1047 | border:0.5px solid lightgray; 1048 | background-color: rgb(255, 255, 255); 1049 | } 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | font: 9pt "微软雅黑"; 1059 | background-color: rgb(255, 255, 255); 1060 | border-top:2px; 1061 | border-bottom:1px solid lightgray; 1062 | padding-bottom:8px ; 1063 | 1064 | 1065 | 识别结果 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | border:0px; 1073 | background-color: rgb(255, 255, 255); 1074 | 1075 | 1076 | QFrame::Sunken 1077 | 1078 | 1079 | 0 1080 | 1081 | 1082 | QTextEdit::NoWrap 1083 | 1084 | 1085 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 1086 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 1087 | p, li { white-space: pre-wrap; } 1088 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 1089 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> 1090 | 1091 | 1092 | 0 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | false 1109 | 1110 | 1111 | 1112 | 0 1113 | 0 1114 | 1115 | 1116 | 1117 | 1118 | 250 1119 | 45 1120 | 1121 | 1122 | 1123 | 1124 | 250 1125 | 45 1126 | 1127 | 1128 | 1129 | 1130 | 微软雅黑 1131 | 12 1132 | 50 1133 | false 1134 | false 1135 | true 1136 | 1137 | 1138 | 1139 | QPushButton:enabled 1140 | { 1141 | background-color: rgb(255, 161, 75); 1142 | color: rgb(255, 255, 255); 1143 | border: 0px; 1144 | font: 11.5pt "微软雅黑" ; 1145 | } 1146 | 1147 | QPushButton:hover 1148 | { 1149 | /*背景颜色*/ 1150 | background-color: rgb(253, 149, 54); 1151 | 1152 | } 1153 | 1154 | QPushButton:disabled 1155 | { 1156 | /*背景颜色*/ 1157 | background-color: lightgray; 1158 | color: rgb(255, 255, 255); 1159 | border: 0px; 1160 | font: 11.5pt "微软雅黑" ; 1161 | 1162 | } 1163 | 1164 | 1165 | 开始识别 1166 | 1167 | 1168 | false 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 0 1185 | 0 1186 | 973 1187 | 26 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | QTitleButton 1195 | QPushButton 1196 |
title
1197 |
1198 |
1199 | 1200 | 1201 | 1202 | 1203 | 1204 | upload_pic_4 1205 | clicked() 1206 | Unframewindow 1207 | recognize() 1208 | 1209 | 1210 | 835 1211 | 719 1212 | 1213 | 1214 | 857 1215 | 817 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | open_photo() 1222 | recognize() 1223 | 1224 |
1225 | -------------------------------------------------------------------------------- /UI/resources/停止.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/停止.png -------------------------------------------------------------------------------- /UI/resources/出口.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/出口.png -------------------------------------------------------------------------------- /UI/resources/图片.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/图片.png -------------------------------------------------------------------------------- /UI/resources/执行.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/执行.png -------------------------------------------------------------------------------- /UI/resources/拍照.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/拍照.png -------------------------------------------------------------------------------- /UI/resources/效果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/效果.png -------------------------------------------------------------------------------- /UI/resources/文字 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/文字 (1).png -------------------------------------------------------------------------------- /UI/resources/文字.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/文字.png -------------------------------------------------------------------------------- /UI/resources/极速响应.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/极速响应.png -------------------------------------------------------------------------------- /UI/resources/极速识别.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/极速识别.png -------------------------------------------------------------------------------- /UI/resources/相机.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/相机.png -------------------------------------------------------------------------------- /UI/resources/识别.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/识别.png -------------------------------------------------------------------------------- /UI/resources/识别图标.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/识别图标.png -------------------------------------------------------------------------------- /UI/resources/风车.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/UI/resources/风车.png -------------------------------------------------------------------------------- /__pycache__/menu.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/menu.cpython-37.pyc -------------------------------------------------------------------------------- /__pycache__/menu.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/menu.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/nets.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/nets.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/picture_rc.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/picture_rc.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/predict.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/predict.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/predict_c.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/predict_c.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/predict_c_2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/predict_c_2.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/prepare.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/prepare.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/title.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/title.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/ui2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/__pycache__/ui2.cpython-38.pyc -------------------------------------------------------------------------------- /benign.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/benign.pkl -------------------------------------------------------------------------------- /data/show_data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/data/show_data.xls -------------------------------------------------------------------------------- /data/show_label.csv: -------------------------------------------------------------------------------- 1 | label,classes 2 | 0,Normal 3 | 0,Normal 4 | 0,Normal 5 | 0,Normal 6 | 0,Normal 7 | 0,Normal 8 | 0,Normal 9 | 0,Normal 10 | 0,Normal 11 | 0,Normal 12 | 0,Normal 13 | 0,Normal 14 | 0,Normal 15 | 0,Normal 16 | 0,Normal 17 | 1,Abnormal 18 | 0,Normal 19 | 0,Normal 20 | 0,Normal 21 | 0,Normal 22 | 0,Normal 23 | 0,Normal 24 | 0,Normal 25 | 0,Normal 26 | 0,Normal 27 | 0,Normal 28 | 0,Normal 29 | 0,Normal 30 | 0,Normal 31 | 0,Normal 32 | 0,Normal 33 | 0,Normal 34 | 0,Normal 35 | 0,Normal 36 | 0,Normal 37 | 0,Normal 38 | 0,Normal 39 | 0,Normal 40 | 0,Normal 41 | 0,Normal 42 | 0,Normal 43 | 0,Normal 44 | 0,Normal 45 | 0,Normal 46 | 0,Normal 47 | 0,Normal 48 | 0,Normal 49 | 0,Normal 50 | 0,Normal 51 | 0,Normal 52 | 0,Normal 53 | 0,Normal 54 | 0,Normal 55 | 0,Normal 56 | 0,Normal 57 | 0,Normal 58 | 0,Normal 59 | 0,Normal 60 | 0,Normal 61 | 0,Normal 62 | 0,Normal 63 | 0,Normal 64 | 0,Normal 65 | 0,Normal 66 | 0,Normal 67 | 0,Normal 68 | 0,Normal 69 | 0,Normal 70 | 0,Normal 71 | 0,Normal 72 | 0,Normal 73 | 0,Normal 74 | 0,Normal 75 | 0,Normal 76 | 0,Normal 77 | 0,Normal 78 | 0,Normal 79 | 0,Normal 80 | 0,Normal 81 | 0,Normal 82 | 0,Normal 83 | 0,Normal 84 | 0,Normal 85 | 0,Normal 86 | 0,Normal 87 | 0,Normal 88 | 0,Normal 89 | 0,Normal 90 | 0,Normal 91 | 0,Normal 92 | 0,Normal 93 | 0,Normal 94 | 0,Normal 95 | 0,Normal 96 | 0,Normal 97 | 0,Normal 98 | 0,Normal 99 | 0,Normal 100 | 0,Normal 101 | 0,Normal 102 | 0,Normal 103 | 0,Normal 104 | 0,Normal 105 | 0,Normal 106 | 0,Normal 107 | 0,Normal 108 | 0,Normal 109 | 0,Normal 110 | 0,Normal 111 | 0,Normal 112 | 0,Normal 113 | 0,Normal 114 | 0,Normal 115 | 0,Normal 116 | 0,Normal 117 | 0,Normal 118 | 0,Normal 119 | 0,Normal 120 | 0,Normal 121 | 0,Normal 122 | 0,Normal 123 | 0,Normal 124 | 0,Normal 125 | 0,Normal 126 | 0,Normal 127 | 0,Normal 128 | 0,Normal 129 | 0,Normal 130 | -------------------------------------------------------------------------------- /dataprocess/NetDataPrcoess.py: -------------------------------------------------------------------------------- 1 | #导入必须的库 2 | 3 | import os 4 | import shutil 5 | import codecs 6 | 7 | 8 | class DataPrcoess(): 9 | def getdata(self,pathd): 10 | ls = os.listdir("./" + pathd) 11 | count = 0 12 | all_data = [] 13 | for i in ls: 14 | # print(i) 15 | path = "./" + pathd + "/" + i 16 | all_data.append(self.readText(path)) 17 | count += 1 18 | print(len(all_data)) 19 | return all_data 20 | #新建文件夹 21 | # def setDir(self,path): 22 | # if path not in os.listdir('./'): 23 | # os.mkdir("./" + path) 24 | # else: 25 | # shutil.rmtree("./" + path) 26 | # os.mkdir("./" + path) 27 | def setDir(self,path): 28 | if path not in os.listdir('./'): 29 | os.mkdir(path) 30 | else: 31 | shutil.rmtree(path) 32 | os.mkdir(path) 33 | # 将二进制转化为数字 34 | def hexdump(self,src, length=16): 35 | result = [] 36 | digits = 4 if isinstance(src, str) else 2 37 | for i in range(0, len(src), length): 38 | s = src[i:i + length] 39 | hexa = ' '.join([hex(x)[2:].upper().zfill(digits) for x in s]) 40 | text = ''.join([chr(x) if 0x20 <= x < 0x7F else '.' for x in s]) 41 | result.append( 42 | "{0:04X}".format(i) + ' ' * 3 + hexa.ljust(length * (digits + 1)) + ' ' * 3 + "{0}".format(text)) 43 | return '\n'.join(result) 44 | 45 | # 将数据以流为类写入文件夹 46 | def writeabnormaldata(self,data_excel, dirname): 47 | mid_pcap = [] 48 | label_data = [] 49 | label_label = [] 50 | n = 1 51 | # self.setDir(dirname) 52 | for i in range(len(data_excel)): 53 | if data_excel["data"][i] == 0: 54 | continue 55 | count = 0 56 | mid_pcap.append(data_excel["data"][i]) 57 | data_number = bytes(str(data_excel["data"][i][2:-1]), encoding="utf-8") 58 | original = codecs.escape_decode(data_number, "hex-escape") 59 | path = "./" + dirname + "/第%d条数据流" % n + ".txt" 60 | with open(path, 'a') as f: 61 | label_data.append(original[0]) 62 | f.write(self.hexdump(original[0])) 63 | f.write("结束") 64 | label_label.append(n) 65 | count += 1 66 | data_excel["data"][i] = 0 67 | for j in range(i + 1, len(data_excel)): 68 | if data_excel["srcip"][i] == data_excel["srcip"][j] and data_excel["dstip"][i] == data_excel["dstip"][ 69 | j] and data_excel["sport"][i] == data_excel["sport"][j] and data_excel["dport"][i] == \ 70 | data_excel["dport"][j] and data_excel["proto"][i] == data_excel["proto"][j]: 71 | count += 1 72 | if count>6 and count<=7: 73 | n += 1 74 | count=0 75 | mid_pcap.append(data_excel["data"][j]) 76 | data_number = bytes(data_excel["data"][j][2:-1], encoding="utf-8") 77 | original = codecs.escape_decode(data_number, "hex-escape") 78 | path = "./" + dirname + "/第%d条数据流" % n + ".txt" 79 | with open(path, 'a') as f: 80 | label_data.append(original[0]) 81 | f.write(self.hexdump(original[0])) 82 | f.write("结束") 83 | label_label.append(n) 84 | data_excel["data"][j] = 0 85 | if count>0: 86 | n += 1 87 | return label_data ,label_label 88 | 89 | def readText(self,path): 90 | data_need = [] 91 | mid_data = [] 92 | file = open(path, "r") 93 | for line in file.readlines(): 94 | curLine = line.strip().split(" ") 95 | flag = 0 96 | # print(curLine) 97 | # print("len",len(curLine)) 98 | for i in range(3, 19): 99 | flag = 1 100 | # print(curLine[i]) 101 | if (i + 1 >= len(curLine) or (curLine[i] == "" and curLine[i + 1] == "")): 102 | flag = 0 103 | break 104 | else: 105 | for h in range(i, len(curLine)): 106 | if "结束" in curLine[h]: 107 | flag = 0 108 | # print(mid_data) 109 | break 110 | mid_data.append(int(curLine[i], 16)) 111 | if flag == 0: 112 | data_need.append(mid_data) 113 | mid_data = [] 114 | return data_need -------------------------------------------------------------------------------- /dataprocess/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/dataprocess/__init__.py -------------------------------------------------------------------------------- /dataprocess/__pycache__/NetDataPrcoess.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/dataprocess/__pycache__/NetDataPrcoess.cpython-38.pyc -------------------------------------------------------------------------------- /dataprocess/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/dataprocess/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /dataprocess/__pycache__/datasave.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/dataprocess/__pycache__/datasave.cpython-38.pyc -------------------------------------------------------------------------------- /dataprocess/datasave.py: -------------------------------------------------------------------------------- 1 | import xlsxwriter 2 | import pandas as pd 3 | from dataprocess import NetDataPrcoess 4 | import xlwt 5 | class savedata(): 6 | def __init__(self,data,filename,pack_number=4,bits_number=121): 7 | self.data=data 8 | self.filename=filename 9 | self.pack_number=pack_number 10 | self.bits_number=bits_number 11 | def writedata(self,worksheet,data,size=4, length=121): 12 | for i in range(len(data)): 13 | # print(len(data[i])) 14 | if len(data[i]) >= size: 15 | count = 1 16 | for j in range(size): 17 | for k in range(length): 18 | if k >= len(data[i][j]): 19 | worksheet.write((i + 1), count, 0) 20 | count += 1 21 | else: 22 | worksheet.write((i + 1), count, data[i][j][k]) 23 | count += 1 24 | # for k in range(0,1): 25 | # worksheet.write((i+1),count,data[i][j][k]) 26 | # count+=1 27 | else: 28 | number = 0 29 | count = 1 30 | h = 0 31 | # print(len(data[i])) 32 | for j in range(len(data[i])): 33 | for k in range(length): 34 | if k >= len(data[i][j]): 35 | worksheet.write((i + 1), count, 0) 36 | count += 1 37 | number += 1 38 | else: 39 | worksheet.write((i + 1), count, data[i][j][k]) 40 | count += 1 41 | number += 1 42 | for nn in range(0, size): 43 | for j in range(len(data[i])): 44 | for k in range(length): 45 | if number <= size*length: 46 | if k >= len(data[i][j]): 47 | worksheet.write((i + 1), number, 0) 48 | number += 1 49 | else: 50 | worksheet.write((i + 1), number, data[i][j][k]) 51 | number += 1 52 | else: 53 | break 54 | # print(number) 55 | for num in range(number, size*length+1): 56 | worksheet.write(i + 1, num, 0) 57 | def save_data(self, label_data, label_label): 58 | # 创建一个workbook 设置编码 59 | dataprocess = NetDataPrcoess.DataPrcoess() 60 | dataprocess.setDir('data') 61 | workbook = xlwt.Workbook(encoding='utf-8') 62 | # 创建一个worksheet 63 | worksheet = workbook.add_sheet('My Worksheet') 64 | worksheet.write(0, 0,label='data') 65 | worksheet.write(0, 1,label='flowmember') 66 | worksheet.write(0, 2,label='label') 67 | worksheet.write(0,3,label='classes') 68 | for i in range(len(label_data)): 69 | worksheet.write(i + 1, 0, label=str(label_data[i])) 70 | worksheet.write(i + 1, 1, label=str(label_label[i])) 71 | workbook.save('./data/show_data.xls') 72 | data = pd.read_excel('./data/show_data.xls', index_col=0) 73 | data.to_csv('./data/show_data.csv', encoding='utf-8') 74 | 75 | def save_excel(self,): # 储存为excel 76 | dataprocess = NetDataPrcoess.DataPrcoess() 77 | dataprocess.setDir("NetData") 78 | # print("1") 79 | dataprocess.setDir("./NetData/testdata") 80 | # print("2") 81 | # data_data = pd.read_csv(self.path) 82 | data_data = self.data 83 | # 返回 84 | show_data,show_label=dataprocess.writeabnormaldata(data_data,"./NetData/testdata") 85 | workbook = xlsxwriter.Workbook(self.filename+".xls") # 创建一个名称为filename的xls文件 86 | workbook.use_zip64() 87 | worksheet = workbook.add_worksheet() 88 | for i in range(0, self.pack_number*self.bits_number): 89 | label = "%d" % i 90 | worksheet.write(0, i + 1, label) 91 | data=dataprocess.getdata("./NetData/testdata") 92 | self.writedata(worksheet,data) 93 | workbook.close() 94 | data=pd.read_excel(self.filename+".xls",index_col=0) 95 | # data.to_csv(self.filename+".csv", encoding='utf-8') 96 | data.to_csv(self.filename+".csv", encoding='utf-8') 97 | #保存用于最后用于显示的文件 98 | self.save_data(show_data,show_label) 99 | # if __name__ == '__main__': 100 | # 101 | # data_save=savedata("./benign.pkl",filename="test_data") 102 | # # data_save=savedata("../UI/benign.csv",filename="test_data") 103 | # data_save.save_excel() 104 | -------------------------------------------------------------------------------- /dataprocess/test_data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/dataprocess/test_data.xls -------------------------------------------------------------------------------- /list.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/list.txt -------------------------------------------------------------------------------- /menu.py: -------------------------------------------------------------------------------- 1 | from PyQt5.Qt import * 2 | import ui2 as ui2 3 | import sys 4 | import multiprocessing as mp 5 | import title as title 6 | import UI.cut_pcap as cut_pcap 7 | import dataprocess.datasave as datasave 8 | import predict_c_2 as predict 9 | import pandas as pd 10 | class Mainwindow(ui2.Ui_Unframewindow, QMainWindow): 11 | def __init__(self, *args, **kwargs): 12 | super().__init__(None,Qt.FramelessWindowHint) 13 | 14 | # self.setui(self) 15 | self.setupUi(self) 16 | self.setWindowTitle('异常流量检测系统') 17 | self.setWindowIcon(QIcon('./resources/OCR-orange.png')) 18 | self.page.setStyleSheet("QWidget#page{background-color: rgb(245, 249, 252);}") 19 | 20 | for i in range(2): 21 | item = self.left_widget.item(i) # 选中QlistWidget的不同按钮 22 | item.setSizeHint(QSize(30, 60)) # 设置按钮大小 23 | 24 | 25 | self.initDrag() 26 | self.slot_init() 27 | self.setCloseButton(True) 28 | self.setMinMaxButtons(True) 29 | self.minWidth = 1280 30 | self.minHeight = 720 31 | self.setMinimumWidth(self.minWidth) # 设置主界面最小长宽 32 | self.setMinimumHeight(self.minHeight) 33 | self.setMouseTracking(True) # 设置widget鼠标跟踪 34 | self.statusBar().hide() # 隐藏状态栏 35 | self.label_8.setContentsMargins(5,5,0,0) #设置label的边界 36 | 37 | self.left_widget.currentRowChanged.connect(self.display) 38 | #初始化表格数据 39 | self.tableWidget.setColumnCount(6) # 设置表格为六列 40 | self.tableWidget_2.setColumnCount(8) # 设置表格为六列 41 | # 创建表头 42 | self.tableWidget.setHorizontalHeaderLabels(['srcip', 'dstip', 'sport', 'dport', 'proto', 'data']) 43 | self.tableWidget_2.setHorizontalHeaderLabels(['srcip', 'dstip', 'sport', 'dport', 'proto', 'data','label','class']) 44 | # 禁止编辑 45 | self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) 46 | self.tableWidget_2.setEditTriggers(QAbstractItemView.NoEditTriggers) 47 | self.detect_flag = 0 48 | 49 | self.label_7.hide() # 将进度栏的图片隐藏 50 | 51 | 52 | def slot_init(self): 53 | self.read_button.clicked.connect(self.curtail_pcap) 54 | self.upload_pic_5.clicked.connect(self.startdetection) 55 | 56 | 57 | 58 | def display(self, index): # 将stackwidget和 listwidget进行连接 59 | self.stack_page.setCurrentIndex(index) 60 | 61 | def initDrag(self): 62 | # 设置鼠标跟踪判断扳机默认值 63 | self._move_drag = False 64 | self._bottom_drag = False 65 | self._right_drag = False 66 | self._left_drag = False 67 | self._right_bottom_corner_drag = False 68 | self._left_bottom_corner_drag = False 69 | 70 | def setCloseButton(self, bool): 71 | # 给widget定义一个setCloseButton函数,为True时设置一个关闭按钮 72 | if bool == True: 73 | self.CloseButton.clicked.connect(self.close) # 按钮信号连接到关闭窗口的槽函数 74 | 75 | def resizeEvent(self, QResizeEvent): 76 | # 自定义窗口调整大小事件 77 | 78 | # 设置在边缘多少位置范围会触发,如左部拉伸则会在距离左边缘的5,高度为(控件高-5)的高度 79 | self._left_rect = [QPoint(x, y) for x in range(0, 5) 80 | for y in range(5, self.height() - 5)] 81 | self._right_rect = [QPoint(x, y) for x in range(self.width() - 5, self.width() + 1) 82 | for y in range(5, self.height() - 5)] 83 | self._bottom_rect = [QPoint(x, y) for x in range(5, self.width() - 5) 84 | for y in range(self.height() - 5, self.height() + 1)] 85 | self._right_bottom_corner_rect = [QPoint(x, y) for x in range(self.width() - 5, self.width() + 1) 86 | for y in range(self.height() - 5, self.height() + 1)] 87 | self._left_bottom_corner_rect = [QPoint(x, y) for x in range(0, 5) 88 | for y in range(self.height() - 5, self.height() + 1)] 89 | 90 | def mouseMoveEvent(self, event): 91 | # 判断鼠标位置切换鼠标手势 92 | if event.pos() in self._right_bottom_corner_rect: 93 | self.setCursor(Qt.SizeFDiagCursor) 94 | 95 | elif event.pos() in self._left_bottom_corner_rect: 96 | self.setCursor(Qt.SizeBDiagCursor) 97 | 98 | elif event.pos() in self._bottom_rect: 99 | self.setCursor(Qt.SizeVerCursor) 100 | 101 | elif event.pos() in self._right_rect: 102 | self.setCursor(Qt.SizeHorCursor) 103 | 104 | elif event.pos() in self._left_rect: 105 | self.setCursor(Qt.SizeHorCursor) 106 | 107 | else: 108 | self.setCursor(Qt.ArrowCursor) 109 | 110 | # 当鼠标左键点击不放及满足点击区域的要求后,分别实现不同的窗口调整 111 | if Qt.LeftButton and self._right_drag: 112 | # 右侧调整窗口宽度 113 | self.resize(event.pos().x(), self.height()) 114 | event.accept() 115 | elif Qt.LeftButton and self._left_drag: 116 | # 左侧调整窗口高度 117 | if self.width() - event.pos().x() > self.minWidth: 118 | self.resize(self.width() - event.pos().x(), self.height()) 119 | self.move(self.x() + event.pos().x(), self.y()) 120 | event.accept() 121 | elif Qt.LeftButton and self._bottom_drag: 122 | # 下侧调整窗口高度 123 | self.resize(self.width(), event.pos().y()) 124 | event.accept() 125 | elif Qt.LeftButton and self._right_bottom_corner_drag: 126 | # 右下角同时调整高度和宽度 127 | self.resize(event.pos().x(), event.pos().y()) 128 | event.accept() 129 | elif Qt.LeftButton and self._left_bottom_corner_drag: 130 | # 左下角同时调整高度和宽度 131 | if self.width() - event.pos().x() > self.minWidth: 132 | self.resize(self.width() - event.pos().x(), event.pos().y()) 133 | self.move(self.x() + event.pos().x(), self.y()) 134 | event.accept() 135 | elif Qt.LeftButton and self._move_drag: 136 | # 标题栏拖放窗口位置 137 | self.move(event.globalPos() - self.move_DragPosition) 138 | event.accept() 139 | 140 | 141 | def mousePressEvent(self, event): 142 | # 重写鼠标点击的事件 143 | if (event.button() == Qt.LeftButton) and (event.pos() in self._right_bottom_corner_rect): 144 | # 鼠标左键点击右下角边界区域 145 | self._right_bottom_corner_drag = True 146 | event.accept() 147 | elif (event.button() == Qt.LeftButton) and (event.pos() in self._left_bottom_corner_rect): 148 | # 鼠标左键点击左下角边界区域 149 | self._left_bottom_corner_drag = True 150 | event.accept() 151 | elif (event.button() == Qt.LeftButton) and (event.pos() in self._left_rect): 152 | # 鼠标左键点击左侧边界区域 153 | self._left_drag = True 154 | event.accept() 155 | elif (event.button() == Qt.LeftButton) and (event.pos() in self._right_rect): 156 | # 鼠标左键点击右侧边界区域 157 | self._right_drag = True 158 | event.accept() 159 | elif (event.button() == Qt.LeftButton) and (event.pos() in self._bottom_rect): 160 | # 鼠标左键点击下侧边界区域 161 | self._bottom_drag = True 162 | event.accept() 163 | elif (event.button() == Qt.LeftButton) and (event.y() < 30): # 距离标题最上方小于30时,变为拖拽 164 | # 鼠标左键点击标题栏区域 165 | self._move_drag = True 166 | self.move_DragPosition = event.globalPos() - self.pos() 167 | event.accept() 168 | 169 | def mouseReleaseEvent(self, QMouseEvent): 170 | # 鼠标释放后,各扳机复位 171 | self._move_drag = False 172 | self._right_bottom_corner_drag = False 173 | self._bottom_drag = False 174 | self._right_drag = False 175 | self._left_drag = False 176 | self._left_bottom_corner_drag = False 177 | 178 | def mouseDoubleClickEvent(self, event): 179 | if self.isMaximized(): 180 | self.showNormal() 181 | else: 182 | self.showMaximized() 183 | return QWidget().mouseDoubleClickEvent(event) 184 | 185 | 186 | def setMinMaxButtons(self, bool): 187 | # 给widget定义一个setMinMaxButtons函数,为True时设置一组最小化最大化按钮 188 | if bool == True: 189 | # 最小化按钮 190 | self.MinButton.clicked.connect(self.showMinimized) # 按钮信号连接到最小化窗口的槽函数 191 | # 最大化按钮 192 | self.MaxButton.clicked.connect(self._changeNormalButton) # 按钮信号连接切换到恢复窗口大小按钮函数 193 | 194 | def _changeNormalButton(self): 195 | # 切换到恢复窗口大小按钮 196 | try: 197 | self.showMaximized() # 先实现窗口最大化 198 | # self._MaximumButton.setText(b'\xef\x80\xb2'.decode("utf-8")) # 更改按钮文本 199 | self.MaxButton.setToolTip("恢复") # 更改按钮提示 200 | self.MaxButton.disconnect() # 断开原本的信号槽连接 201 | self.MaxButton.clicked.connect(self._changeMaxButton) # 重新连接信号和槽 202 | except: 203 | pass 204 | 205 | 206 | 207 | 208 | def return_pic(self): 209 | # 隐藏两个控件 210 | self.delete_pic.hide() 211 | self.label_pic.hide() 212 | 213 | # 展示四个控件 214 | self.pic_label_1.show() 215 | self.pic_label_2.show() 216 | self.upload_pic.show() 217 | self.spaceitem.show() 218 | self.upload_pic_5.setEnabled(False) # 取消激活识别按钮 219 | 220 | def select_path(self): 221 | self.fname_p = QFileDialog.getOpenFileName(self, 'Open file', "", "*.csv;;All Files(*)") 222 | # print(self.fname) 223 | if self.fname_p == ('', ''): 224 | pass 225 | else: 226 | self.addrEdit.setText(self.fname_p[0]) 227 | 228 | # title.read_csv(self.fname[0],self.tableWidget) 229 | def getshowdata(self,): 230 | data_csv_data = pd.read_csv(r"./data/show_data.csv", encoding='gbk', parse_dates=True) 231 | data_csv_label = pd.read_csv(r"./data/show_label.csv", encoding='gbk', parse_dates=True) 232 | length = len(data_csv_label) - (data_csv_data['flowmember'].max() - (data_csv_data['flowmember'].max() //64) *64) 233 | k=(data_csv_data['flowmember'].max() //64) *64 234 | for i in range(length, len(data_csv_label)): 235 | data_csv_label['label'][k] = data_csv_label['label'][i] 236 | data_csv_label['classes'][k] = data_csv_label['classes'][i] 237 | k+= 1 238 | j = 1 239 | i = 0 240 | count = 0 241 | while i < len(data_csv_data): 242 | if data_csv_data['flowmember'][i] == j: 243 | data_csv_data['label'][i] = data_csv_label['label'][j-1] 244 | data_csv_data['classes'][i]=data_csv_label['classes'][j-1] 245 | i += 1 246 | else: 247 | j = j + 1 248 | # print("i",i) 249 | if j > data_csv_data['flowmember'].max(): 250 | break 251 | data_csv_data['label'][i] = data_csv_label['label'][j-1] 252 | data_csv_data['classes'][i] = data_csv_label['classes'][j-1] 253 | i += 1 254 | return data_csv_data 255 | 256 | def curtail_pcap(self): 257 | self.label_6.setText('程序正在执行,请稍等') 258 | integrate = [self.label_5,self.label_6,self.label_7] 259 | #替换显示的图片 260 | self.label_5.hide() 261 | self.label_7.show() 262 | self.tableWidget.clearContents() 263 | 264 | num_cores = int(mp.cpu_count()) 265 | pool = mp.Pool(num_cores) 266 | moder = cut_pcap.pcap_cut() # 继承截取pcap的类,传入 267 | clip_num = int(self.lineEdit_2.text()) #截取数据包的数量 268 | # moder.read_pcap2('benign.csv',pool) 269 | self.data = moder.read_pcap2('save.pkl', pool,clip_num) # 获得pcap提取的流量包的数据 270 | # csv_path = 'benign.csv' 271 | # pickle_path = 'save.pkl' 272 | # title.read_csv(csv_path,self.tableWidget) #将csv读取到PYQT5 273 | title.read_pickle(self.data, self.tableWidget) # 将pickle读取到PYQT5 274 | QMessageBox.information(self, 'pcap截取', '截取成功!') 275 | # data_save=datasave.savedata("./"+csv_path,filename="test_data") 276 | data_save=datasave.savedata(self.data,filename="test_data") 277 | 278 | data_save.save_excel() 279 | self.label_6.setText('程序未运行') 280 | self.label_5.show() 281 | self.label_7.hide() 282 | 283 | def startdetection(self): 284 | # path=self.addrEdit.text() 285 | self.tableWidget_2.clearContents() 286 | path = r'./test_data.csv' 287 | # print(os.listdir()) 288 | predicted=predict.predict(path) 289 | predicted.finallmainmodel1() 290 | predicted.finallmainmodel2() 291 | predicted.finallmainmodel3() 292 | predicted.statistic() 293 | data_csv_data=self.getshowdata() 294 | self.saveshowdata(data_csv_data) 295 | # data_orginal = pd.read_csv(r"./save.csv", encoding='gbk', parse_dates=True) 296 | data_orginal = pd.read_pickle(r"save.pkl") 297 | 298 | data_show = pd.read_csv(r"./data/shown.csv", encoding='gbk', parse_dates=True) 299 | data_orginal['label'] = 0 300 | data_orginal['classes']=0 301 | data_orginal=self.finalldata(data_orginal,data_show) 302 | self.savelabelshown(data_orginal) 303 | title.read_csv('./data/shown_finall.csv',self.tableWidget_2) 304 | 305 | def saveshowdata(self,data_csv_data): 306 | import xlwt 307 | # 创建一个workbook 设置编码 308 | workbook = xlwt.Workbook(encoding='utf-8') 309 | # 创建一个worksheet 310 | worksheet = workbook.add_sheet('My Worksheet') 311 | worksheet.write(0,0,label='data') 312 | worksheet.write(0,1,label='flowmember') 313 | worksheet.write(0,2,label='label') 314 | worksheet.write(0,3,label='classes') 315 | for i in range(len(data_csv_data)): 316 | worksheet.write(i + 1, 0, label=str(data_csv_data['data'][i])) 317 | worksheet.write(i + 1, 1, label=str(data_csv_data['flowmember'][i])) 318 | worksheet.write(i + 1, 2, label=str(data_csv_data['label'][i])) 319 | worksheet.write(i + 1, 3, label=str(data_csv_data['classes'][i])) 320 | workbook.save('./data/shown.csv') 321 | data = pd.read_excel('./data/shown.csv', index_col=0) 322 | data.to_csv('./data/shown.csv', encoding='utf-8') 323 | def finalldata(self,data_orginal, data_show): 324 | for i in range(len(data_orginal)): 325 | for j in range(len(data_show)): 326 | if data_orginal['data'][i] == data_show['data'][j]: 327 | data_orginal['label'][i]=data_show['label'][j] 328 | data_orginal['classes'][i]=data_show['classes'][j] 329 | return data_orginal 330 | def savelabelshown(self,data_orginal): 331 | import xlwt 332 | # 创建一个workbook 设置编码 333 | workbook = xlwt.Workbook(encoding='utf-8') 334 | # 创建一个worksheet 335 | worksheet = workbook.add_sheet('My Worksheet') 336 | worksheet.write(0, 0, label='srcip') 337 | worksheet.write(0, 1, label='dstip') 338 | worksheet.write(0, 2, label='sport') 339 | worksheet.write(0, 3, label='dport') 340 | worksheet.write(0, 4, label='proto') 341 | worksheet.write(0, 5, label='data') 342 | worksheet.write(0, 6, label='label') 343 | worksheet.write(0, 7, label='classes') 344 | for i in range(len(data_orginal)): 345 | worksheet.write(i+1,0, label=str(data_orginal['srcip'][i])) 346 | worksheet.write(i+1,1, label=str(data_orginal['dstip'][i])) 347 | worksheet.write(i+1,2, label=str(data_orginal['sport'][i])) 348 | worksheet.write(i+1,3, label=str(data_orginal['dport'][i])) 349 | worksheet.write(i+1,4, label=str(data_orginal['proto'][i])) 350 | worksheet.write(i+1,5, label=str(data_orginal['data'][i])) 351 | worksheet.write(i+1,6, label=str(data_orginal['label'][i])) 352 | worksheet.write(i+1,7, label=str(data_orginal['classes'][i])) 353 | workbook.save('./data/shown_finall.csv') 354 | data = pd.read_excel('./data/shown_finall.csv', index_col=0) 355 | data.to_csv('./data/shown_finall.csv', encoding='utf-8') 356 | if __name__ == '__main__': 357 | app=QApplication(sys.argv) 358 | mp.freeze_support() #避免在打包过程中出现无限弹窗 359 | window=Mainwindow() 360 | window.show() 361 | sys.exit(app.exec_()) 362 | -------------------------------------------------------------------------------- /menu.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | 4 | block_cipher = None 5 | 6 | 7 | a = Analysis(['menu.py'], 8 | pathex=['E:\\seafile\\downloadfile\\project\\completeUI'], 9 | binaries=[], 10 | datas=[], 11 | hiddenimports=[], 12 | hookspath=[], 13 | runtime_hooks=[], 14 | excludes=[], 15 | win_no_prefer_redirects=False, 16 | win_private_assemblies=False, 17 | cipher=block_cipher, 18 | noarchive=False) 19 | pyz = PYZ(a.pure, a.zipped_data, 20 | cipher=block_cipher) 21 | exe = EXE(pyz, 22 | a.scripts, 23 | [], 24 | exclude_binaries=True, 25 | name='menu', 26 | debug=False, 27 | bootloader_ignore_signals=False, 28 | strip=False, 29 | upx=True, 30 | console=True ) 31 | coll = COLLECT(exe, 32 | a.binaries, 33 | a.zipfiles, 34 | a.datas, 35 | strip=False, 36 | upx=True, 37 | upx_exclude=[], 38 | name='menu') 39 | -------------------------------------------------------------------------------- /model/pridect/model_best.pth.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/model/pridect/model_best.pth.tar -------------------------------------------------------------------------------- /model/pridect_Pccn/model_best.pth.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/model/pridect_Pccn/model_best.pth.tar -------------------------------------------------------------------------------- /model/pridect_tpcnn/model_best.pth.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/model/pridect_tpcnn/model_best.pth.tar -------------------------------------------------------------------------------- /nets.py: -------------------------------------------------------------------------------- 1 | 2 | from __future__ import print_function, division, absolute_import 3 | import os 4 | import torch 5 | import torch.nn as nn 6 | import torch.nn.functional as F 7 | 8 | torch.nn.SmoothL1Loss 9 | ####-------------------------------------------事先定义 10 | # # 三级平行模型(模型) 11 | class TPCNN(nn.Module): 12 | def __init__(self, num_class=10, head_payload=False): 13 | super(TPCNN, self).__init__() 14 | # 上 15 | self.uconv1 = nn.Sequential( # 16 | nn.Conv2d(1, 16, kernel_size=3, stride=1, padding=1, dilation=1, bias=True), 17 | nn.BatchNorm2d(16, eps=1e-05, momentum=0.9, affine=True), 18 | nn.ReLU(), 19 | ) 20 | self.uconv2 = nn.Sequential( # 21 | nn.Conv2d(16, 32, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 22 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 23 | nn.ReLU(), 24 | ) 25 | # 中 26 | self.mconv1 = nn.Sequential( # 27 | nn.Conv2d(1, 32, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 28 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 29 | nn.ReLU(), 30 | ) 31 | # 下 32 | self.dconv1 = nn.Sequential( # 33 | nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1, dilation=1, bias=True), 34 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 35 | nn.ReLU(), 36 | nn.MaxPool2d(kernel_size=2) 37 | ) 38 | 39 | self.uconv3 = nn.Sequential( # 40 | nn.Conv2d(96, 128, kernel_size=3, stride=1, padding=1, dilation=1, bias=True), 41 | nn.BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True), 42 | nn.ReLU(), 43 | ) 44 | 45 | self.mconv2 = nn.Sequential( # 46 | nn.Conv2d(96, 128, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 47 | nn.BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True), 48 | nn.ReLU(), 49 | ) 50 | 51 | self.dconv2 = nn.Sequential( # 52 | nn.Conv2d(96, 128, kernel_size=3, stride=1, padding=1, dilation=1, bias=True), 53 | nn.BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True), 54 | nn.ReLU(), 55 | ) 56 | 57 | self.uconv4 = nn.Sequential( # 58 | nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 59 | nn.BatchNorm2d(512, eps=1e-05, momentum=0.9, affine=True), 60 | nn.ReLU(), 61 | ) 62 | self.globalconv1 = nn.Sequential( 63 | nn.Conv2d(896, 1024, kernel_size=3, stride=1, padding=1), 64 | nn.BatchNorm2d(1024, eps=1e-05, momentum=0.9, affine=True), 65 | nn.ReLU() 66 | ) 67 | 68 | self.dmaxpool = nn.MaxPool2d(kernel_size=2,padding=1) 69 | 70 | # self.lstm1 = nn.LSTM(256,512, 2) 71 | # self.lstm2 = nn.LSTM(self.i_size*2,self.i_size*2, 2) 72 | 73 | self.avpool = nn.AdaptiveAvgPool2d(2) 74 | # self.globallstm = nn.LSTM(512, 256, 1) 75 | 76 | self.fc1 = nn.Linear(1024*2*2, 512) 77 | self.fc2 = nn.Linear(512, num_class) 78 | 79 | def forward(self, x,train): 80 | # print("x",x.shape) 81 | # 上 82 | uout = self.uconv1(x) 83 | uout = self.uconv2(uout) 84 | 85 | # 中 86 | mout = self.mconv1(x) 87 | 88 | # 下 89 | dout = self.dconv1(x) 90 | 91 | # 连接 92 | # print("uout", uout.shape) 93 | # print("mout", mout.shape) 94 | # print("dout", dout.shape) 95 | 96 | out = torch.cat((uout, mout, dout), dim=1) 97 | # print("out", out.shape) 98 | 99 | # 上 100 | uout = self.uconv3(out) 101 | 102 | # 中 103 | mout = self.mconv2(out) 104 | # 下 105 | dout = self.dconv2(out) 106 | 107 | # 连接 108 | # print("uout", uout.shape) 109 | # print("dout", dout.shape) 110 | 111 | out = torch.cat((uout, dout), dim=1) 112 | # print("out", out.shape) 113 | 114 | # 上 115 | uout = self.uconv4(out) 116 | 117 | # 中 118 | 119 | # 下 120 | dout = self.dmaxpool(out) 121 | 122 | # 连接 123 | # print("uout", uout.shape) 124 | # print("mout", mout.shape) 125 | # print("dout", dout.shape) 126 | 127 | out = torch.cat((uout, mout, dout), dim=1) 128 | # print("out",out.shape) 129 | # 最后的网络 130 | # print("out", out.shape) 131 | out = self.globalconv1(out) 132 | out = self.avpool(out) 133 | 134 | # 全连接层 135 | # print("out", out.shape) 136 | out=out.view(-1,1024*2*2) 137 | out = self.fc1(out) 138 | out = self.fc2(out) 139 | 140 | return out 141 | 142 | # 三级平行时序模型 143 | class TPCNN_C(nn.Module): 144 | def __init__(self, num_class=10, head_payload=False): 145 | super(TPCNN_C, self).__init__() 146 | # 上 147 | self.uconv1 = nn.Sequential( # 148 | nn.Conv2d(1, 16, kernel_size=3, stride=1, padding=1, dilation=1, bias=True), 149 | nn.BatchNorm2d(16, eps=1e-05, momentum=0.9, affine=True), 150 | nn.ReLU(), 151 | ) 152 | self.uconv2 = nn.Sequential( # 153 | nn.Conv2d(16, 32, kernel_size=3, stride=2, padding=0, dilation=1, bias=True), 154 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 155 | nn.ReLU(), 156 | ) 157 | # 中 158 | self.mconv1 = nn.Sequential( # 159 | nn.Conv2d(1, 32, kernel_size=3, stride=2, padding=0, dilation=1, bias=True), 160 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 161 | nn.ReLU(), 162 | ) 163 | # 下 164 | self.dconv1 = nn.Sequential( # 165 | nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=0, dilation=1, bias=True), 166 | nn.BatchNorm2d(32, eps=1e-05, momentum=0.9, affine=True), 167 | nn.ReLU(), 168 | nn.MaxPool2d(kernel_size=2) 169 | ) 170 | # 上 171 | self.uconv3 = nn.Sequential( # 172 | nn.Conv2d(96, 128, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 173 | nn.BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True), 174 | nn.ReLU(), 175 | ) 176 | # 中 177 | # self.mconv2 = nn.Sequential( # 178 | # nn.Conv2d(96,128, kernel_size=3, stride=2, padding=1,dilation=1,bias=True), 179 | # nn.BatchNorm2d(128,eps=1e-05,momentum=0.9,affine=True), 180 | # nn.ReLU(), 181 | # nn.MaxPool2d(kernel_size=2) 182 | # ) 183 | self.mlstm = nn.LSTM(48, 8, 2) 184 | 185 | # 下 186 | self.dconv2 = nn.Sequential( # 187 | nn.Conv2d(96, 128, kernel_size=3, stride=2, padding=1, dilation=1, bias=True), 188 | nn.BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True), 189 | nn.ReLU(), 190 | ) 191 | 192 | self.uconv4 = nn.Sequential( # 193 | nn.Conv2d(256, 256, kernel_size=2, stride=2, padding=0, dilation=1, bias=True),###______ 194 | nn.BatchNorm2d(256, eps=1e-05, momentum=0.9, affine=True), 195 | nn.ReLU(), 196 | ) 197 | self.globalconv1 = nn.Sequential( 198 | nn.Conv2d(912,912, kernel_size=3, stride=1, padding=1), 199 | nn.BatchNorm2d(912,eps=1e-05, momentum=0.9, affine=True), 200 | nn.ReLU() 201 | ) 202 | 203 | self.dmaxpool = nn.MaxPool2d(kernel_size=2) 204 | 205 | # self.lstm1 = nn.LSTM(256,512, 2) 206 | # self.lstm2 = nn.LSTM(self.i_size*2,self.i_size*2, 2) 207 | 208 | self.avpool = nn.AdaptiveAvgPool2d(2) 209 | # self.globallstm = nn.LSTM(512, 256, 1) 210 | 211 | self.fc1 = nn.Linear(912* 2*2, 128) 212 | self.fc2 = nn.Linear(128,num_class) 213 | 214 | 215 | def forward(self, x,train): 216 | # print(x.shape) 217 | # 上 218 | uout = self.uconv1(x) 219 | uout = self.uconv2(uout) 220 | # 中 221 | mout = self.mconv1(x) 222 | 223 | # 下 224 | dout = self.dconv1(x) 225 | 226 | # 连接 227 | out = torch.cat((uout, mout, dout), dim=1) 228 | # print("out", out.shape) 229 | 230 | # 上 231 | uout = self.uconv3(out) 232 | 233 | # 中 234 | # print(out.shape) 235 | # m=out.view(64,-1,48) 236 | m = out.view(out.size(0), -1, 48) 237 | mout,_= self.mlstm(m) 238 | # print("mout", mout.shape) 239 | 240 | # 下 241 | dout = self.dconv2(out) 242 | 243 | # 连接 244 | # print("uout",uout.shape) 245 | # print("mout", mout.shape) 246 | # print("dout", dout.shape) 247 | 248 | out = torch.cat((uout, dout), dim=1) 249 | # print("out", out.shape) 250 | 251 | # 上 252 | uout = self.uconv4(out) 253 | # print("uout",uout.shape) 254 | # 中 255 | 256 | # 下 257 | dout = self.dmaxpool(out) 258 | # print("dout",dout.shape) 259 | # 连接 260 | # 261 | 262 | mout = torch.reshape(mout, [mout.size(0), -1, 2, 2]) 263 | dout = torch.reshape(dout, [mout.size(0), -1, 2, 2]) 264 | uout = torch.reshape(uout, [mout.size(0), -1, 2, 2]) 265 | out = torch.cat((uout, mout, dout,), dim=1) 266 | 267 | # 最后的网络 268 | # print("out", out.shape) 269 | # print(out.shape) 270 | out = self.globalconv1(out) 271 | out = self.avpool(out) 272 | 273 | # 全连接层 274 | out=out.view(-1,912*2*2) 275 | # out = out.view(-1, 1024 * 2 * 2) 276 | out = self.fc1(out) 277 | out = self.fc2(out) 278 | # print("out", out.shape) 279 | 280 | return out 281 | 282 | 283 | #夏本辉师兄模型 284 | class Pccn(nn.Module): 285 | def __init__(self, num_class=12,head_payload=False): 286 | super(Pccn, self).__init__() 287 | self.globe_conv = nn.Sequential( 288 | nn.Conv2d(in_channels=1, out_channels=16, kernel_size=3, padding=1, stride=1, bias=False), 289 | nn.BatchNorm2d(16), 290 | nn.ReLU(), 291 | ) 292 | self.branchA_1 = nn.Sequential( 293 | nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, padding=1, stride=2, bias=False), 294 | nn.BatchNorm2d(32), 295 | nn.ReLU(), 296 | ) 297 | self.branchA_2 = nn.Sequential( 298 | nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, padding=1, stride=1, bias=False), 299 | nn.BatchNorm2d(32), 300 | nn.ReLU(), 301 | nn.MaxPool2d(kernel_size=2, padding=0, stride=2), 302 | ) 303 | self.shortcut_1 = nn.Sequential( 304 | nn.Conv2d(in_channels=16, out_channels=64, kernel_size=1, padding=0, stride=2, bias=False), 305 | nn.BatchNorm2d(64), 306 | nn.ReLU(), 307 | ) 308 | self.branchB_1 = nn.Sequential( 309 | nn.Conv2d(in_channels=64, out_channels=96, kernel_size=3, padding=1, stride=1, bias=False), 310 | nn.BatchNorm2d(96), 311 | nn.ReLU(), 312 | ) 313 | self.branchB_2 = nn.Sequential( 314 | nn.Conv2d(in_channels=64, out_channels=96, kernel_size=3, padding=1, stride=1, bias=False), 315 | nn.BatchNorm2d(96), 316 | nn.ReLU(), 317 | ) 318 | self.shortcut_2 = nn.Sequential( 319 | nn.Conv2d(in_channels=64, out_channels=192, kernel_size=1, padding=0, stride=1, bias=False), 320 | nn.BatchNorm2d(192), 321 | nn.ReLU(), 322 | ) 323 | self.branchC_1 = nn.Sequential( 324 | nn.Conv2d(in_channels=192, out_channels=256, kernel_size=3, padding=1, stride=2, bias=False), 325 | nn.BatchNorm2d(256), 326 | nn.ReLU(), 327 | ) 328 | self.branchC_2 = nn.Sequential( 329 | nn.MaxPool2d(kernel_size=2, padding=1, stride=2), 330 | ) 331 | self.shortcut_3 = nn.Sequential( 332 | nn.Conv2d(in_channels=192, out_channels=448, kernel_size=1, padding=0, stride=2, bias=False), 333 | nn.BatchNorm2d(448), 334 | nn.ReLU(), 335 | ) 336 | self.globe_conv_2 = nn.Sequential( 337 | nn.Conv2d(in_channels=448, out_channels=896, kernel_size=3, padding=1, stride=1, bias=False), 338 | nn.BatchNorm2d(896), 339 | nn.ReLU(), 340 | ) 341 | self.max_pool = nn.Sequential(nn.MaxPool2d(kernel_size=4)) 342 | self.fc = nn.Linear(896, num_class) 343 | def forward(self, x,train): 344 | x = self.globe_conv(x) 345 | out_1 = self.branchA_1(x) 346 | out_2 = self.branchA_2(x) 347 | out = torch.cat([out_1, out_2], dim=1) 348 | x = self.shortcut_1(x) 349 | out += x 350 | out = F.relu(out) 351 | out_1 = self.branchB_1(out) 352 | out_2 = self.branchB_2(out) 353 | out = torch.cat([out_1, out_2], dim=1) 354 | x = self.shortcut_2(x) 355 | out += x 356 | out = F.relu(out) 357 | out_1 = self.branchC_1(out) 358 | out_2 = self.branchC_2(out) 359 | # print("out_1",out_1.shape) 360 | # print("out_2",out_2.shape) 361 | out = torch.cat([out_1, out_2], dim=1) 362 | # print("out",out.shape) 363 | x = self.shortcut_3(x) 364 | # print("x",x.shape) 365 | out += x 366 | out = F.relu(out) 367 | out = self.globe_conv_2(out) 368 | out = self.max_pool(out) 369 | out = out.view(-1, 896 * 1 * 1) 370 | out = self.fc(out) 371 | return out -------------------------------------------------------------------------------- /picture.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | resources/停止.png 4 | resources/执行.png 5 | resources/exit.png 6 | resources/min.png 7 | resources/restore.png 8 | resources/short.png 9 | resources/识别图标.png 10 | resources/camera.png 11 | resources/label_pic.png 12 | resources/风车.png 13 | 14 | 15 | -------------------------------------------------------------------------------- /predict_c_2.py: -------------------------------------------------------------------------------- 1 | import time 2 | import pandas as pd 3 | import torch 4 | import nets as my_new_nets 5 | import torch.nn as nn 6 | class predict(): 7 | def __init__(self,path): 8 | self.path=path 9 | print('\nreading datset, waiting ...... ') 10 | self.start = time.time() 11 | 12 | # model1 13 | self.model=my_new_nets.TPCNN_C(num_class=13,head_payload=True) 14 | # model = nn.DataParallel(model) 15 | # torch.backends.cudnn.benchmark = True 16 | self.model = nn.DataParallel(self.model).cuda() 17 | self.state = { 18 | 'state_dict':self.model.state_dict(), # 模型内部的参数,包括每层的权重,偏置等等 19 | } 20 | self.model.load_state_dict(torch.load("./model/pridect/model_best.pth.tar")['state_dict']) 21 | # print(self.model.load_state_dict(torch.load("./model/TPCCL_C/model_best.pth.tar")['state_dict'])) 22 | self.model.eval() 23 | self.predicted_all=[] 24 | # self.predicted=[] 25 | # self.predicted_label=[] 26 | 27 | #model2 28 | self.model2=my_new_nets.TPCNN(num_class=13,head_payload=True) 29 | self.model2=nn.DataParallel(self.model2).cuda() 30 | self.state2= { 31 | 'state_dict': self.model2.state_dict(), # 模型内部的参数,包括每层的权重,偏置等等 32 | } 33 | self.model2.load_state_dict(torch.load("./model/pridect_tpcnn/model_best.pth.tar")['state_dict']) 34 | self.model2.eval() 35 | self.predicted_all2=[] 36 | # self.predicted2=[] 37 | # self.predicted_label2=[] 38 | 39 | #model3 40 | self.model3=my_new_nets.Pccn(num_class=13, head_payload=True) 41 | self.model3=nn.DataParallel(self.model3).cuda() 42 | self.state3= { 43 | 'state_dict': self.model3.state_dict(), # 模型内部的参数,包括每层的权重,偏置等等 44 | } 45 | self.model3.load_state_dict(torch.load("./model/pridect_Pccn/model_best.pth.tar")['state_dict']) 46 | self.model3.eval() 47 | self.predicted_all3 = [] 48 | #为页面展示制作所建 49 | self.save_flow_member=[] 50 | self.save_flow_name=[] 51 | def softmax(self,x): 52 | x_exp = x.exp() # m * n 53 | partition = x_exp.sum(dim=1, keepdim=True) # 按列累加, m * 1 54 | return x_exp / partition # 广播机制, [m * n] / [m * 1] = [m * n] 55 | 56 | #预测函数model1 57 | def predict(self,data,train=True): 58 | torch.set_grad_enabled(True) 59 | outputs =self.model(data, train) 60 | outputs=self.softmax(outputs) 61 | _,predicted=torch.max(outputs,1) 62 | predicted=predicted.cpu().numpy() 63 | return predicted 64 | 65 | #预测函数model2 66 | def predict2(self,data,train=True): 67 | torch.set_grad_enabled(True) 68 | outputs =self.model2(data, train) 69 | outputs=self.softmax(outputs) 70 | _,predicted=torch.max(outputs,1) 71 | predicted=predicted.cpu().numpy() 72 | return predicted 73 | #预测函数model3 74 | def predict3(self,data,train=True): 75 | torch.set_grad_enabled(True) 76 | outputs =self.model3(data, train) 77 | outputs=self.softmax(outputs) 78 | _,predicted=torch.max(outputs,1) 79 | predicted=predicted.cpu().numpy() 80 | return predicted 81 | #保存结果数据 82 | def save_excel(self,): 83 | import xlwt 84 | # 创建一个workbook 设置编码 85 | workbook = xlwt.Workbook(encoding='utf-8') 86 | # 创建一个worksheet 87 | worksheet = workbook.add_sheet('My Worksheet') 88 | worksheet.write(0,0,label='label') 89 | worksheet.write(0,1,label='classes') 90 | for i in range(len(self.save_flow_member)): 91 | worksheet.write(i+1,0,label=self.save_flow_member[i]) 92 | worksheet.write(i+1,1,label=self.save_flow_name[i]) 93 | workbook.save('./data/show_label.csv') 94 | data = pd.read_excel('./data/show_label.csv', index_col=0) 95 | data.to_csv('./data/show_label.csv', encoding='utf-8') 96 | 97 | #model1 98 | def finallmainmodel1(self,): 99 | file=pd.read_csv(self.path) 100 | print(file.shape) 101 | print(len(file)) 102 | for i in range(1, (len(file) //64) + 2): 103 | # print(i) 104 | if (i *64) < len(file): 105 | predict_data = file.values[(i - 1) *64:i *64, 1:] 106 | predict_data = torch.from_numpy(predict_data) 107 | predict_data = predict_data.float() 108 | # print(predict_data.shape) 109 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 110 | predicted = self.predict(predict_data) 111 | # print(len(predicted)) 112 | for i in range(len(predicted)): 113 | if predicted[i]==12: 114 | self.predicted_all.append(0) 115 | else: 116 | self.predicted_all.append(1) 117 | else: 118 | predict_data = file.values[len(file)-64:len(file), 1:] 119 | # predict_label = file.values[len(file)-64:len(file), -1] 120 | predict_data = torch.from_numpy(predict_data) 121 | predict_data = predict_data.float() 122 | # print("11", len(file)-64) 123 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 124 | predicted = self.predict(predict_data, False) 125 | # print(len(predicted)) 126 | for i in range(len(predicted)): 127 | if predicted[i] == 12: 128 | self.predicted_all.append(0) 129 | else: 130 | self.predicted_all.append(1) 131 | #model2 132 | def finallmainmodel2(self, ): 133 | file = pd.read_csv(self.path) 134 | print(file.shape) 135 | print(len(file)) 136 | for i in range(1, (len(file) // 64) + 2): 137 | # print(i) 138 | if (i * 64) < len(file): 139 | predict_data = file.values[(i - 1) * 64:i * 64, 1:] 140 | predict_data = torch.from_numpy(predict_data) 141 | predict_data = predict_data.float() 142 | # print(predict_data.shape) 143 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 144 | predicted = self.predict2(predict_data) 145 | # print(len(predicted)) 146 | for i in range(len(predicted)): 147 | if predicted[i] == 12: 148 | self.predicted_all2.append(0) 149 | else: 150 | self.predicted_all2.append(1) 151 | else: 152 | predict_data = file.values[len(file) - 64:len(file), 1:] 153 | # predict_label = file.values[len(file)-64:len(file), -1] 154 | predict_data = torch.from_numpy(predict_data) 155 | predict_data = predict_data.float() 156 | # print("11", len(file)-64) 157 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 158 | predicted = self.predict2(predict_data, False) 159 | # print(len(predicted)) 160 | for i in range(len(predicted)): 161 | if predicted[i] == 12: 162 | self.predicted_all2.append(0) 163 | else: 164 | self.predicted_all2.append(1) 165 | #model3 166 | def finallmainmodel3(self, ): 167 | file = pd.read_csv(self.path) 168 | print(file.shape) 169 | print(len(file)) 170 | for i in range(1, (len(file) // 64) + 2): 171 | # print(i) 172 | if (i * 64) < len(file): 173 | predict_data = file.values[(i - 1) * 64:i * 64, 1:] 174 | predict_data = torch.from_numpy(predict_data) 175 | predict_data = predict_data.float() 176 | # print(predict_data.shape) 177 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 178 | predicted = self.predict3(predict_data) 179 | # print(len(predicted)) 180 | for i in range(len(predicted)): 181 | if predicted[i] == 12: 182 | self.predicted_all3.append(0) 183 | else: 184 | self.predicted_all3.append(1) 185 | else: 186 | predict_data = file.values[len(file) - 64:len(file), 1:] 187 | # predict_label = file.values[len(file)-64:len(file), -1] 188 | predict_data = torch.from_numpy(predict_data) 189 | predict_data = predict_data.float() 190 | # print("11", len(file)-64) 191 | predict_data = predict_data.view(predict_data.shape[0], 1, 22, 22) 192 | predicted = self.predict3(predict_data, False) 193 | # print(len(predicted)) 194 | for i in range(len(predicted)): 195 | if predicted[i] == 12: 196 | self.predicted_all3.append(0) 197 | else: 198 | self.predicted_all3.append(1) 199 | def statistic(self,): 200 | count0 = 0 201 | count1 = 0 202 | for i in range(len(self.predicted_all)): 203 | if self.judgment(self.predicted_all[i],self.predicted_all2[i],self.predicted_all3[i])==0: 204 | count0+=1 205 | self.save_flow_member.append(0) 206 | self.save_flow_name.append('Normal') 207 | else: 208 | count1+=1 209 | self.save_flow_member.append(1) 210 | self.save_flow_name.append('Abnormal') 211 | print("0", count0);print("1", count1); 212 | print(self.save_flow_member) 213 | print(self.save_flow_name) 214 | self.save_excel() 215 | def judgment(self,pmodel1,pmodel2,pmodel3): 216 | if (pmodel1==pmodel2==pmodel3 and pmodel1==0) or (pmodel1==pmodel2 and pmodel1==0) or (pmodel1==pmodel3 and pmodel3==0) or (pmodel2==pmodel3 and pmodel2==0): 217 | return 0 218 | else: 219 | return 1 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /prepare.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | #!/usr/bin/python 3 | #-*- encoding:utf-8 -*- 4 | 5 | import numpy as np 6 | import time 7 | import pandas as pd 8 | import torch 9 | import tqdm 10 | import shutil 11 | import torch.optim as optim 12 | import torch.nn as nn 13 | from torch.autograd import Variable 14 | from torch.utils.data import Dataset, DataLoader 15 | from sklearn.model_selection import train_test_split 16 | 17 | 18 | 19 | def train(train_loader,model,loss_function,optimizer,epoch): 20 | ''' 21 | train_data: train data,include label in the last dimension 22 | model: net model 23 | loss: type of loss to be used 24 | optimizer: training optimmizer 25 | epoch: current epoch 26 | return: None 27 | ''' 28 | batch_time =AverageMeter() 29 | data_time = AverageMeter() 30 | losses = AverageMeter() 31 | acc = AverageMeter() 32 | losses_list=[] 33 | accuracy_list=[] 34 | model.train() 35 | 36 | end = time.time() 37 | 38 | for step,(feature,label) in enumerate(train_loader): # feature 返回的是数据集的数据,label返回的是标签 39 | feature = Variable(feature).cuda(non_blocking=True) 40 | label = Variable(label).cuda(non_blocking=True) 41 | # input feature to train,得到预测标签y_pred 42 | y_pred = model(feature,train=True) 43 | # 将输出值输入到损失函数进行处理 44 | # squeeze()默认将所有的1的维度删除,此时输入的label是[256,1],squeeze后是[256],相当于都存放在一个数据里面了 45 | loss = loss_function(y_pred,label.squeeze()) 46 | 47 | # losses_list.append(loss.item()) #保存损失度画图 48 | 49 | # label_sqe = label.squeeze() 50 | # input the value of loss to the variable losses 51 | # print(feature.size(0)) 52 | losses.update(loss.item(),feature.size(0)) 53 | # compute accuracy,batch_size = 256,y_pred 的shape(256,12) 分别判断这256个流量里面属于12个分类的准确率 54 | # 获得本次输入的准确率 55 | pred_acc,pred_count = accuracy(y_pred.data,label,topk=(1,1)) 56 | acc.update(pred_acc,pred_count) 57 | 58 | # accuracy_list.append(pred_acc) #保存精度画图 59 | 60 | optimizer.zero_grad() # 梯度清0 61 | loss.backward() 62 | optimizer.step() 63 | 64 | 65 | batch_time.update(time.time() - end,1) #更新时间 66 | end = time.time() 67 | 68 | 69 | if step % 10 == 0: 70 | print('epoch:[{0}][{1}/{2}]\t' 71 | 'Time:{batch_time.val:.3f} ({batch_time.avg:.3f})\t' 72 | 'Loss:{loss.val:.4f} ({loss.avg:.4f})\t' 73 | 'Accuracy:{acc.val:.3f} ({acc.avg:.3f})'.format( 74 | epoch,step,len(train_loader),batch_time=batch_time,loss=losses,acc=acc 75 | ) 76 | ) 77 | # return accuracy_list,losses_list 78 | 79 | def validate(validate_loader,model,loss_function,best_precision,lowest_loss): 80 | batch_time = AverageMeter() 81 | losses = AverageMeter() 82 | acc = AverageMeter() 83 | 84 | #switch to evaluable mode,forbidden batchnormalization and dropout 85 | model.eval() 86 | 87 | end = time.time() 88 | for step,(feature,label) in enumerate(validate_loader): 89 | # feature,label = data 90 | 91 | feature = Variable(feature).cuda(non_blocking=True) 92 | label = Variable(label).cuda(non_blocking=True) 93 | 94 | with torch.no_grad(): # 停止梯度的计算,节省GPU算力和显存 95 | y_pred = model(feature,train=True) 96 | loss = loss_function(y_pred,label.squeeze()) 97 | 98 | #measure accuracy and record loss 99 | pred_acc,PRED_COUNT = accuracy(y_pred.data,label,topk=(1,1)) 100 | losses.update(loss.item(),feature.size(0)) 101 | acc.update(pred_acc,PRED_COUNT) 102 | 103 | 104 | batch_time.update(time.time()-end,1) 105 | end = time.time() 106 | 107 | if step % 10 == 0: 108 | print('TrainVal: [{0}/{1}]\t' 109 | 'Time {batch_time.val:.3f} ({batch_time.avg:.3f})\t' 110 | 'Loss {loss.val:.4f} ({loss.avg:.4f})\t' 111 | 'Accuray {acc.val:.3f} ({acc.avg:.3f})'.format( 112 | step, len(validate_loader), batch_time=batch_time, loss=losses, acc=acc)) 113 | 114 | print(' * Accuray {acc.avg:.3f}'.format(acc=acc), '(Previous Best Acc: %.3f)' % best_precision, 115 | ' * Loss {loss.avg:.3f}'.format(loss=losses), 'Previous Lowest Loss: %.3f)' % lowest_loss) 116 | return acc.avg,losses.avg 117 | 118 | 119 | def test(test_loader, model, num_class, topk=1, ): 120 | """ 121 | test_loader: test data, type of DataLoader 122 | model: pretrained model 123 | filename: the file used to save inference result 124 | """ 125 | top1_prob = [] 126 | top1_pred_label = [] 127 | topk_prob = [] 128 | topk_pred_label = [] 129 | actual_label = [] 130 | correct = 0 131 | train = False 132 | 133 | predict_num = torch.zeros((1, num_class)) 134 | acc_num = torch.zeros((1, num_class)) 135 | target_num = torch.zeros((1, num_class)) 136 | topk_predict_num = torch.zeros((1, num_class)) 137 | topk_acc_num = torch.zeros((1, num_class)) 138 | topk_target_num = torch.zeros((1, num_class)) 139 | 140 | model.eval() 141 | for step, (feature, label) in enumerate(test_loader): 142 | # retrun the testing feature and it label 143 | feature = Variable(feature) 144 | label = Variable(label) 145 | 146 | with torch.no_grad(): 147 | y_pred = model(feature, train) 148 | # 使用softmax预测结果 149 | smax = nn.Softmax(1) 150 | smax_out = smax(y_pred) 151 | 152 | probility, pred_label = torch.topk(smax_out, topk) 153 | p1, l1 = torch.topk(smax_out, 1) # 返回top1 154 | # 使用scatter 根据l1.view(-1,1)对全0数组进行分配,对预测最大值的位置置1 155 | top1_mask = torch.zeros(y_pred.size()).scatter_(1, l1.cpu().view(-1, 1), 1) 156 | topk_mask = torch.zeros(y_pred.size()) 157 | topk_label_index = pred_label.view(1, -1) 158 | # 根据输入的batch_size,即feature的行数生成列表 159 | topk_label_row = np.array([[x] * topk for x in range(feature.size(0))]).reshape(1, -1).tolist() 160 | 161 | topk_mask[topk_label_row, topk_label_index] = 1 162 | actual_mask = torch.zeros(y_pred.size()).scatter_(1, label.cpu().view(-1, 1), 1) 163 | top1_acc_mask = top1_mask * actual_mask 164 | topk_acc_mask = topk_mask * actual_mask 165 | # 判断正确的数量 166 | acc_num += top1_acc_mask.sum(0) 167 | predict_num += top1_mask.sum(0) 168 | target_num += actual_mask.sum(0) 169 | topk_acc_num += topk_acc_mask.sum(0) 170 | topk_predict_num += topk_mask.sum(0) 171 | topk_target_num += actual_mask.sum(0) 172 | 173 | actual_label += label.squeeze().tolist() 174 | topk_prob += probility.tolist() 175 | topk_pred_label += pred_label.tolist() 176 | top1_prob += p1.tolist() 177 | top1_pred_label += l1.tolist() 178 | 179 | # 里面储存的是测试集所有数据的预测标签和预测值 180 | top1_prob = np.array(top1_prob) 181 | top1_pred_label = np.array(top1_pred_label) 182 | topk_prob = np.array(topk_prob) 183 | topk_pred_label = np.array(topk_pred_label) 184 | actual_label = np.array(actual_label).reshape(-1, 1) 185 | # acc_num = tp target_num = TP+FN predict_num = tp+fp (预测正确+预测为正确但是错误的) 186 | recall = acc_num / target_num 187 | precision = acc_num / predict_num 188 | F1 = 2 * recall * precision / (recall + precision) 189 | # accuracy = (TP+TN)/(total example) 190 | accuracy = acc_num.sum(1) / target_num.sum(1) 191 | # accuracys = acc_num / target_num 192 | topk_recall = topk_acc_num / topk_target_num 193 | topk_precision = topk_acc_num / topk_predict_num 194 | topk_F1 = 2 * topk_recall * topk_precision / (topk_recall + topk_precision) 195 | topk_accuracy = topk_acc_num.sum(1) / topk_target_num.sum(1) 196 | # topk_accuracys = topk_acc_num / topk_target_num 197 | 198 | recall = (recall.numpy() * 100).round(4) 199 | precision = (precision.numpy() * 100).round(4) 200 | F1 = (F1.numpy() * 100).round(4) 201 | accuracy = (accuracy.numpy() * 100).round(4) 202 | # accuracys = (accuracys.numpy()*100).round(4) 203 | topk_recall = (topk_recall.numpy() * 100).round(4) 204 | topk_precision = (topk_precision.numpy() * 100).round(4) 205 | topk_F1 = (topk_F1.numpy() * 100).round(4) 206 | topk_accuracy = (topk_accuracy.numpy() * 100).round(4) 207 | # topk_accuracys = (topk_accuracys.numpy()*100).round(4) 208 | 209 | result = (top1_prob, top1_pred_label, topk_prob, topk_pred_label, actual_label) 210 | top1_metrics = (accuracy, recall, precision, F1) 211 | topk_metrics = (topk_accuracy, topk_recall, topk_precision, topk_F1) 212 | 213 | 214 | return result, top1_metrics, topk_metrics 215 | 216 | 217 | def accuracy(y_pred,y_label,topk=(1,)): # 默认去top1准确率 218 | """" 219 | y_pred: the net predected label 220 | y_label: the actual label 221 | topk: the top k accuracy 222 | return: accuracy and data length 223 | """ 224 | final_acc = 0 225 | maxk = max(topk) 226 | 227 | PRED_COUNT = y_label.size(0) 228 | #预测准确的数量 229 | PRED_CORRECT_COUNT = 0 230 | # 获得y_pred 对12个类别的top k值(此时k=1),返回prob是按大小排序后的值,pred_label是索引 231 | prob,pred_label = y_pred.topk(maxk,dim=1,largest=True,sorted=True) 232 | for x in range(pred_label.size(0)): # 遍历每一行(即每一个数据流) 233 | if int(pred_label[x]) == y_label[x]: # 判断标签是否正确 234 | PRED_CORRECT_COUNT += 1 235 | 236 | if PRED_COUNT == 0: 237 | return final_acc 238 | 239 | final_acc = PRED_CORRECT_COUNT / PRED_COUNT 240 | return final_acc*100,PRED_COUNT 241 | 242 | 243 | def adjust_learning_rate(model,weight_decay,base_lr,lr_decay): 244 | base_lr = base_lr / lr_decay 245 | return optim.Adam(model.parameters(),base_lr,weight_decay=weight_decay,amsgrad=True) 246 | 247 | def save_checkpoint(state,is_best,is_lowest_loss,filename): 248 | s_filename = './model/%s/checkpoint.pth.tar' %filename 249 | torch.save(state,s_filename) 250 | if is_best: 251 | shutil.copyfile(s_filename,'./model/%s/model_best.pth.tar' %filename) 252 | if is_lowest_loss: 253 | shutil.copyfile(s_filename,'./model/%s/lowest_loss.pth.tar' %filename) 254 | 255 | 256 | class DealDataSet(Dataset): # 将数据从numpy转换成tensor 257 | def __init__(self,data_list,header_payload=True): 258 | #将数据转换成tensor 259 | self.x = torch.from_numpy(data_list[:,:-1]) 260 | # 修改数据类型从LongTensor为FloatTensor 261 | self.x = self.x.type(torch.FloatTensor) 262 | if header_payload ==True: # 判断读取的数据是否包含header、payload 263 | self.x = self.x.view(self.x.shape[0],1,22,22) 264 | else: 265 | self.x = self.x.view(self.x.shape[0],1,16,16) 266 | self.y = torch.from_numpy(data_list[:,[-1]]) 267 | self.y = self.y.type(torch.LongTensor) 268 | self.len = self.x.shape[0] 269 | self.xshape = self.x.shape 270 | self.yshape = self.y.shape 271 | 272 | 273 | def __getitem__(self,index): 274 | return self.x[index],self.y[index] 275 | 276 | def __len__(self): 277 | return self.len 278 | 279 | 280 | 281 | 282 | class AverageMeter(object): 283 | """计算和保存当前值与平均值""" 284 | def __init__(self): 285 | self.reset() 286 | 287 | def reset(self): 288 | self.val = 0 289 | self.avg = 0 290 | self.sum = 0 291 | self.count = 0 292 | 293 | def update(self,val,n=1): 294 | self.val = val 295 | self.sum += val*n 296 | self.count += n 297 | self.avg = self.sum / self.count 298 | 299 | class TrainDataSetPayload_2012(): 300 | 301 | def __init__(self, ): 302 | super(TrainDataSetPayload_2012, self).__init__() 303 | 304 | def read_csv(self): 305 | # payload_benign = pd.read_csv('./2012dataset/label_Bruteforce_SSH.csv') 306 | payload_nonclassifed = pd.read_csv('./2012dataset/label_non-classifed_attacks.csv') 307 | payload_inflter = pd.read_csv('./2012dataset/label_Infltering.csv') 308 | payload_http = pd.read_csv('./2012dataset/label_HTTP.CSV') 309 | payload_distributedenial = pd.read_csv('./2012dataset/label_Distributed_denial.csv') 310 | payload_brutessh = pd.read_csv('./2012dataset/label_Bruteforce_SSH.csv') 311 | 312 | # print('finish reading dataset, cost time :',time.time() - start) 313 | # 剔除第一列 314 | # benign = payload_benign.values[:, 1:] 315 | nonclassifed = payload_nonclassifed.values[:, 0:] 316 | inflter = payload_inflter.values[:, 0:] 317 | http = payload_http.values[:, 0:] 318 | distributedenial = payload_distributedenial.values[:, 0:] 319 | brutessh = payload_brutessh.values[:, 0:] 320 | 321 | return nonclassifed, inflter, http, distributedenial, brutessh 322 | 323 | def get_item(self): 324 | nonclassifed, inflter, http, distributedenial, brutessh = self.read_csv() 325 | 326 | # print('shape of benign: ', benign.shape) 327 | print('shape of nonclassifed: ', nonclassifed.shape) 328 | print('shape of inflter: ', inflter.shape) 329 | print('shape of http: ', http.shape) 330 | print('shape of distributedenial: ', distributedenial.shape) 331 | print('shape of rutessh: ', brutessh.shape) 332 | 333 | # 剔除最后一列标签 334 | # x_benign = benign[:, :-1] 335 | x_nonclassifed = nonclassifed[:, :-1] 336 | x_inflter = inflter[:, :-1] 337 | x_http = http[:, :-1] 338 | x_distributedenial = distributedenial[:, :-1] 339 | x_brutessh = brutessh[:, :-1] 340 | 341 | # 获取标签 342 | # y_benign = benign[:, -1] 343 | y_nonclassifed = nonclassifed[:, -1] 344 | y_inflter = inflter[:, -1] 345 | y_http = http[:, -1] 346 | y_distributedenial = distributedenial[:, -1] 347 | y_brutessh = brutessh[:, -1] 348 | 349 | # x_tr_benign, x_te_benign, y_tr_benign, y_te_benign = train_test_split(x_benign, y_benign, test_size=0.2,random_state=1) 350 | x_tr_nonclassifed, x_te_nonclassifed, y_tr_nonclassifed, y_te_nonclassifed = train_test_split(x_nonclassifed, 351 | y_nonclassifed, 352 | test_size=0.2, 353 | random_state=1) 354 | x_tr_inflter, x_te_inflter, y_tr_inflter, y_te_inflter = train_test_split(x_inflter, y_inflter, test_size=0.2, 355 | random_state=1) 356 | x_tr_http, x_te_http, y_tr_http, y_te_http = train_test_split(x_http, y_http, test_size=0.2, random_state=1) 357 | x_tr_distributedenial, x_te_distributedenial, y_tr_distributedenial, y_te_distributedenial = train_test_split( 358 | x_distributedenial, y_distributedenial, test_size=0.2, random_state=1) 359 | x_tr_brutessh, x_te_brutessh, y_tr_brutessh, y_te_brutessh = train_test_split(x_brutessh, y_brutessh, 360 | test_size=0.2, random_state=1) 361 | 362 | x_train = np.concatenate( 363 | (x_tr_nonclassifed, x_tr_inflter, x_tr_http, x_tr_distributedenial, x_tr_brutessh)) 364 | y_train = np.concatenate( 365 | (y_tr_nonclassifed, y_tr_inflter, y_tr_http, y_tr_distributedenial, y_tr_brutessh)) 366 | 367 | x_test = np.concatenate( 368 | (x_te_nonclassifed, x_te_inflter, x_te_http, x_te_distributedenial, x_te_brutessh)) 369 | y_test = np.concatenate( 370 | (y_te_nonclassifed, y_te_inflter, y_te_http, y_te_distributedenial, y_te_brutessh)) 371 | 372 | return x_train, y_train, x_test, y_test 373 | 374 | class TrainDataSetPayload_2012_cat(): 375 | 376 | def __init__(self,data_type ): 377 | self.data_type = data_type 378 | super(TrainDataSetPayload_2012_cat, self).__init__() 379 | 380 | def read_csv(self): 381 | if self.data_type==1: 382 | payload_bengin = pd.read_csv('./data/4/5/label_bengin.CSV') 383 | payload_nonclassifed = pd.read_csv('./data/4/5/label_non-classifed_attacks.CSV') 384 | payload_inflter = pd.read_csv('./data/4/5/label_Infltering.CSV') 385 | payload_http = pd.read_csv('./data/4/5/label_HTTP.CSV') 386 | payload_distributedenial = pd.read_csv('./data/4/5/label_Distributed_denial.CSV') 387 | payload_brutessh = pd.read_csv('./data/4/5/label_Bruteforce_SSH.CSV') 388 | elif self.data_type==2: 389 | payload_nonclassifed = pd.read_csv('./6/2/label_non-classifed_attacks.csv') 390 | payload_inflter = pd.read_csv('./6/2/label_Infltering.csv') 391 | payload_http = pd.read_csv('./6/2/label_HTTP.CSV') 392 | payload_distributedenial = pd.read_csv('./6/2/label_Distributed_denial.csv') 393 | payload_brutessh = pd.read_csv('./6/2/label_Bruteforce_SSH.csv') 394 | # payload_bengin=pd.read_csv("./7/label_bengin.csv") 395 | # print('finish reading dataset, cost time :',time.time() - start) 396 | # 剔除第一列 397 | # benign = payload_benign.values[:, 1:] 398 | nonclassifed = payload_nonclassifed.values[:, 1:] 399 | inflter = payload_inflter.values[:, 1:] 400 | http = payload_http.values[:, 1:] 401 | distributedenial = payload_distributedenial.values[:, 1:] 402 | brutessh = payload_brutessh.values[:, 1:] 403 | bengin=payload_bengin.values[:,1:] 404 | 405 | 406 | return nonclassifed, inflter, http, distributedenial, brutessh ,bengin 407 | 408 | def get_item(self): 409 | nonclassifed, inflter, http, distributedenial, brutessh, bengin= self.read_csv() 410 | 411 | # print('shape of benign: ', benign.shape) 412 | print('shape of nonclassifed: ', nonclassifed.shape) 413 | print('shape of inflter: ', inflter.shape) 414 | print('shape of http: ', http.shape) 415 | print('shape of distributedenial: ', distributedenial.shape) 416 | print('shape of rutessh: ', brutessh.shape) 417 | print('shape of bengin: ', bengin.shape) 418 | 419 | # 剔除最后一列标签 420 | # x_benign = benign[:, :-1] 421 | x_nonclassifed = nonclassifed[:, :-1] 422 | x_inflter = inflter[:, :-1] 423 | D_x_inflter=(x_inflter,x_nonclassifed) 424 | x_inflter=np.concatenate(D_x_inflter,axis=0) 425 | x_http = http[:, :-1] 426 | x_distributedenial = distributedenial[:, :-1] 427 | x_brutessh = brutessh[:, :-1] 428 | x_bengin=bengin[:,:-1] 429 | 430 | # 获取标签 431 | y_benign = bengin[:, -1] 432 | y_nonclassifed = nonclassifed[:, -1] 433 | y_inflter = inflter[:, -1] 434 | D_y_inflter=(y_nonclassifed,y_inflter) 435 | y_inflter=np.concatenate(D_y_inflter,axis=0) 436 | y_http = http[:, -1] 437 | y_distributedenial = distributedenial[:, -1] 438 | y_brutessh = brutessh[:, -1] 439 | 440 | x_tr_benign, x_te_benign, y_tr_benign, y_te_benign = train_test_split(x_bengin, y_benign, test_size=0.2,random_state=1) 441 | # x_tr_nonclassifed, x_te_nonclassifed, y_tr_nonclassifed, y_te_nonclassifed = train_test_split(x_nonclassifed, 442 | # y_nonclassifed, 443 | # test_size=0.2, 444 | # random_state=1) 445 | x_tr_inflter, x_te_inflter, y_tr_inflter, y_te_inflter = train_test_split(x_inflter, y_inflter, test_size=0.2, 446 | random_state=1) 447 | x_tr_http, x_te_http, y_tr_http, y_te_http = train_test_split(x_http, y_http, test_size=0.2, random_state=1) 448 | x_tr_distributedenial, x_te_distributedenial, y_tr_distributedenial, y_te_distributedenial = train_test_split( 449 | x_distributedenial, y_distributedenial, test_size=0.2, random_state=1) 450 | x_tr_brutessh, x_te_brutessh, y_tr_brutessh, y_te_brutessh = train_test_split(x_brutessh, y_brutessh, 451 | test_size=0.2, random_state=1) 452 | 453 | x_train = np.concatenate( 454 | (x_tr_benign,x_tr_inflter, x_tr_http, x_tr_distributedenial, x_tr_brutessh)) 455 | y_train = np.concatenate( 456 | (y_tr_benign,y_tr_inflter, y_tr_http, y_tr_distributedenial, y_tr_brutessh)) 457 | 458 | x_test = np.concatenate( 459 | (x_te_benign,x_te_inflter, x_te_http, x_te_distributedenial, x_te_brutessh)) 460 | y_test = np.concatenate( 461 | (y_te_benign,y_te_inflter, y_te_http, y_te_distributedenial, y_te_brutessh)) 462 | 463 | return x_train, y_train, x_test, y_test 464 | 465 | 466 | 467 | -------------------------------------------------------------------------------- /save.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/save.pkl -------------------------------------------------------------------------------- /sniff.py: -------------------------------------------------------------------------------- 1 | from scapy.all import * 2 | import pyshark 3 | 4 | def pack_callback(packet): 5 | print ( packet.show() ) 6 | if packet['Ether'].payload: 7 | # print(packet) 8 | print (packet['Ether'].src) 9 | print (packet['Ether'].dst) 10 | print (packet['Ether'].type) 11 | 12 | if packet['ARP'].payload: 13 | print(packet) 14 | print (packet['ARP'].psrc) 15 | print (packet['ARP'].pdst) 16 | print (packet['ARP'].hwsrc) 17 | print (packet['ARP'].hwdst) 18 | time.sleep(2) 19 | 20 | filterstr="tcp || udp" 21 | B = sniff(filter=filterstr,count=300) 22 | 23 | 24 | 25 | 26 | # B= sniff(count=5) 27 | # B[0]['ARP'] 28 | 29 | # a = rdpcap('./new.pcap') 30 | # print(a[0]) 31 | 32 | # capture = pyshark.LiveCapture(bpf_filter='ip and tcp port') 33 | # capture = pyshark.LiveCapture() 34 | # capture.sniff(timeout=20) 35 | # print(capture) 36 | 37 | -------------------------------------------------------------------------------- /test_data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AltarIbnL/Network-anomaly-detection-with-deep-learning-along-with-UI/33391f1a84200516c648b7ff4240f22f441bd1b1/test_data.xls -------------------------------------------------------------------------------- /title.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout 4 | from PyQt5.QtCore import Qt, QPoint 5 | from PyQt5.QtGui import QFont, QCursor 6 | from PyQt5.Qt import * 7 | import csv 8 | import xlrd 9 | import pandas as pd 10 | 11 | 12 | 13 | 14 | class QTitleLabel(QLabel): 15 | """ 16 | 新建标题栏标签类 17 | """ 18 | def __init__(self, *args): 19 | # 继承父类的初始化属性,super()内部可写可不写 20 | # super(QTitleLabel, self).__init__(*args) 21 | super().__init__(*args) 22 | self.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) 23 | self.setFixedHeight(30) 24 | 25 | 26 | class QTitleButton(QPushButton): 27 | """ 28 | 新建标题栏按钮类 29 | """ 30 | def __init__(self, *args): 31 | super(QTitleButton, self).__init__(*args) 32 | # self.setFont(QFont("Webdings")) # 特殊字体以不借助图片实现最小化最大化和关闭按钮 33 | self.setFixedWidth(40) 34 | self.setFlat(True) 35 | 36 | 37 | 38 | 39 | def read_csv(filename,tableWidget3): 40 | # filename = '1.csv' 41 | 42 | with open(filename)as csvfile: 43 | # csv.reader(csvfile, dialect='excel', **fmtparams)返回一个 reader 对象,该对象将逐行遍历 csvfile 44 | reader = csv.reader(csvfile) 45 | # 逐行读取CSV 46 | rows = [row for row in reader] 47 | 48 | for i in range(1, len(rows)): 49 | rowslist = rows[i] # 获取excel每行内容 50 | for j in range(len(rows[i])): 51 | # 在tablewidget中添加行 52 | row = tableWidget3.rowCount() 53 | tableWidget3.insertRow(row) 54 | 55 | # 把数据写入tablewidget中 56 | newItem = QTableWidgetItem(str(rowslist[j])) 57 | tableWidget3.setItem(i - 1, j, newItem) 58 | 59 | def read_pickle(df,tableWidget3): 60 | # pickle = 'test2.pkl' 61 | # df = pd.read_pickle(filename) 62 | 63 | i=1 64 | for val in df.itertuples(index=False): 65 | for j in range(len(val)): 66 | # 在tablewidget中添加行 67 | row = tableWidget3.rowCount() 68 | tableWidget3.insertRow(row) 69 | 70 | # 把数据写入tablewidget中 71 | newItem = QTableWidgetItem(str(val[j])) 72 | tableWidget3.setItem(i - 1, j, newItem) 73 | i+=1 74 | 75 | 76 | 77 | 78 | 79 | if __name__ == '__main__': 80 | filename = '1.csv' 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /ui2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'ui2.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.2 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | 11 | from PyQt5 import QtCore, QtGui, QtWidgets 12 | 13 | 14 | class Ui_Unframewindow(object): 15 | def setupUi(self, Unframewindow): 16 | Unframewindow.setObjectName("Unframewindow") 17 | Unframewindow.setWindowModality(QtCore.Qt.NonModal) 18 | Unframewindow.resize(1120, 639) 19 | Unframewindow.setMouseTracking(True) 20 | Unframewindow.setStatusTip("") 21 | Unframewindow.setAutoFillBackground(False) 22 | Unframewindow.setStyleSheet("QListWidget, QListView, QTreeWidget, QTreeView {\n" 23 | " outline: 0px;\n" 24 | "}\n" 25 | "\n" 26 | "QListWidget {\n" 27 | " \n" 28 | " color: #cccccc;\n" 29 | " background: #2e2e36;\n" 30 | "}\n" 31 | "\n" 32 | "QListWidget::Item:selected {\n" 33 | " background: #26262e;\n" 34 | " color: #fd7e19;\n" 35 | " border-left: 5px solid #fd9536;\n" 36 | " \n" 37 | "}\n" 38 | "HistoryPanel:hover {\n" 39 | " background: rgb(52, 52, 52);\n" 40 | "}\n" 41 | "/**********Title**********/\n" 42 | "QTitleLabel{\n" 43 | " background-color: Gainsboro;\n" 44 | " font: 100 10pt;\n" 45 | "}\n" 46 | "\n" 47 | "\n" 48 | "/**********Button**********/\n" 49 | "QTitleButton{\n" 50 | " background-color: rgba(255, 255, 255, 0);\n" 51 | " color: black;\n" 52 | " border: 0px;\n" 53 | " font: 100 10pt;\n" 54 | "}\n" 55 | "QTitleButton#MinButton:hover,#MaxButton:hover{\n" 56 | " background-color: #D0D0D1;\n" 57 | " border: 0px;\n" 58 | " font: 100 10pt;\n" 59 | "\n" 60 | "\n" 61 | "}\n" 62 | "\n" 63 | "QTitleButton#CloseButton:hover{\n" 64 | " background-color: #D32424;\n" 65 | " color: white;\n" 66 | " border: 0px;\n" 67 | " font: 100 10pt;\n" 68 | " \n" 69 | "}\n" 70 | "\n" 71 | "QTitleButton#MinButton{\n" 72 | " image: url(./resource/short.png);\n" 73 | " \n" 74 | "}\n" 75 | "QTitleButton#CloseButton{\n" 76 | " image: url(./resource/exit.png);\n" 77 | "}\n" 78 | "QTitleButton#MaxButton{\n" 79 | " image: url(./resource/restore.png);\n" 80 | "}\n" 81 | "\n" 82 | "\n" 83 | "") 84 | Unframewindow.setUnifiedTitleAndToolBarOnMac(False) 85 | self.centralwidget = QtWidgets.QWidget(Unframewindow) 86 | self.centralwidget.setObjectName("centralwidget") 87 | self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget) 88 | self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) 89 | self.horizontalLayout_2.setSpacing(0) 90 | self.horizontalLayout_2.setObjectName("horizontalLayout_2") 91 | self.left = QtWidgets.QWidget(self.centralwidget) 92 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding) 93 | sizePolicy.setHorizontalStretch(0) 94 | sizePolicy.setVerticalStretch(0) 95 | sizePolicy.setHeightForWidth(self.left.sizePolicy().hasHeightForWidth()) 96 | self.left.setSizePolicy(sizePolicy) 97 | self.left.setMinimumSize(QtCore.QSize(150, 0)) 98 | self.left.setMaximumSize(QtCore.QSize(150, 16777215)) 99 | self.left.setMouseTracking(True) 100 | self.left.setStyleSheet("background: #2e2e36;") 101 | self.left.setObjectName("left") 102 | self.verticalLayout = QtWidgets.QVBoxLayout(self.left) 103 | self.verticalLayout.setContentsMargins(0, 10, 0, 0) 104 | self.verticalLayout.setSpacing(0) 105 | self.verticalLayout.setObjectName("verticalLayout") 106 | self.icon_1 = QtWidgets.QLabel(self.left) 107 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 108 | sizePolicy.setHorizontalStretch(0) 109 | sizePolicy.setVerticalStretch(0) 110 | sizePolicy.setHeightForWidth(self.icon_1.sizePolicy().hasHeightForWidth()) 111 | self.icon_1.setSizePolicy(sizePolicy) 112 | self.icon_1.setMinimumSize(QtCore.QSize(150, 100)) 113 | self.icon_1.setMaximumSize(QtCore.QSize(150, 100)) 114 | self.icon_1.setMouseTracking(True) 115 | self.icon_1.setStyleSheet("image: url(:/icon/resources/识别图标.png);\n" 116 | "\n" 117 | "background-color: #2e2e36;") 118 | self.icon_1.setText("") 119 | self.icon_1.setWordWrap(False) 120 | self.icon_1.setObjectName("icon_1") 121 | self.verticalLayout.addWidget(self.icon_1) 122 | self.icon_bottom_label = QtWidgets.QLabel(self.left) 123 | self.icon_bottom_label.setMinimumSize(QtCore.QSize(120, 50)) 124 | self.icon_bottom_label.setMaximumSize(QtCore.QSize(120, 50)) 125 | font = QtGui.QFont() 126 | font.setFamily("等线") 127 | font.setBold(True) 128 | font.setWeight(75) 129 | self.icon_bottom_label.setFont(font) 130 | self.icon_bottom_label.setStyleSheet("background: #2e2e36;\n" 131 | "color: #cccccc;\n" 132 | "border-bottom:0.5px solid rgb(240, 240, 240,30%);\n" 133 | "\n" 134 | "") 135 | self.icon_bottom_label.setFrameShape(QtWidgets.QFrame.NoFrame) 136 | self.icon_bottom_label.setFrameShadow(QtWidgets.QFrame.Plain) 137 | self.icon_bottom_label.setLineWidth(0) 138 | self.icon_bottom_label.setScaledContents(False) 139 | self.icon_bottom_label.setAlignment(QtCore.Qt.AlignCenter) 140 | self.icon_bottom_label.setObjectName("icon_bottom_label") 141 | self.verticalLayout.addWidget(self.icon_bottom_label, 0, QtCore.Qt.AlignHCenter) 142 | self.left_widget = QtWidgets.QListWidget(self.left) 143 | self.left_widget.setMinimumSize(QtCore.QSize(150, 0)) 144 | self.left_widget.setMaximumSize(QtCore.QSize(150, 16777215)) 145 | self.left_widget.setBaseSize(QtCore.QSize(0, 0)) 146 | self.left_widget.setMouseTracking(True) 147 | self.left_widget.setStyleSheet("QListWidget, QListView, QTreeWidget, QTreeView {\n" 148 | " outline: 0px;\n" 149 | "}\n" 150 | "\n" 151 | "QListWidget {\n" 152 | " \n" 153 | " color: #cccccc;\n" 154 | " background: #2e2e36;\n" 155 | "}\n" 156 | "\n" 157 | "QListWidget::Item:selected {\n" 158 | " background: #26262e;\n" 159 | " color: #fd7e19;\n" 160 | " border-left: 5px solid #fd9536;\n" 161 | " \n" 162 | "}\n" 163 | "HistoryPanel:hover {\n" 164 | " background: rgb(52, 52, 52);\n" 165 | "}") 166 | self.left_widget.setFrameShape(QtWidgets.QFrame.NoFrame) 167 | self.left_widget.setSelectionRectVisible(False) 168 | self.left_widget.setObjectName("left_widget") 169 | item = QtWidgets.QListWidgetItem() 170 | item.setTextAlignment(QtCore.Qt.AlignCenter) 171 | font = QtGui.QFont() 172 | font.setBold(True) 173 | font.setWeight(75) 174 | item.setFont(font) 175 | icon = QtGui.QIcon() 176 | icon.addPixmap(QtGui.QPixmap(":/icon/test/resource/极速响应.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 177 | icon.addPixmap(QtGui.QPixmap(":/icon/test/resource/极速识别.png"), QtGui.QIcon.Selected, QtGui.QIcon.Off) 178 | item.setIcon(icon) 179 | self.left_widget.addItem(item) 180 | item = QtWidgets.QListWidgetItem() 181 | item.setTextAlignment(QtCore.Qt.AlignCenter) 182 | font = QtGui.QFont() 183 | font.setBold(True) 184 | font.setWeight(75) 185 | item.setFont(font) 186 | icon1 = QtGui.QIcon() 187 | icon1.addPixmap(QtGui.QPixmap(":/icon/test/resource/文字.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 188 | icon1.addPixmap(QtGui.QPixmap(":/icon/test/resource/文字 (1).png"), QtGui.QIcon.Selected, QtGui.QIcon.Off) 189 | item.setIcon(icon1) 190 | self.left_widget.addItem(item) 191 | self.verticalLayout.addWidget(self.left_widget) 192 | self.horizontalLayout_2.addWidget(self.left) 193 | self.right_widget = QtWidgets.QWidget(self.centralwidget) 194 | self.right_widget.setObjectName("right_widget") 195 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.right_widget) 196 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 197 | self.verticalLayout_2.setSpacing(0) 198 | self.verticalLayout_2.setObjectName("verticalLayout_2") 199 | self.label_widget = QtWidgets.QWidget(self.right_widget) 200 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Preferred) 201 | sizePolicy.setHorizontalStretch(0) 202 | sizePolicy.setVerticalStretch(0) 203 | sizePolicy.setHeightForWidth(self.label_widget.sizePolicy().hasHeightForWidth()) 204 | self.label_widget.setSizePolicy(sizePolicy) 205 | self.label_widget.setMinimumSize(QtCore.QSize(0, 40)) 206 | self.label_widget.setMaximumSize(QtCore.QSize(16777215, 40)) 207 | self.label_widget.setMouseTracking(True) 208 | self.label_widget.setStyleSheet("QWidget#label_widget{\n" 209 | " background-color: rgb(255, 255, 255);\n" 210 | " \n" 211 | "\n" 212 | "\n" 213 | "}\n" 214 | "") 215 | self.label_widget.setObjectName("label_widget") 216 | self.horizontalLayout = QtWidgets.QHBoxLayout(self.label_widget) 217 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 218 | self.horizontalLayout.setSpacing(0) 219 | self.horizontalLayout.setObjectName("horizontalLayout") 220 | spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) 221 | self.horizontalLayout.addItem(spacerItem) 222 | self.MinButton = QTitleButton(self.label_widget) 223 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 224 | sizePolicy.setHorizontalStretch(0) 225 | sizePolicy.setVerticalStretch(0) 226 | sizePolicy.setHeightForWidth(self.MinButton.sizePolicy().hasHeightForWidth()) 227 | self.MinButton.setSizePolicy(sizePolicy) 228 | self.MinButton.setMaximumSize(QtCore.QSize(40, 16777215)) 229 | self.MinButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 230 | self.MinButton.setMouseTracking(True) 231 | self.MinButton.setStyleSheet("QTitleButton#MinButton{\n" 232 | " \n" 233 | " \n" 234 | " image: url(:/icon/resources/short.png);\n" 235 | "\n" 236 | "}") 237 | self.MinButton.setText("") 238 | self.MinButton.setFlat(True) 239 | self.MinButton.setObjectName("MinButton") 240 | self.horizontalLayout.addWidget(self.MinButton) 241 | self.MaxButton = QTitleButton(self.label_widget) 242 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 243 | sizePolicy.setHorizontalStretch(0) 244 | sizePolicy.setVerticalStretch(0) 245 | sizePolicy.setHeightForWidth(self.MaxButton.sizePolicy().hasHeightForWidth()) 246 | self.MaxButton.setSizePolicy(sizePolicy) 247 | self.MaxButton.setMinimumSize(QtCore.QSize(40, 0)) 248 | self.MaxButton.setMaximumSize(QtCore.QSize(40, 16777215)) 249 | self.MaxButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 250 | self.MaxButton.setMouseTracking(True) 251 | self.MaxButton.setStyleSheet("QTitleButton#MaxButton{\n" 252 | " \n" 253 | " image: url(:/icon/resources/restore.png);\n" 254 | "\n" 255 | "}") 256 | self.MaxButton.setText("") 257 | self.MaxButton.setFlat(True) 258 | self.MaxButton.setObjectName("MaxButton") 259 | self.horizontalLayout.addWidget(self.MaxButton) 260 | self.CloseButton = QTitleButton(self.label_widget) 261 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) 262 | sizePolicy.setHorizontalStretch(0) 263 | sizePolicy.setVerticalStretch(0) 264 | sizePolicy.setHeightForWidth(self.CloseButton.sizePolicy().hasHeightForWidth()) 265 | self.CloseButton.setSizePolicy(sizePolicy) 266 | self.CloseButton.setMinimumSize(QtCore.QSize(40, 0)) 267 | self.CloseButton.setMaximumSize(QtCore.QSize(40, 16777215)) 268 | self.CloseButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 269 | self.CloseButton.setMouseTracking(True) 270 | self.CloseButton.setAutoFillBackground(False) 271 | self.CloseButton.setStyleSheet("QTitleButton#CloseButton{\n" 272 | " \n" 273 | " image: url(:/icon/resources/exit.png);\n" 274 | "\n" 275 | "}") 276 | self.CloseButton.setText("") 277 | self.CloseButton.setFlat(True) 278 | self.CloseButton.setObjectName("CloseButton") 279 | self.horizontalLayout.addWidget(self.CloseButton) 280 | self.verticalLayout_2.addWidget(self.label_widget) 281 | self.stack_page = QtWidgets.QStackedWidget(self.right_widget) 282 | self.stack_page.setMinimumSize(QtCore.QSize(0, 0)) 283 | self.stack_page.setObjectName("stack_page") 284 | self.page = QtWidgets.QWidget() 285 | self.page.setStyleSheet("QWidget#page{\n" 286 | " background-color: rgb(245, 249, 252);\n" 287 | "}\n" 288 | "\n" 289 | "\n" 290 | "\n" 291 | "") 292 | self.page.setObjectName("page") 293 | self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.page) 294 | self.verticalLayout_7.setObjectName("verticalLayout_7") 295 | self.label_show_camera_widget = QtWidgets.QWidget(self.page) 296 | self.label_show_camera_widget.setObjectName("label_show_camera_widget") 297 | self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.label_show_camera_widget) 298 | self.horizontalLayout_8.setContentsMargins(14, 14, 14, 14) 299 | self.horizontalLayout_8.setSpacing(15) 300 | self.horizontalLayout_8.setObjectName("horizontalLayout_8") 301 | self.tableWidget = QtWidgets.QTableWidget(self.label_show_camera_widget) 302 | self.tableWidget.setStyleSheet("QTableWidget#tableWidget{\n" 303 | " border:0.5px solid lightgray; \n" 304 | " background-color: rgb(255, 255, 255);\n" 305 | "\n" 306 | "}\n" 307 | "\n" 308 | "") 309 | self.tableWidget.setObjectName("tableWidget") 310 | self.tableWidget.setColumnCount(0) 311 | self.tableWidget.setRowCount(0) 312 | self.horizontalLayout_8.addWidget(self.tableWidget) 313 | self.verticalLayout_9 = QtWidgets.QVBoxLayout() 314 | self.verticalLayout_9.setObjectName("verticalLayout_9") 315 | self.widget_2 = QtWidgets.QWidget(self.label_show_camera_widget) 316 | self.widget_2.setMaximumSize(QtCore.QSize(180, 16777215)) 317 | self.widget_2.setObjectName("widget_2") 318 | self.verticalLayout_10 = QtWidgets.QVBoxLayout(self.widget_2) 319 | self.verticalLayout_10.setContentsMargins(0, 0, 0, -1) 320 | self.verticalLayout_10.setObjectName("verticalLayout_10") 321 | spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) 322 | self.verticalLayout_10.addItem(spacerItem1) 323 | self.read_button = QtWidgets.QPushButton(self.widget_2) 324 | self.read_button.setMinimumSize(QtCore.QSize(180, 30)) 325 | self.read_button.setMaximumSize(QtCore.QSize(180, 30)) 326 | self.read_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 327 | self.read_button.setStyleSheet("\n" 328 | "QPushButton:hover\n" 329 | "{\n" 330 | " /*背景颜色*/ \n" 331 | " background-color: rgb(253, 149, 54);\n" 332 | " \n" 333 | "}\n" 334 | "QPushButton\n" 335 | "{\n" 336 | " background-color: rgb(255, 161, 75);\n" 337 | " border-radius:10px;\n" 338 | " color: rgb(255, 255, 255);\n" 339 | " border: 0px;\n" 340 | " font: 9pt \"微软雅黑\" ;\n" 341 | "}\n" 342 | "") 343 | self.read_button.setObjectName("read_button") 344 | self.verticalLayout_10.addWidget(self.read_button) 345 | self.curtailnum_layout = QtWidgets.QHBoxLayout() 346 | self.curtailnum_layout.setObjectName("curtailnum_layout") 347 | self.label_4 = QtWidgets.QLabel(self.widget_2) 348 | self.label_4.setStyleSheet("QLabel{\n" 349 | " \n" 350 | " font: 8pt \"微软雅黑\";\n" 351 | "\n" 352 | "}") 353 | self.label_4.setObjectName("label_4") 354 | self.curtailnum_layout.addWidget(self.label_4) 355 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget_2) 356 | self.lineEdit_2.setObjectName("lineEdit_2") 357 | self.curtailnum_layout.addWidget(self.lineEdit_2) 358 | self.curtailnum_layout.setStretch(1, 1) 359 | self.verticalLayout_10.addLayout(self.curtailnum_layout) 360 | self.text_layout1 = QtWidgets.QHBoxLayout() 361 | self.text_layout1.setObjectName("text_layout1") 362 | self.label_6 = QtWidgets.QLabel(self.widget_2) 363 | self.label_6.setStyleSheet("font: 8pt \"微软雅黑\";") 364 | self.label_6.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) 365 | self.label_6.setObjectName("label_6") 366 | self.text_layout1.addWidget(self.label_6) 367 | self.label_5 = QtWidgets.QLabel(self.widget_2) 368 | self.label_5.setLayoutDirection(QtCore.Qt.LeftToRight) 369 | self.label_5.setStyleSheet("QLabel{\n" 370 | " border:0px solid lightgray; \n" 371 | " image: url(:/icon/resources/停止.png);\n" 372 | "}\n" 373 | "") 374 | self.label_5.setText("") 375 | self.label_5.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) 376 | self.label_5.setObjectName("label_5") 377 | self.text_layout1.addWidget(self.label_5) 378 | self.label_7 = QtWidgets.QLabel(self.widget_2) 379 | self.label_7.setEnabled(True) 380 | self.label_7.setStyleSheet("QLabel{\n" 381 | " border:0px solid lightgray; \n" 382 | " image: url(:/icon/resources/执行.png);\n" 383 | "}\n" 384 | "") 385 | self.label_7.setText("") 386 | self.label_7.setObjectName("label_7") 387 | self.text_layout1.addWidget(self.label_7) 388 | self.text_layout1.setStretch(1, 1) 389 | self.text_layout1.setStretch(2, 1) 390 | self.verticalLayout_10.addLayout(self.text_layout1) 391 | spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) 392 | self.verticalLayout_10.addItem(spacerItem2) 393 | self.verticalLayout_9.addWidget(self.widget_2) 394 | self.horizontalLayout_8.addLayout(self.verticalLayout_9) 395 | self.horizontalLayout_8.setStretch(0, 3) 396 | self.verticalLayout_7.addWidget(self.label_show_camera_widget) 397 | self.cam_pic = QtWidgets.QPushButton(self.page) 398 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 399 | sizePolicy.setHorizontalStretch(20) 400 | sizePolicy.setVerticalStretch(20) 401 | sizePolicy.setHeightForWidth(self.cam_pic.sizePolicy().hasHeightForWidth()) 402 | self.cam_pic.setSizePolicy(sizePolicy) 403 | self.cam_pic.setMinimumSize(QtCore.QSize(20, 20)) 404 | self.cam_pic.setMaximumSize(QtCore.QSize(20, 20)) 405 | self.cam_pic.setText("") 406 | icon2 = QtGui.QIcon() 407 | icon2.addPixmap(QtGui.QPixmap(":/icon/图片.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 408 | self.cam_pic.setIcon(icon2) 409 | self.cam_pic.setFlat(True) 410 | self.cam_pic.setObjectName("cam_pic") 411 | self.verticalLayout_7.addWidget(self.cam_pic, 0, QtCore.Qt.AlignRight) 412 | self.verticalLayout_7.setStretch(0, 1) 413 | self.stack_page.addWidget(self.page) 414 | self.page_2 = QtWidgets.QWidget() 415 | self.page_2.setStyleSheet("QWidget{\n" 416 | " background-color: rgb(245, 249, 252);\n" 417 | "}\n" 418 | "") 419 | self.page_2.setObjectName("page_2") 420 | self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.page_2) 421 | self.verticalLayout_6.setContentsMargins(-1, -1, -1, 0) 422 | self.verticalLayout_6.setSpacing(0) 423 | self.verticalLayout_6.setObjectName("verticalLayout_6") 424 | self.widget = QtWidgets.QWidget(self.page_2) 425 | self.widget.setObjectName("widget") 426 | self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.widget) 427 | self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) 428 | self.verticalLayout_3.setSpacing(0) 429 | self.verticalLayout_3.setObjectName("verticalLayout_3") 430 | self.r_bottom_widget = QtWidgets.QWidget(self.widget) 431 | self.r_bottom_widget.setStyleSheet("") 432 | self.r_bottom_widget.setObjectName("r_bottom_widget") 433 | self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.r_bottom_widget) 434 | self.horizontalLayout_3.setContentsMargins(14, 14, 14, 14) 435 | self.horizontalLayout_3.setSpacing(15) 436 | self.horizontalLayout_3.setObjectName("horizontalLayout_3") 437 | self.text_widget = QtWidgets.QWidget(self.r_bottom_widget) 438 | self.text_widget.setStyleSheet("QWidget#text_widget{\n" 439 | " border:0.5px solid lightgray; \n" 440 | " background-color: rgb(255, 255, 255);\n" 441 | "}\n" 442 | "\n" 443 | "\n" 444 | "") 445 | self.text_widget.setObjectName("text_widget") 446 | self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.text_widget) 447 | self.verticalLayout_5.setContentsMargins(11, -1, -1, -1) 448 | self.verticalLayout_5.setObjectName("verticalLayout_5") 449 | self.label_3 = QtWidgets.QLabel(self.text_widget) 450 | self.label_3.setStyleSheet("font: 9pt \"微软雅黑\";\n" 451 | "background-color: rgb(255, 255, 255);\n" 452 | "border-top:2px;\n" 453 | "border-bottom:1px solid lightgray;\n" 454 | "padding-bottom:8px ;") 455 | self.label_3.setObjectName("label_3") 456 | self.verticalLayout_5.addWidget(self.label_3) 457 | self.tableWidget_2 = QtWidgets.QTableWidget(self.text_widget) 458 | self.tableWidget_2.setStyleSheet("border:0px;\n" 459 | "background-color: rgb(255, 255, 255);") 460 | self.tableWidget_2.setObjectName("tableWidget_2") 461 | self.tableWidget_2.setColumnCount(0) 462 | self.tableWidget_2.setRowCount(0) 463 | self.verticalLayout_5.addWidget(self.tableWidget_2) 464 | self.horizontalLayout_3.addWidget(self.text_widget) 465 | self.horizontalLayout_3.setStretch(0, 1) 466 | self.verticalLayout_3.addWidget(self.r_bottom_widget) 467 | self.verticalLayout_3.setStretch(0, 3) 468 | self.verticalLayout_6.addWidget(self.widget) 469 | self.button_bottom = QtWidgets.QWidget(self.page_2) 470 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) 471 | sizePolicy.setHorizontalStretch(0) 472 | sizePolicy.setVerticalStretch(0) 473 | sizePolicy.setHeightForWidth(self.button_bottom.sizePolicy().hasHeightForWidth()) 474 | self.button_bottom.setSizePolicy(sizePolicy) 475 | self.button_bottom.setObjectName("button_bottom") 476 | self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.button_bottom) 477 | self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) 478 | self.horizontalLayout_4.setObjectName("horizontalLayout_4") 479 | self.export_2 = QtWidgets.QWidget(self.button_bottom) 480 | self.export_2.setMinimumSize(QtCore.QSize(650, 120)) 481 | self.export_2.setMaximumSize(QtCore.QSize(650, 120)) 482 | self.export_2.setLayoutDirection(QtCore.Qt.LeftToRight) 483 | self.export_2.setObjectName("export_2") 484 | self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.export_2) 485 | self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0) 486 | self.horizontalLayout_5.setSpacing(0) 487 | self.horizontalLayout_5.setObjectName("horizontalLayout_5") 488 | self.label = QtWidgets.QLabel(self.export_2) 489 | self.label.setLayoutDirection(QtCore.Qt.LeftToRight) 490 | self.label.setStyleSheet("background-color: transparent;\n" 491 | "font: 9pt \"微软雅黑\";\n" 492 | "border: 0px;\n" 493 | "") 494 | self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) 495 | self.label.setObjectName("label") 496 | self.horizontalLayout_5.addWidget(self.label) 497 | self.widget_3 = QtWidgets.QWidget(self.export_2) 498 | self.widget_3.setMinimumSize(QtCore.QSize(350, 30)) 499 | self.widget_3.setObjectName("widget_3") 500 | self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.widget_3) 501 | self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0) 502 | self.horizontalLayout_6.setSpacing(8) 503 | self.horizontalLayout_6.setObjectName("horizontalLayout_6") 504 | self.label_8 = QtWidgets.QLabel(self.widget_3) 505 | self.label_8.setMinimumSize(QtCore.QSize(0, 100)) 506 | self.label_8.setMaximumSize(QtCore.QSize(16777215, 100)) 507 | self.label_8.setStyleSheet("QWidget#label_8{\n" 508 | " border:0.5px solid gray; \n" 509 | " font: \"微软雅黑\";\n" 510 | "}\n" 511 | "") 512 | self.label_8.setWordWrap(True) 513 | self.label_8.setIndent(1) 514 | self.label_8.setObjectName("label_8") 515 | self.horizontalLayout_6.addWidget(self.label_8) 516 | spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) 517 | self.horizontalLayout_6.addItem(spacerItem3) 518 | self.label_2 = QtWidgets.QLabel(self.widget_3) 519 | self.label_2.setStyleSheet("background-color: transparent;\n" 520 | "font: 9pt \"微软雅黑\";\n" 521 | "border: 0px;\n" 522 | "") 523 | self.label_2.setObjectName("label_2") 524 | self.horizontalLayout_6.addWidget(self.label_2) 525 | self.label_9 = QtWidgets.QLabel(self.widget_3) 526 | self.label_9.setStyleSheet("\n" 527 | "\n" 528 | "border: 0px;\n" 529 | "font: 8pt \"微软雅黑\" ;") 530 | self.label_9.setScaledContents(True) 531 | self.label_9.setWordWrap(True) 532 | self.label_9.setObjectName("label_9") 533 | self.horizontalLayout_6.addWidget(self.label_9) 534 | self.horizontalLayout_6.setStretch(0, 1) 535 | self.horizontalLayout_5.addWidget(self.widget_3) 536 | self.horizontalLayout_5.setStretch(1, 1) 537 | self.horizontalLayout_4.addWidget(self.export_2) 538 | spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) 539 | self.horizontalLayout_4.addItem(spacerItem4) 540 | self.upload_pic_5 = QtWidgets.QPushButton(self.button_bottom) 541 | self.upload_pic_5.setEnabled(True) 542 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) 543 | sizePolicy.setHorizontalStretch(0) 544 | sizePolicy.setVerticalStretch(0) 545 | sizePolicy.setHeightForWidth(self.upload_pic_5.sizePolicy().hasHeightForWidth()) 546 | self.upload_pic_5.setSizePolicy(sizePolicy) 547 | self.upload_pic_5.setMinimumSize(QtCore.QSize(250, 45)) 548 | self.upload_pic_5.setMaximumSize(QtCore.QSize(250, 45)) 549 | font = QtGui.QFont() 550 | font.setFamily("微软雅黑") 551 | font.setPointSize(12) 552 | font.setBold(False) 553 | font.setItalic(False) 554 | font.setWeight(50) 555 | font.setKerning(True) 556 | self.upload_pic_5.setFont(font) 557 | self.upload_pic_5.setLayoutDirection(QtCore.Qt.RightToLeft) 558 | self.upload_pic_5.setStyleSheet("QPushButton:enabled\n" 559 | "{\n" 560 | " background-color: rgb(255, 161, 75);\n" 561 | " color: rgb(255, 255, 255);\n" 562 | " border: 0px;\n" 563 | " font: 11.5pt \"微软雅黑\" ;\n" 564 | "}\n" 565 | "\n" 566 | "QPushButton:hover\n" 567 | "{\n" 568 | " /*背景颜色*/ \n" 569 | " background-color: rgb(253, 149, 54);\n" 570 | " \n" 571 | "}\n" 572 | "\n" 573 | "QPushButton:disabled\n" 574 | "{\n" 575 | " /*背景颜色*/ \n" 576 | " background-color: lightgray;\n" 577 | " color: rgb(255, 255, 255);\n" 578 | " border: 0px;\n" 579 | " font: 11.5pt \"微软雅黑\" ;\n" 580 | " \n" 581 | "}") 582 | self.upload_pic_5.setFlat(False) 583 | self.upload_pic_5.setObjectName("upload_pic_5") 584 | self.horizontalLayout_4.addWidget(self.upload_pic_5) 585 | self.horizontalLayout_4.setStretch(2, 2) 586 | self.verticalLayout_6.addWidget(self.button_bottom) 587 | self.verticalLayout_6.setStretch(0, 1) 588 | self.stack_page.addWidget(self.page_2) 589 | self.verticalLayout_2.addWidget(self.stack_page) 590 | self.horizontalLayout_2.addWidget(self.right_widget) 591 | Unframewindow.setCentralWidget(self.centralwidget) 592 | self.menubar = QtWidgets.QMenuBar(Unframewindow) 593 | self.menubar.setEnabled(True) 594 | self.menubar.setGeometry(QtCore.QRect(0, 0, 1120, 23)) 595 | self.menubar.setObjectName("menubar") 596 | Unframewindow.setMenuBar(self.menubar) 597 | 598 | self.retranslateUi(Unframewindow) 599 | self.stack_page.setCurrentIndex(1) 600 | QtCore.QMetaObject.connectSlotsByName(Unframewindow) 601 | 602 | def retranslateUi(self, Unframewindow): 603 | _translate = QtCore.QCoreApplication.translate 604 | Unframewindow.setWindowTitle(_translate("Unframewindow", "MainWindow")) 605 | self.icon_bottom_label.setText(_translate("Unframewindow", "

异常流量检测系统

")) 606 | __sortingEnabled = self.left_widget.isSortingEnabled() 607 | self.left_widget.setSortingEnabled(False) 608 | item = self.left_widget.item(0) 609 | item.setText(_translate("Unframewindow", "流量提取")) 610 | item = self.left_widget.item(1) 611 | item.setText(_translate("Unframewindow", "流量鉴别")) 612 | self.left_widget.setSortingEnabled(__sortingEnabled) 613 | self.MinButton.setToolTip(_translate("Unframewindow", "最小化")) 614 | self.MaxButton.setToolTip(_translate("Unframewindow", "最大化")) 615 | self.CloseButton.setToolTip(_translate("Unframewindow", "关闭窗口")) 616 | self.read_button.setText(_translate("Unframewindow", "截取数据包")) 617 | self.label_4.setText(_translate("Unframewindow", "截取数量")) 618 | self.lineEdit_2.setText(_translate("Unframewindow", "400")) 619 | self.label_6.setText(_translate("Unframewindow", "程序未运行")) 620 | self.label_3.setText(_translate("Unframewindow", "识别结果")) 621 | self.label.setText(_translate("Unframewindow", "页面说明:")) 622 | self.label_8.setText(_translate("Unframewindow", "

本页面用于展示截取流量的标签:

(1)页面分别展示的是源IP地址,源端口,目的IP地址,目的端口和传输层协议(对于协议而言,6:TCP 17:UDP 1:ICMP)

(2)我们主要使用2个训练集,分别是ISCX 2012 和CIC-IDS 2017。


")) 623 | self.label_2.setText(_translate("Unframewindow", "检测模型:")) 624 | self.label_9.setText(_translate("Unframewindow", "

三种模型交替判断

")) 625 | self.upload_pic_5.setText(_translate("Unframewindow", "开始识别")) 626 | from title import QTitleButton 627 | import picture_rc 628 | --------------------------------------------------------------------------------