最近一直在做深度学习,因为要在项目中实现,一直苦于没有好的搭载平台,前后试过Java,Android,Qt,移植过程比较恶心。opencv只出到3.3.1,以前的版本都不可以移植tensorflow,opencv还没有很好的与深度学习框架的一个搭配,最近也一直在做吧。
所以最好的方式还是通过Python来做深度学习,方便,tensorflow的github也都是为它做的。
了解到了PyQt5,是一款使用Qt5去做UI,然后在转化成Python的py文件。
PyQt5 的安装配置方式:PyQt5安装配置方式
在QtDesigner中编写界面:
这个UI编辑方式和Qt一模一样,会Qt的话,得心应手。编写好了之后保存就可以了。
然后选中这个ui文件,用External Tools中的PyUIC转化成py文件,因为新建中用了图标,所以图标也需要转化。.qrc文件和所用到的图标都要放在同一个目录中,防止出错,找不到。qrc图标文件用External Tools中的Pyqcc进行转化。
这样机会生成一个这样的文件。用python写成的ui。
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(835, 520)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 835, 26))
self.menubar.setObjectName("menubar")
self.menu_2 = QtWidgets.QMenu(self.menubar)
self.menu_2.setObjectName("menu_2")
self.menu_3 = QtWidgets.QMenu(self.menubar)
self.menu_3.setObjectName("menu_3")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
MainWindow.setMenuBar(self.menubar)
self.toolBar = QtWidgets.QToolBar(MainWindow)
self.toolBar.setObjectName("toolBar")
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.action_N = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/new/prefix1/new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_N.setIcon(icon)
self.action_N.setObjectName("action_N")
self.menu.addAction(self.action_N)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.menu_2.setTitle(_translate("MainWindow", "编辑"))
self.menu_3.setTitle(_translate("MainWindow", "关于"))
self.menu.setTitle(_translate("MainWindow", "文件(&F)"))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
self.action_N.setText(_translate("MainWindow", "新建(&N)"))
然后新建一个Python File,在文件中编写:
from PyQt5 import QtWidgets
from test2 import Ui_MainWindow
from PyQt5.QtWidgets import QFileDialog
class MyWindow(QtWidgets.QMainWindow,Ui_MainWindow):
def __init__(self):
super(MyWindow,self).__init__()
self.setupUi(self)
self.action_N.triggered.connect(self.openMsg)
def openMsg(self):
file,ok=QFileDialog.getOpenFileName(self,"打开","All Files(*);;Text Files(*.txt)")
self.statusBar().showMessage(file)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
myshow = MyWindow()
myshow.show()
sys.exit(app.exec_())
然后运行:
博主在寻找深度学习项目的搭载平台时,发现Python结合Tensorflow是最优选择。文章介绍了如何利用PyQt5创建UI,并通过QtDesigner设计界面,使用PyUIC和Pyqcc将UI文件转化为Python代码,从而构建一个深度学习记事本。
618

被折叠的 条评论
为什么被折叠?



