wusihan 1 سال پیش
کامیت
3db01ec195
51فایلهای تغییر یافته به همراه1167 افزوده شده و 0 حذف شده
  1. 19 0
      README.md
  2. 3 0
      commit.bat
  3. 2 0
      day1/first.py
  4. 0 0
      day1/python
  5. 67 0
      day2/.ipynb_checkpoints/day2-checkpoint.ipynb
  6. BIN
      day2/1.jpg
  7. 19 0
      day2/README.md
  8. 67 0
      day2/day2.ipynb
  9. 7 0
      day2/ex01.py
  10. BIN
      day2/gpu.bmp
  11. BIN
      day2/sea.jpg
  12. 51 0
      day3/.ipynb_checkpoints/03卷积特征-checkpoint.ipynb
  13. 3 0
      day3/.ipynb_checkpoints/commit-checkpoint.bat
  14. 63 0
      day3/.ipynb_checkpoints/day3笔记-checkpoint.ipynb
  15. BIN
      day3/.ipynb_checkpoints/fengjing-checkpoint.bmp
  16. BIN
      day3/.ipynb_checkpoints/gpu-checkpoint.bmp
  17. BIN
      day3/2.jpg
  18. 54 0
      day3/33卷积特征.ipynb
  19. 24 0
      day3/codes/ex_qt01.py
  20. 23 0
      day3/codes/notes.txt
  21. 3 0
      day3/commit.bat
  22. 63 0
      day3/day3笔记.ipynb
  23. BIN
      day3/fengjing.bmp
  24. BIN
      day3/gpu.bmp
  25. 5 0
      day4/monitor/main.py
  26. 69 0
      day4/monitor/ui/monitor.ui
  27. 52 0
      day4/monitor/ui/monitor_ui_py
  28. 45 0
      day4/monitor/ui/untitled.ui
  29. 1 0
      day5/AIAPP/app.bat
  30. BIN
      day5/AIAPP/dev/__pycache__/camera.cpython-39.pyc
  31. 31 0
      day5/AIAPP/dev/camera.py
  32. 0 0
      day5/AIAPP/frame/__pycache__
  33. 10 0
      day5/AIAPP/frame/app.py
  34. 44 0
      day5/AIAPP/frame/win.py
  35. 7 0
      day5/AIAPP/main.py
  36. BIN
      day5/AIAPP/ui/__pycache__/traffic_ui.cpython-39.pyc
  37. 119 0
      day5/AIAPP/ui/monitor.ui
  38. 2 0
      day5/AIAPP/ui/tools.bat
  39. 69 0
      day5/AIAPP/ui/traffic.ui
  40. 119 0
      day5/AIAPP/ui/traffic_ui.py
  41. BIN
      day6/infer/03_1.jpg
  42. BIN
      day6/infer/04_9.jpg
  43. BIN
      day6/infer/05_2.jpg
  44. BIN
      day6/infer/_pycache_/__pycache__/model.cpython-39.pyc
  45. 39 0
      day6/infer/_pycache_/infer.py
  46. 76 0
      day6/infer/_pycache_/model.py
  47. BIN
      day6/infer/lenet5.pt
  48. 0 0
      day6/infer/model.cpython-39.pyc
  49. 0 0
      day6/lenet/ds.py
  50. 11 0
      day6/lenet/model.py
  51. 0 0
      day6/lenet/train.py

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+##第一天实训日志
+-**1.任务**
+>
+>
+-**2.内容**
+-**3.要求**
+-**4.提交**
+##第二天实训日志
+
+##第三天实训日志
+
+
+##第四天实训日志
+
+
+##第五天实训日志
+
+
+##第六天实训日志

+ 3 - 0
commit.bat

@@ -0,0 +1,3 @@
+git add *
+git commit -m "作业"
+git push -u origin master

+ 2 - 0
day1/first.py

@@ -0,0 +1,2 @@
+print("Python编程,少年大成!")
+print("我是一只快乐的小鸟!")

+ 0 - 0
day1/python


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 67 - 0
day2/.ipynb_checkpoints/day2-checkpoint.ipynb


BIN
day2/1.jpg


+ 19 - 0
day2/README.md

