pyqt5 简单项目

该文描述了一个基于Python的GUI应用程序,用于管理人脸识别系统。用户可以输入人脸数量、设置训练参数(batch_size、模型准确度、最小训练次数)并启动训练过程。程序使用argparse处理命令行参数,并结合Qt库创建交互界面。
摘要由CSDN通过智能技术生成

模块一

import argparse

parser=argparse.ArgumentParser()

parser.add_argument("--n",help="录入人脸数良",type=int,default=30)

args=parser.parse_args()

模块二

import argparse

parser=argparse.ArgumentParser()

parser.add_argument("--b",help="设置batch_size,默认为3",type=int,default=3)
parser.add_argument("--a",help="模型准确度,默认为0.3",type=float,default=0.3)
parser.add_argument("--c",help="最少模型训练次数,总次数为10,默认为3",type=int,default=2)

args= parser.parse_args()

模块三

import sys
import subprocess
from PyQt5.QtWidgets import QApplication,\
    QWidget,\
    QMessageBox,\
    QPushButton,\
    QHBoxLayout,\
    QVBoxLayout,\
    QLineEdit

class MainApp:

    def __init__(self):
        super().__init__()

        self.window=QWidget()
        self.window.setWindowTitle("生产实习")
        self.window.resize(500,500)

        self.Hlayout=QHBoxLayout()
        self.window.setLayout(self.Hlayout)

        self.button1=QPushButton(self.window)
        self.button1.setText("训练")
        self.button1.clicked.connect(self.inface)

        self.button2=QPushButton(self.window)
        self.button2.setText("识别")
        self.button2.clicked.connect(self.is_my_face)

        self.Hlayout.addWidget(self.button1)
        self.Hlayout.addWidget(self.button2)

    def inface(self):
        self.atest=ATest()
        self.atest.window.show()

    def is_my_face(self):
        subprocess.run(["python3", "is_my_face.py"])
        QMessageBox.about(self.window,"结果","识别结束")

class ATest:

    def __init__(self):
        super().__init__()

        self.window=QWidget()
        self.window.setWindowTitle("训练模块")
        self.window.resize(500,500)

        self.Hlayout=QHBoxLayout()
        self.window.setLayout(self.Hlayout)

        self.button1=QPushButton(self.window)
        self.button1.setText("录入人脸")
        self.button1.clicked.connect(self.get_my_faces)

        self.button2=QPushButton(self.window)
        self.button2.setText("训练网络")
        self.button2.clicked.connect(self.train_faces)

        self.button3=QPushButton(self.window)
        self.button3.setText("录入其他人脸")
        self.button3.clicked.connect(self.set_other_faces)

        self.Hlayout.addWidget(self.button1)
        self.Hlayout.addWidget(self.button2)
        self.Hlayout.addWidget(self.button3)

    def get_my_faces(self):
        self.face=Face()
        self.face.window.show()

    def set_other_faces(self):
        self.oface=OFace()
        self.oface.window.show()

    def train_faces(self):
        self.trains=Train()
        self.trains.window.show()

class Face:

    def __init__(self):
        super().__init__()

        self.window=QWidget()
        self.window.setWindowTitle("人脸录入模块")

        self.vlayout=QVBoxLayout()
        self.window.setLayout(self.vlayout)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("录入数量(默认为30张)")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.faces)

        self.vlayout.addWidget(self.text1)
        self.vlayout.addWidget(self.button1)

    def faces(self):
        command = ["python3","get_my_faces.py"]
        if self.text1.text():
            command.append("--n")
            command.append(self.text1.text())
        subprocess.run(command)
        QMessageBox.about(self.window, "结果", "录入结束")

class OFace:

    def __init__(self):
        super().__init__()

        self.window=QWidget()
        self.window.setWindowTitle("人脸录入模块")

        self.vlayout=QVBoxLayout()
        self.window.setLayout(self.vlayout)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("录入数量(默认为30张)")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.faces)

        self.vlayout.addWidget(self.text1)
        self.vlayout.addWidget(self.button1)

    def faces(self):
        command = ["python3","set_other_faces.py"]
        if self.text1.text():
            command.append("--n")
            command.append(self.text1.text())
        subprocess.run(command)
        QMessageBox.about(self.window, "结果", "录入结束")

class Train:

    def __init__(self):
        super().__init__()
        self.window=QWidget()
        self.window.setWindowTitle("参数设置模块")
        self.window.resize(350,200)

        self.vlayout=QVBoxLayout()
        self.window.setLayout(self.vlayout)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("设置batch_size,默认为3")

        self.text2=QLineEdit(self.window)
        self.text2.setPlaceholderText("模型准确度,默认为0.3")

        self.text3=QLineEdit(self.window)
        self.text3.setPlaceholderText("最少模型训练次数,总次数为10,默认为3")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.train)

        self.vlayout.addWidget(self.text1)
        self.vlayout.addWidget(self.text2)
        self.vlayout.addWidget(self.text3)
        self.vlayout.addWidget(self.button1)

    def train(self):
        command=["python3","train_faces.py"]

        if self.text1.text():
            command.append("--b")
            command.append(self.text1.text())

        if self.text2.text():
            command.append("--a")
            command.append(self.text2.text())

        if self.text3.text():
            command.append("--c")
            command.append(self.text3.text())

        subprocess.run(command)
        QMessageBox.about(self.window, "结果", "训练结束")

if __name__=="__main__":
    app=QApplication(sys.argv)

    maap=MainApp()
    maap.window.show()

    sys.exit(app.exec_())
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值