模块一
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_())