@@ -0,0 +1,19 @@
+##第一天实训日志
+-**1.任务**
+>
+>
+-**2.内容**
+-**3.要求**
+-**4.提交**
+##第二天实训日志
+
+##第三天实训日志
+
+
+##第四天实训日志
+
+
+##第五天实训日志
+
+
+##第六天实训日志

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 67 - 0
day2/day2.ipynb


+ 7 - 0
day2/ex01.py

@@ -0,0 +1,7 @@
+import numpy #向量与矩阵运算库(线性代数运算库)
+import cv2   #opencv-python opencv-contribute-python:图像处理
+#生成数组
+img_array=[[[0,255,0,128]for i in range(255)]for j in range(255)]#255*255的图像,图像的像素[0,255,0,255]
+#cv2中只支持numpy的格式
+img_numpy = numpy.array(img_array)
+cv2.imwrite("1.jpg",img_numpy)

BIN
day2/gpu.bmp


BIN
day2/sea.jpg


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 51 - 0
day3/.ipynb_checkpoints/03卷积特征-checkpoint.ipynb


+ 3 - 0
day3/.ipynb_checkpoints/commit-checkpoint.bat

@@ -0,0 +1,3 @@
+git add *
+git commit -m "作业"
+git push -u origin master

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 63 - 0
day3/.ipynb_checkpoints/day3笔记-checkpoint.ipynb


BIN
day3/.ipynb_checkpoints/fengjing-checkpoint.bmp


BIN
day3/.ipynb_checkpoints/gpu-checkpoint.bmp


BIN
day3/2.jpg


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 54 - 0
day3/33卷积特征.ipynb


+ 24 - 0
day3/codes/ex_qt01.py

@@ -0,0 +1,24 @@
+# 引入模块
+from PyQt5.QtWidgets import QApplication
+from PyQt5.QtWidgets import QDialog
+from PyQt5.QtWidgets import QMainWindow
+from PyQt5.QtWidgets import QPushButton
+
+#创建Qt应用
+app = QApplication([])   #参数:命令行参数
+"""
+   Qt的应用必须在APP之间
+"""
+dlg = QMainWindow()
+#dlg = QDialog()
+#改变对话框的大小
+dlg.resize(1000,1000)  #设置窗体大小
+dlg.move(100,100)    #设置窗体的位置
+dlg.setWindowTitle("我的窗体")
+
+btn = QPushButton("登录",dlg)
+btn.resize(100, 36)
+btn.move(200,200)
+btn.show()
+dlg.show()
+app.exec()   #让应用程序进入消息循环

+ 23 - 0
day3/codes/notes.txt

@@ -0,0 +1,23 @@
+1.条件
+    安装的模块:PyQT5,PyQT5-tools
+    where python 确定python 安装路径:${PYTHON_HOME}
+    安装的模块在
+    ${PYTHON_HOME}/Lib/site-packages/PyQTS
+    ${PYTHON_HOME}/Lib/site-packages/pyqts-tools
+    ${PYTHON_HOME}/Lib/site-packages/qt5-appliaction
+2.开发一个窗体程序
+  2.1创建QApplication
+  2.2创建对话框
+   窗体:主窗体(菜单),对话框(无菜单),闪屏(没有标题栏)
+3.在窗体添加按钮,文本框,标签,多选按钮,单旋按钮
+4.程序开发的结构(模式)
+   main.py   #程序的入口
+   根目录   monitor(交通监控)
+     |- ui    #界面设计
+     |- form  #窗体 
+     |- biz   #业务实现(人工智能推理接口)
+     |- dev   #摄像头的处理
+
+
+
+

+ 3 - 0
day3/commit.bat

@@ -0,0 +1,3 @@
+git add *
+git commit -m "作业"
+git push -u origin master

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 63 - 0
day3/day3笔记.ipynb


BIN
day3/fengjing.bmp


BIN
day3/gpu.bmp


+ 5 - 0
day4/monitor/main.py

@@ -0,0 +1,5 @@
+#pyuic5 -o monitor_ui.py monitor.ui
+#-o 表示输出
+#monitor_ui.py表示输出文件,可以随意命名
+# monitor.ui我们设计的界面文件。这个文件只能翻译以后使用。
+# pyuic5是一个把ui文件翻译成py文件的工具

+ 69 - 0
day4/monitor/ui/monitor.ui

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Traffic</class>
+ <widget class="QDialog" name="Traffic">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>745</width>
+    <height>635</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="lblViedo">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>10</y>
+     <width>640</width>
+     <height>480</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:5px;
+border-style:dotted;
+border-color:red;
+border-radius:10px;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:purple;
+border-right-color:pink;
+
+
+</string>
+   </property>
+   <property name="text">
+    <string>视频显示区</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="ptncapture">
+   <property name="geometry">
+    <rect>
+     <x>80</x>
+     <y>510</y>
+     <width>181</width>
+     <height>71</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:7px;
+border-left-color:#ffffff;
+border-top-color:#ffffff;
+border-bottom-color:#888888;
+border-right-color:#bbbbbb;
+
+</string>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 52 - 0
day4/monitor/ui/monitor_ui_py

@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'monitor.ui'
+#
+# Created by: PyQt5 UI code generator 5.15.9
+#
+# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# run again.  Do not edit this file unless you know what you are doing.
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_Dialog(object):
+    def setupUi(self, Dialog):
+        Dialog.setObjectName("Dialog")
+        Dialog.resize(664, 635)
+        self.label = QtWidgets.QLabel(Dialog)
+        self.label.setGeometry(QtCore.QRect(30, 10, 221, 211))
+        self.label.setStyleSheet("border-width:5px;\n"
+"border-style:dotted;\n"
+"border-color:red;\n"
+"border-radius:10px;\n"
+"border-top-color:red;\n"
+"border-bottom-color:green;\n"
+"border-left-color:purple;\n"
+"border-right-color:pink;\n"
+"\n"
+"\n"
+"")
+        self.label.setObjectName("label")
+        self.pushButton = QtWidgets.QPushButton(Dialog)
+        self.pushButton.setGeometry(QtCore.QRect(70, 290, 141, 61))
+        self.pushButton.setStyleSheet("border-width:2px;\n"
+"border-style:solid;\n"
+"border-radius:7px;\n"
+"border-left-color:#ffffff;\n"
+"border-top-color:#ffffff;\n"
+"border-bottom-color:#888888;\n"
+"border-right-color:#bbbbbb;\n"
+"\n"
+"")
+        self.pushButton.setObjectName("pushButton")
+
+        self.retranslateUi(Dialog)
+        QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+    def retranslateUi(self, Dialog):
+        _translate = QtCore.QCoreApplication.translate
+        Dialog.setWindowTitle(_translate("Dialog", "智能交通监控系统"))
+        self.label.setText(_translate("Dialog", "视频显示区"))
+        self.pushButton.setText(_translate("Dialog", "处理视频"))

+ 45 - 0
day4/monitor/ui/untitled.ui

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>570</width>
+    <height>444</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>50</y>
+     <width>221</width>
+     <height>201</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>90</x>
+     <y>340</y>
+     <width>93</width>
+     <height>28</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 1 - 0
day5/AIAPP/app.bat

@@ -0,0 +1 @@
+python main.py

BIN
day5/AIAPP/dev/__pycache__/camera.cpython-39.pyc


+ 31 - 0
day5/AIAPP/dev/camera.py

@@ -0,0 +1,31 @@
+from PyQt5.QtCore import QThread    # 引入多线程,设备是多个,一个设备一个任务
+import cv2
+# from cv2 import VideoCapture 
+
+# 1. 定义信号(引入)
+from PyQt5.QtCore import pyqtSignal
+
+class CameraDev(QThread):
+    # 定义信号(定义)
+    sig_video = pyqtSignal(bytes, int, int, int)  # 信号传递的数据(图像的二进制数据,字节序列(bytes), 图像高度int,宽度int,通道数int)
+    def __init__(self):
+        super(CameraDev, self).__init__()
+        # 开始视频抓取的任务初始化
+        # 初始化摄像头
+        self.cam = cv2.VideoCapture(
+            0, # 摄像头的编号,从0
+            cv2.CAP_DSHOW # 视频的处理调用DirectX 3D (DirectShow)
+        )
+
+    def run(self):
+        # 设备线程的任务,run结束,则任务结束
+        while True:
+            # 反复抓取视频处理
+            # print("设备准备工作!")
+            status, img = self.cam.read()  # 从摄像头读取图像
+            if status:
+                # print(img.shape)
+                # 显示图像
+                # 2. 发送信号
+                self.sig_video.emit(img.tobytes(), img.shape[0], img.shape[1], img.shape[2])
+            QThread.usleep(100000)  # 1000000微秒 = 1秒

+ 0 - 0
day5/AIAPP/frame/__pycache__


+ 10 - 0
day5/AIAPP/frame/app.py

@@ -0,0 +1,10 @@
+from PyQt5.QtWidgets import QApplication
+from frame.win import Win
+
+class App(QApplication):
+     def __init__(self):
+          super(App,self).__init__([])
+
+
+          self.win=Win()
+          self.win.show()

+ 44 - 0
day5/AIAPP/frame/win.py

@@ -0,0 +1,44 @@
+from PyQt5.QtWidgets import QDialog
+from PyQt5.QtGui import QImage  #,QPxmap
+from PyQt5.QtGui import QPixmap  
+# 引入
+from ui.traffic_ui import Ui_Traffic
+
+from dev.camera import CameraDev
+
+class Win(QDialog):  # 扩展QDialog(新增,覆盖功能)
+    def __init__(self):  # 实现构造器(完成初始化,数据初始化,功能初始化)
+        super(Win, self).__init__()   # 调用父类构造器
+        # 调用ui
+        # 创建对象
+        self.ui = Ui_Traffic()  
+        # 关联ui到当前窗体
+        self.ui.setupUi(self)
+        
+        # 创建一个设备对象
+        self.dev = CameraDev()
+        # 启动设备线程工作
+        self.dev.start()
+
+        # 3. 绑定信号与槽。
+        self.dev.sig_video.connect(self.showVideo)
+
+    # 3. 定义槽(Slot)函数 (Qt技术:信号与槽),一定与信号同型
+    def showVideo(self, data, h, w, c):
+        # print("(",h, ",", w, ",",c, ")")  # python格式字符串
+        # 1. 使用data,h, w, c创建QImage
+        q_img = QImage(
+            data,    # 图像的字节数组
+            w,       # 图像宽度
+            h,       # 图像高度
+            w * c,   # 图像每行字节数
+            QImage.Format_BGR888   # 图像格式BGR,每个通道8个bit,1个字节
+        )
+        # 2. 使用QImage创建QPixmap
+        pix_img = QPixmap.fromImage(q_img)  # 自动从QImage转换为QPixmap,QLabel只支持QPixmap格式
+
+        # 3. 显示QLabel:lblVideo  
+        self.ui.lblVideo.setPixmap(pix_img)
+
+        # 4 适当的缩放
+        self.ui.lblVideo.setScaledContents(True)

+ 7 - 0
day5/AIAPP/main.py

@@ -0,0 +1,7 @@
+from frame.app import App
+
+
+
+app=App()
+
+app.exec() #消息循环(程序循环处理操作系统发过来的消息)阻塞函数

BIN
day5/AIAPP/ui/__pycache__/traffic_ui.cpython-39.pyc


+ 119 - 0
day5/AIAPP/ui/monitor.ui

@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Traffic</class>
+ <widget class="QDialog" name="Traffic">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>562</width>
+    <height>679</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="lblViedo">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>100</y>
+     <width>640</width>
+     <height>480</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:5px;
+border-style:dotted;
+border-color:red;
+border-radius:10px;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:purple;
+border-right-color:pink;
+
+
+</string>
+   </property>
+   <property name="text">
+    <string>视频显示区</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="ptncapture">
+   <property name="geometry">
+    <rect>
+     <x>250</x>
+     <y>580</y>
+     <width>181</width>
+     <height>71</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:7px;
+border-left-color:#ffffff;
+border-top-color:#ffffff;
+border-bottom-color:#888888;
+border-right-color:#bbbbbb;
+
+</string>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>260</x>
+     <y>30</y>
+     <width>161</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <pointsize>11</pointsize>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="text">
+    <string>智能交通监控系统</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>40</x>
+     <y>600</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>识别信息</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>630</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:1px;
+</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 2 - 0
day5/AIAPP/ui/tools.bat

@@ -0,0 +1,2 @@
+@rem @符号在执行命令,不回显命令行
+@pyuics -o traffic_ui.py traffic.ui

+ 69 - 0
day5/AIAPP/ui/traffic.ui

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Traffic</class>
+ <widget class="QDialog" name="Traffic">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>745</width>
+    <height>635</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="lblViedo">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>10</y>
+     <width>640</width>
+     <height>480</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:5px;
+border-style:dotted;
+border-color:red;
+border-radius:10px;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:purple;
+border-right-color:pink;
+
+
+</string>
+   </property>
+   <property name="text">
+    <string>视频显示区</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="ptncapture">
+   <property name="geometry">
+    <rect>
+     <x>80</x>
+     <y>510</y>
+     <width>181</width>
+     <height>71</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:7px;
+border-left-color:#ffffff;
+border-top-color:#ffffff;
+border-bottom-color:#888888;
+border-right-color:#bbbbbb;
+
+</string>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 119 - 0
day5/AIAPP/ui/traffic_ui.py

@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Traffic</class>
+ <widget class="QDialog" name="Traffic">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>769</width>
+    <height>679</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>智能交通监控系统</string>
+  </property>
+  <widget class="QLabel" name="lblViedo">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>100</y>
+     <width>640</width>
+     <height>480</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:5px;
+border-style:dotted;
+border-color:red;
+border-radius:10px;
+border-top-color:red;
+border-bottom-color:green;
+border-left-color:purple;
+border-right-color:pink;
+
+
+</string>
+   </property>
+   <property name="text">
+    <string>视频显示区</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="ptncapture">
+   <property name="geometry">
+    <rect>
+     <x>250</x>
+     <y>580</y>
+     <width>181</width>
+     <height>71</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:2px;
+border-style:solid;
+border-radius:7px;
+border-left-color:#ffffff;
+border-top-color:#ffffff;
+border-bottom-color:#888888;
+border-right-color:#bbbbbb;
+
+</string>
+   </property>
+   <property name="text">
+    <string>抓取图像</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>260</x>
+     <y>30</y>
+     <width>161</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <pointsize>11</pointsize>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="text">
+    <string>智能交通监控系统</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>40</x>
+     <y>600</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>识别信息</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>630</y>
+     <width>72</width>
+     <height>15</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">border-width:1px;
+</string>
+   </property>
+   <property name="text">
+    <string>TextLabel</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

BIN
day6/infer/03_1.jpg


BIN
day6/infer/04_9.jpg


BIN
day6/infer/05_2.jpg


BIN
day6/infer/_pycache_/__pycache__/model.cpython-39.pyc


+ 39 - 0
day6/infer/_pycache_/infer.py

@@ -0,0 +1,39 @@
+from model import LeNet5
+import torch
+import cv2
+import numpy as np
+
+class  DigitClassifier:
+    def __init__(self): # 初始化
+        super(DigitClassifier, self).__init__()
+        # 创建网络
+        self.net = LeNet5()
+        # 加载模型算子(训练好的模型)
+        state = torch.load("lenet5.pt")
+        self.net.load_state_dict(state)
+
+    
+    def recognize_file(self, digit_file): # 输入图像文件
+        # 1. 读取文件
+        img = cv2.imread(digit_file)
+        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+        # 2. 处理文件:图像转为NCHW格式的float张量
+        img = img.astype(np.float32) 
+        img = img / 255.0   # 像素转换为0-1之间的值
+        img = torch.from_numpy(img).clone()  # 把矩阵转换为张量
+        img = img.view(1, 1, 28, 28)  # 模型支持4维图像 NCHW
+        # 3. 调用self.net预测
+        y = self.net(img)
+        # 4. 处理预测结果:类别与概率
+        cls = torch.argmax(y, dim=1).item()  # item取张量的值
+        prob = y[0][cls].item()
+        print(cls, prob)
+        return cls,  prob# 返回类别,返回这个类别的概率
+
+
+
+if __name__ == "__main__":
+    classifier = DigitClassifier() # 生成分类器
+    cls, prob = classifier.recognize_file("05_2.jpg")
+    print(F"类别:{cls},概率:{prob}")
+

+ 76 - 0
day6/infer/_pycache_/model.py

@@ -0,0 +1,76 @@
+from torch.nn import Module    # 扩展该类实现我们自己的深度网络模型
+from torch.nn import Conv2d, Linear   # 卷积运算(特征抽取),全邻接线性运算(分类器)
+from torch.nn.functional import relu, max_pool2d, avg_pool2d  # relu折线函数,maxpool(从数组返回一个最大值)
+import torch
+
+class LeNet5(Module):
+    # 构造器
+    def __init__(self, class_num=10):  # 10手写数字的分类。一共10个类别
+        super(LeNet5, self).__init__()
+        """
+            5层  (28 * 28 * 1)
+                |- 1. 卷积5 * 5 -> (28 * 28 * 6)    -(2, 2) -> (14, 14 , 6)
+                |- 2. 卷积5 * 5 -> (10 * 10 * 16)   -(2, 2) -> (5, 5, 16)
+                |- 3. 卷积5 * 5 -> (1 * 1 * 120)   
+                |- 4. 全连接 120 -> 84 
+                |- 5. 全连接 84 - 10 (1, 0, 0, 0, 0, 0, 0, 0, 0, 0)  取概率最大的下标就是识别出来的数字
+        """
+        self.conv1 = Conv2d(in_channels=1, out_channels=6,  kernel_size=5, stride=1, padding=2)
+        self.conv2 = Conv2d(in_channels=6, out_channels=16, kernel_size=5, stride=1, padding=0)
+        self.conv3 = Conv2d(in_channels=16, out_channels=120, kernel_size=5, stride=1,padding=0)
+
+        self.fc1 = Linear(120, 84)
+        self.fc2 = Linear(84, 10)
+
+
+    # 预测函数
+    def forward(self, x):
+        """
+            x表述输入图像, 格式是:[NHWC]
+        """
+        y = x
+        # 计算预测
+        # 第一层网络
+        y = self.conv1(y)  # (28*28*1) -> (28*28*6)
+        y = max_pool2d(y, (2, 2))  # (28*28*6) -> (14*14*6)
+        y = relu(y)        # 过滤负值(所有的负值设置为0)
+
+        # 第二层
+        y = self.conv2(y)   # (14*14*6) -> (10*10*16)
+        y = max_pool2d(y, (2, 2))   # (10*10*16) -> (5*5*16)
+        y = relu(y)         # 过滤负值
+
+        # 第三层
+        y = self.conv3(y)   # (5*5*16) -> (1*1*120)
+
+        # 把y从(1*1*120) -> (120)向量
+        y = y.view(-1, 120)  
+
+        # 第四层
+        y = self.fc1(y)
+        y = relu(y)
+
+        # 第五层
+        y = self.fc2(y)
+        # y = relu(y)        # 这个激活函数已经没有意义
+
+        # 把向量的分量全部转换0-1之间的值(概率)     
+        y = torch.softmax(y, dim=1) 
+
+        return y
+
+
+# print(__name__)
+if __name__ == "__main__":  # 表示是独立执行册程序块
+    # 下面代码被调用,则执行不到。
+    img = torch.randint(0, 256, (1, 1, 28, 28))  # 构造一个随机矩阵 == 噪音图像[NCHW]
+    img = img.float()    # 神经网络输入的必须是float类型
+    net = LeNet5()
+    y = net(img)
+    # y = net.forward(img)  # 等价于y = net(img)
+
+    # 判定最大下标
+    cls = torch.argmax(y, dim=1)
+    print(F"识别的结果是:{cls.numpy()[0]}")
+    print(y)
+

BIN
day6/infer/lenet5.pt


+ 0 - 0
day6/infer/model.cpython-39.pyc


+ 0 - 0
day6/lenet/ds.py


+ 11 - 0
day6/lenet/model.py

@@ -0,0 +1,11 @@
+from torch.nn import Module  #扩展该类实现自己的深度网络模型
+from torch.nn import conv2d,liner   #卷积运算(特征抽取)
+from torch.nn.functional import relu,max_poold,avg_poo12d
+
+class LeNets(Module):
+    def_ init_(self,class_num=10):
+    super(LeNet5,self),_init_()
+
+    
+    def forward(self, x):
+        return

+ 0 - 0
day6/lenet/train.py


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است