(十)老照片修复、图像超分、图片提高分辨率、图片高清化、图片清晰化、黑白图片上色、人脸祛斑、美颜、人体瘦身、图像去噪、人像抠图、批量处理、视频提高分辨率、视频逐帧修复

2023-11-20

(十)老照片修复、图像超分、图片提高分辨率、图片高清化、图片清晰化、黑白图片上色、人脸祛斑、美颜、人体瘦身、图像去噪、人像抠图、批量处理、视频提高分辨率、视频逐帧修复

本文的代码的功能是:可以对图片文件、视频批量增强清晰度,对老照片进行修复、复原操作、对黑白照片进行上色处理、人脸祛斑、美颜、人体瘦身、图像去噪等图像处理功能,使用了人工智能的算法。

本文与前几篇博文关联性较强,请事先阅读前几篇。 对此文感兴趣的可以加微深入探讨:herbert156
可运行的试用版本下载:https://pan.baidu.com/s/1nHvh_fd5yT5Spb2Faknn3Q 提取码: vu6d
如果提示过期,可以向博主索要新的SN文件。

一、主要功能:
以下的Python代码的功能:批量选择视频、批量选择图片,主要包括:
1、对图片、视频进行高清化、修复、上色并输出变换后的文件;
2、可以批量处理,在选择文件的对话框里可以选择多个文件,进行批量操作;
3、如果电脑有GPU,则会自动选择GPU处理,加快处理速度;
4、信息统计里面可以实时显示处理的各种统计信息;
5、视频处理完毕后自动进行音频的处理与合成。

软件运行界面如下:
在这里插入图片描述

二、主要代码:

话不多说,上代码!

UI的Python代码:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Repire_UI.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# 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_ai_repire(object):
    def setupUi(self, ai_repire):
        ai_repire.setObjectName("ai_repire")
        ai_repire.setEnabled(True)
        ai_repire.resize(912, 823)
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        ai_repire.setFont(font)
        ai_repire.setMouseTracking(False)
        self.layoutWidget = QtWidgets.QWidget(ai_repire)
        self.layoutWidget.setGeometry(QtCore.QRect(360, 760, 531, 41))
        self.layoutWidget.setObjectName("layoutWidget")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget)
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.startButton = QtWidgets.QPushButton(self.layoutWidget)
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.startButton.setFont(font)
        self.startButton.setObjectName("startButton")
        self.horizontalLayout_5.addWidget(self.startButton)
        self.stopButton = QtWidgets.QPushButton(self.layoutWidget)
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.stopButton.setFont(font)
        self.stopButton.setObjectName("stopButton")
        self.horizontalLayout_5.addWidget(self.stopButton)
        spacerItem = QtWidgets.QSpacerItem(60, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_5.addItem(spacerItem)
        self.helpButton = QtWidgets.QPushButton(self.layoutWidget)
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.helpButton.setFont(font)
        self.helpButton.setObjectName("helpButton")
        self.horizontalLayout_5.addWidget(self.helpButton)
        self.quitButton = QtWidgets.QPushButton(self.layoutWidget)
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.quitButton.setFont(font)
        self.quitButton.setObjectName("quitButton")
        self.horizontalLayout_5.addWidget(self.quitButton)
        self.groupBox_2 = QtWidgets.QGroupBox(ai_repire)
        self.groupBox_2.setGeometry(QtCore.QRect(10, 20, 881, 281))
        self.groupBox_2.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
        self.groupBox_2.setAlignment(QtCore.Qt.AlignCenter)
        self.groupBox_2.setObjectName("groupBox_2")
        self.my_label1 = QtWidgets.QLabel(self.groupBox_2)
        self.my_label1.setGeometry(QtCore.QRect(12, 30, 427, 240))
        self.my_label1.setObjectName("my_label1")
        self.my_label2 = QtWidgets.QLabel(self.groupBox_2)
        self.my_label2.setGeometry(QtCore.QRect(443, 30, 427, 240))
        self.my_label2.setObjectName("my_label2")
        self.groupBox_4 = QtWidgets.QGroupBox(ai_repire)
        self.groupBox_4.setGeometry(QtCore.QRect(10, 320, 881, 111))
        self.groupBox_4.setAlignment(QtCore.Qt.AlignCenter)
        self.groupBox_4.setObjectName("groupBox_4")
        self.filesButton = QtWidgets.QPushButton(self.groupBox_4)
        self.filesButton.setGeometry(QtCore.QRect(20, 30, 78, 24))
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.filesButton.setFont(font)
        self.filesButton.setObjectName("filesButton")
        self.outButton = QtWidgets.QPushButton(self.groupBox_4)
        self.outButton.setGeometry(QtCore.QRect(20, 70, 78, 24))
        font = QtGui.QFont()
        font.setFamily("宋体")
        font.setPointSize(12)
        self.outButton.setFont(font)
        self.outButton.setObjectName("outButton")
        self.txt1 = QtWidgets.QLabel(self.groupBox_4)
        self.txt1.setGeometry(QtCore.QRect(110, 32, 771, 20))
        self.txt1.setObjectName("txt1")
        self.txt2 = QtWidgets.QLabel(self.groupBox_4)
        self.txt2.setGeometry(QtCore.QRect(110, 72, 771, 20))
        self.txt2.setObjectName("txt2")
        self.groupBox_5 = QtWidgets.QGroupBox(ai_repire)
        self.groupBox_5.setGeometry(QtCore.QRect(10, 640, 881, 81))
        self.groupBox_5.setAlignment(QtCore.Qt.AlignCenter)
        self.groupBox_5.setObjectName("groupBox_5")
        self.txt11 = QtWidgets.QLabel(self.groupBox_5)
        self.txt11.setGeometry(QtCore.QRect(20, 20, 861, 16))
        self.txt11.setObjectName("txt11")
        self.txt12 = QtWidgets.QLabel(self.groupBox_5)
        self.txt12.setGeometry(QtCore.QRect(20, 50, 861, 21))
        self.txt12.setObjectName("txt12")
        self.groupBox_6 = QtWidgets.QGroupBox(ai_repire)
        self.groupBox_6.setGeometry(QtCore.QRect(10, 450, 881, 71))
        self.groupBox_6.setAlignment(QtCore.Qt.AlignCenter)
        self.groupBox_6.setObjectName("groupBox_6")
        self.checkBox_1 = QtWidgets.QCheckBox(self.groupBox_6)
        self.checkBox_1.setGeometry(QtCore.QRect(40, 30, 141, 16))
        self.checkBox_1.setObjectName("checkBox_1")
        self.checkBox_2 = QtWidgets.QCheckBox(self.groupBox_6)
        self.checkBox_2.setGeometry(QtCore.QRect(210, 30, 141, 16))
        self.checkBox_2.setObjectName("checkBox_2")
        self.groupBox_7 = QtWidgets.QGroupBox(ai_repire)
        self.groupBox_7.setGeometry(QtCore.QRect(10, 550, 881, 71))
        self.groupBox_7.setAlignment(QtCore.Qt.AlignCenter)
        self.groupBox_7.setObjectName("groupBox_7")
        self.checkBox_3 = QtWidgets.QCheckBox(self.groupBox_7)
        self.checkBox_3.setGeometry(QtCore.QRect(40, 30, 141, 16))
        self.checkBox_3.setObjectName("checkBox_3")
        self.checkBox_4 = QtWidgets.QCheckBox(self.groupBox_7)
        self.checkBox_4.setGeometry(QtCore.QRect(210, 30, 141, 16))
        self.checkBox_4.setObjectName("checkBox_4")
        self.checkBox_5 = QtWidgets.QCheckBox(self.groupBox_7)
        self.checkBox_5.setGeometry(QtCore.QRect(390, 30, 181, 16))
        self.checkBox_5.setObjectName("checkBox_5")
        self.comboBox_1 = QtWidgets.QComboBox(self.groupBox_7)
        self.comboBox_1.setGeometry(QtCore.QRect(560, 28, 71, 22))
        self.comboBox_1.setObjectName("comboBox_1")

        self.retranslateUi(ai_repire)
        QtCore.QMetaObject.connectSlotsByName(ai_repire)

    def retranslateUi(self, ai_repire):
        _translate = QtCore.QCoreApplication.translate
        ai_repire.setWindowTitle(_translate("ai_repire", "iCANX图像修复工具"))
        self.startButton.setText(_translate("ai_repire", "开始处理"))
        self.stopButton.setText(_translate("ai_repire", "停止处理"))
        self.helpButton.setText(_translate("ai_repire", "帮助"))
        self.quitButton.setText(_translate("ai_repire", "退出"))
        self.groupBox_2.setTitle(_translate("ai_repire", "预览窗口"))
        self.my_label1.setText(_translate("ai_repire", "原图"))
        self.my_label2.setText(_translate("ai_repire", "卡通"))
        self.groupBox_4.setTitle(_translate("ai_repire", "文件设置"))
        self.filesButton.setText(_translate("ai_repire", "选择文件"))
        self.outButton.setText(_translate("ai_repire", "输出目录"))
        self.txt1.setText(_translate("ai_repire", "请选择图像文件[Ctrl+A全选、Ctrl/Shift+鼠标可多选]......"))
        self.txt2.setText(_translate("ai_repire", "输出目录"))
        self.groupBox_5.setTitle(_translate("ai_repire", "信息统计"))
        self.txt11.setText(_translate("ai_repire", "【图像信息】"))
        self.txt12.setText(_translate("ai_repire", "【运行信息】"))
        self.groupBox_6.setTitle(_translate("ai_repire", "功能选择"))
        self.checkBox_1.setText(_translate("ai_repire", "照片高清修复"))
        self.checkBox_2.setText(_translate("ai_repire", "黑白照片上色"))
        self.groupBox_7.setTitle(_translate("ai_repire", "输出设置"))
        self.checkBox_3.setText(_translate("ai_repire", "原始分辨率"))
        self.checkBox_4.setText(_translate("ai_repire", "2倍分辨率"))
        self.checkBox_5.setText(_translate("ai_repire", "手动设置(图片宽度):"))

主处理代码:

class MainWin(QWidget, Ui_ai_repire):
    def __init__(self):
        super(MainWin, self).__init__()
        self.setupUi(self)
        global hwnd, run_flag
        self.createLayout()
        self.setWindowIcon(QIcon("damo/anime.ico"))
        self.setWindowFlags(Qt.WindowMinimizeButtonHint)
        self.show(); run_flag = 1

    def CV2toPIL(self, img):  # cv2转PIL
        return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA))
    def PILtoCV2(self, img):  # PIL转cv2
        return cv2.cvtColor(np.array(img), cv2.COLOR_RGBA2BGRA)
    def two_pic_combine_PIL(self, back_img, fore_img): #2个图片合并
        back_img = self.CV2toPIL(back_img); fore_img = self.CV2toPIL(fore_img); r,g,b,alpha = fore_img.split()
        return cv2.cvtColor(self.PILtoCV2(Image.composite(fore_img, back_img, alpha)), cv2.COLOR_BGRA2BGR)

    def ShowCarton(self, result, img_path, style):  # 卡通转换
        if self.checkBox_1.isChecked(): multiple = 2    # 图片修复返回的图片分辨率是原图的2else: multiple = 1  # 图片上色返回的图片分辨率是原图的1倍

        size_x = result.shape[1]  # 宽度
        size_y = result.shape[0]  # 高度

        if self.checkBox_3.isChecked(): # 原始分辨率
            img_w = int(size_x/multiple)
            img_h = int(size_y/multiple)
        elif self.checkBox_4.isChecked(): # 2倍分辨率
            img_w = int(size_x*2/multiple)
            img_h = int(size_y*2/multiple)
        elif self.checkBox_5.isChecked(): # 手动设置
            set_w = int(self.comboBox_1.currentText())
            img_w = set_w
            img_h = int(size_y * (set_w / result.shape[1]))
        else:
            img_w = int(size_x*2/multiple)
            img_h = int(size_y*2/multiple)

        jpg_name = out_dir + '/' + os.path.splitext(os.path.split(img_path)[1])[0] + '_'+style+'.jpg'
        # print(img_w, img_h)
        outfile = cv2.resize(result, (img_w, img_h))
        cv2.imencode('.jpg', outfile)[1].tofile(jpg_name)

        if size_x / size_y > 1.7778: fx = 427 / size_x; fy = fx   # 计算16:9的比例,以便缩放不变形
        else: fx = 240 / size_y; fy = fx
        self.my_label2.setPixmap(self.CvMatToQImage(cv2.resize(result, (0, 0), fx=fx, fy=fy)))
        cv2.waitKey(1)
        # cv2.imshow('Test', result1.astype(np.uint8));  cv2.waitKey(0)

    def image_change_background(self, imagefile):
        global iii, stop_flag, t0
        try:
            img1= cv2.imdecode(np.fromfile(imagefile, dtype=np.uint8), -1)
            if img1.shape[2] == 4: img1 = cv2.cvtColor(img1, cv2.COLOR_BGRA2BGR)
        except:
            self.show_error('读取图片文件【'+imagefile+'】时,出现错误!\n\n原因:目录/文件名不能包含中文...'); return
        cv2.waitKey(1)

        if img1 is None: self.show_error('读取图片文件【'+imagefile+'】时,出现错误!\n\n原因:目录/文件名不能包含中文...'); return

        size_x = img1.shape[1]  # 宽度
        size_y = img1.shape[0]  # 高度
        if size_x > 3840 or size_x > 3840:
            self.show_error('【文件】:'+ imagefile + '\n【分辨率】:' + str(size_x) + 'x' + str(size_y) +
                                   '\n\n【错误信息】:图片文件的长边不能大于3840像素!\n'); return
        if self.checkBox_3.isChecked() or self.checkBox_4.isChecked() or self.checkBox_5.isChecked(): pass
        else: self.show_error('\n您必须在【输出设置】里面,选择一项【输出分辨率】的选项...\n'); return

        imageinfo = '【图片信息】 文件总数:%d | 正在处理(%d/%d):'%(filesnums,iii,filesnums) + os.path.split(imagefile)[1]+\
                    ' | 图像分辨率:%dx%d '%(size_x,size_y)
        self.txt11.setText(imageinfo)
        t1 = time.time()
        if size_x / size_y > 1.7778: fx = 427 / size_x; fy = fx   # 计算16:9的比例,以便缩放不变形
        else: fx = 240 / size_y; fy = fx

        if stop_flag:
            self.txt11.setText('【图片信息】 文件总s数:%d个 | 处理完成:%d个' % (filesnums, iii))
            self.txt12.setText('【运行信息】 用户终止了正在运行的程序......')
            return
        self.my_label1.setPixmap(self.CvMatToQImage(cv2.resize(img1, (0, 0), fx=fx, fy=fy)))

        if not DEBUG_FLAG: self.RunCarton(imagefile)
        else: pass  #img3 = img1

        cv2.waitKey(1); t2 = time.time()
        runinfo = '【运行信息】 当前图片处理耗时:%.3f| 总处理耗时:%.1f| 处理进度:%.1f%%'%((t2-t1),(t2-t0),100*(iii/filesnums))
        self.txt12.setText(runinfo);  cv2.waitKey(1)
        self.txt12.setText('【运行信息】 处理完毕!总消耗时间:%d秒'%(t2-t0))
        self.txt11.setText('【图片信息】 文件总数:%d个 | 处理完成:%d个'%(filesnums,iii))

    def CvMatToQImage(self, ptr):  # Converts an opencv MAT format into a QImage
        ptr = cv2.cvtColor(ptr, cv2.COLOR_BGRA2RGBA)  # 颜色格式转换
        QtImg = QtGui.QImage(ptr.data, ptr.shape[1], ptr.shape[0], QtGui.QImage.Format_RGBA8888)
        return QtGui.QPixmap.fromImage(QtImg)

    # def show_error(self,str):
    #     r_button = QMessageBox.question(self, my_title,'\n\n'+str+'\n\n', QMessageBox.Ok)
    def show_error(self, str):
        infoBox = QMessageBox()
        infoBox.setIcon(QMessageBox.Information)
        infoBox.setText(str)
        infoBox.setStandardButtons(QMessageBox.Ok)
        infoBox.button(QMessageBox.Ok).animateClick(30000)  # 10秒自动关闭
        infoBox.exec_()

    def set_False_Btn(self):
        self.filesButton.setEnabled(False);       self.outButton.setEnabled(False)
        self.startButton.setEnabled(False);       self.stopButton.setEnabled(True)
        self.quitButton.setEnabled(False)
    def set_True_Btn(self):
        self.filesButton.setEnabled(True);       self.outButton.setEnabled(True)
        self.startButton.setEnabled(True);       self.stopButton.setEnabled(False)
        self.quitButton.setEnabled(True)

    def startrun(self):
        global iii,stop_flag,t0
        iii = 0; stop_flag = False

        self.txt12.setText('【运行信息】 正在初始化AI模型......');cv2.waitKey(1)
        t0 = time.time()

        if files == []: self.show_error('请选择需要变换的图像文件!'); return
        if not os.path.exists(out_dir): self.show_error('输出目录不存在,请重新选择!'); return
        self.set_False_Btn()

        for file in files:
            iii += 1
            if stop_flag: break
            self.image_change_background(file)

        self.set_True_Btn()

    def stoprun(self):
        global stop_flag
        r_button = QMessageBox.question(self, my_title,
                                        "\n\n    确定要停止图片变换吗?\n\n", QMessageBox.Yes | QMessageBox.No)
        if r_button == QMessageBox.Yes: stop_flag = True

    def helpWin(self):
        str="\n\n\n1、【选择文件】选择需要修复的图像文件(可多选);\n2、【输出目录】修复后的文件目录,文件名:源文件_1.jpg;\n"+\
        "3、如没有Nvidia系列GPU,AI算法自动选择CPU处理;\n4、文件的长边不能大于3840像素;\n\n\n"+\
        "      本软件著作权归属:XXX         网址:xxx.com\n\n"
        QMessageBox.question(self, my_title, str, QMessageBox.Ok)
    def quitWin(self):
        r_button = QMessageBox.question(self, my_title,
                                        "\n\n退出将终止修复过程...... \n\n确认退出吗?\n\n", QMessageBox.Yes | QMessageBox.No)
        if r_button == QMessageBox.Yes: sys.exit()

    def filesButton_fuc(self):
        global files,filesnums, input_path
        files, ok1 = QFileDialog.getOpenFileNames(self,'请选择图像文件[全选:Ctrl+A、多选:Ctrl/Shift+鼠标]',
                                                       input_path,"*.jpg;;*.png")
        filesnums = len(files)
        if files!=[]:
            txt='目录:'+os.path.split(files[0])[0]+' | 已选文件:'+str(filesnums)+'个 | 文件名:'
            for file in files: txt=txt+ os.path.split(file)[1]+'; '
            self.txt1.setText(txt)
            input_path = os.path.split(files[0])[0]
        else: self.txt1.setText('请选择图像文件[全选:Ctrl+A、多选:Ctrl/Shift+鼠标]......')

    def outButton_fuc(self):
        global out_dir, work_path
        out_dir = QFileDialog.getExistingDirectory(self,'选择修复后的输出文件夹', work_path)
        if out_dir == '':
            self.txt2.setText('请选择图片修复后的文件保存目录......')
            work_path = out_dir
        else: self.txt2.setText(out_dir)

    def box_choose1(self):  # 照片高清修复
        if self.checkBox_1.isChecked(): self.checkBox_2.setChecked(False)
        else: self.checkBox_2.setChecked(True)
    def box_choose2(self):  # 黑白照片上色
        if self.checkBox_2.isChecked(): self.checkBox_1.setChecked(False)
        else: self.checkBox_1.setChecked(True)
    def box_choose3(self):  # 原始分辨率
        self.checkBox_4.setChecked(False)
        self.checkBox_5.setChecked(False)
    def box_choose4(self):  # 2倍分辨率
        self.checkBox_3.setChecked(False)
        self.checkBox_5.setChecked(False)
    def box_choose5(self):  # 手动设置
        self.comboBox_1.setEnabled(True)
        self.checkBox_3.setChecked(False)
        self.checkBox_4.setChecked(False)
    def click_comboBox1(self, text):    # 手动分辨率
        pass
    def createLayout(self):
        self.my_label1.setPixmap(self.CvMatToQImage(img_start))
        self.my_label2.setPixmap(self.CvMatToQImage(img_start))

        self.my_label1.setAlignment(Qt.AlignCenter); self.my_label2.setAlignment(Qt.AlignCenter)
        self.my_label1.setFixedSize(427, 240); self.my_label2.setFixedSize(427, 240)
        self.my_label1.setAlignment(Qt.AlignCenter); self.my_label2.setAlignment(Qt.AlignCenter)
        self.my_label1.setToolTip("本区域,显示的是原始图片缩略图...")
        self.my_label2.setToolTip("本区域,显示的是变换后的缩略图...")

        self.checkBox_1.setChecked(True)
        self.checkBox_4.setChecked(True)

        self.checkBox_1.stateChanged.connect(self.box_choose1)
        self.checkBox_2.stateChanged.connect(self.box_choose2)
        self.checkBox_3.stateChanged.connect(self.box_choose3)
        self.checkBox_4.stateChanged.connect(self.box_choose4)
        self.checkBox_5.stateChanged.connect(self.box_choose5)

        self.comboBox_1.addItems(['3840','2560','1920','1280','640'])
        self.comboBox_1.setEnabled(False)
        self.comboBox_1.activated[str].connect(self.click_comboBox1)

        self.filesButton.setToolTip("选择即将被变换的的图片文件,可单选、多选...")
        self.outButton.setToolTip("选择输出文件目录,变换后的文件将存在此目录...")

        self.txt2.setText(out_dir)

        self.filesButton.clicked.connect(self.filesButton_fuc)
        self.outButton.clicked.connect(self.outButton_fuc)

        self.stopButton.setEnabled(False)
        self.startButton.clicked.connect(self.startrun)
        self.stopButton.clicked.connect(self.stoprun)
        self.helpButton.clicked.connect(self.helpWin)
        self.quitButton.clicked.connect(self.quitWin)

#if __name__ == '__main__':
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication(sys.argv)
MainWin = MainWin()
sys.exit(app.exec_())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

(十)老照片修复、图像超分、图片提高分辨率、图片高清化、图片清晰化、黑白图片上色、人脸祛斑、美颜、人体瘦身、图像去噪、人像抠图、批量处理、视频提高分辨率、视频逐帧修复 的相关文章

  • 如何覆盖 Django 的默认管理模板和布局

    我正在尝试覆盖 Django 的默认模板 现在只有base site html 我正在尝试更改 django 管理文本 我做了以下事情 我在我的应用程序目录中创建了一个文件夹 opt mydjangoapp templates admin
  • 从 SHAP 值中获取特征重要性

    我想要获得重要功能的数据框 通过下面的代码 我得到了 shap values 但我不确定这些值的含义是什么 在我的 df 中有 142 个特征和 67 个实验 但得到了一个带有 ca 的数组 2500 个值 explainer shap T
  • 上传时的 Google Drive API——这些额外的空行从何而来?

    总结一下该程序 我从我的 Google 云端硬盘下载一个文件 然后在本地计算机中打开并读取一个文件 file a txt 然后在我的计算机中打开另一个文件 file b txt 处于附加模式 并且在使用这个新的 file b 更新我的 Go
  • 检测到通过 ChromeDriver 启动的 Chrome 浏览器

    我正在尝试在 python 中使用 selenium chromedriver 来访问 www mouser co uk 网站 然而 从第一次拍摄开始 它就被检测为机器人 有人对此有解释吗 此后我使用的代码 options Options
  • 将 transaction.commit_manually() 升级到 Django > 1.6

    我继承了为 Django 1 4 编写的应用程序的一些代码 我们需要更新代码库以使用 Django 1 7 并最终更新到 1 8 作为下一个长期支持版本 在一些地方它使用旧风格 transaction commit manually and
  • TensorFlow:带有轴选项的 bincount

    在 TensorFlow 中 我可以使用 tf bincount 获取数组中每个元素的计数 x tf placeholder tf int32 None freq tf bincount x tf Session run freq feed
  • Python 是解释型的还是编译型的,或者两者兼而有之?

    据我了解 An 解释的语言是由解释器 将高级语言转换为机器代码然后执行的程序 实时运行和执行的高级语言 它一次处理一点程序 A compiled语言是一种高级语言 其代码首先由编译器 将高级语言转换为机器代码的程序 转换为机器代码 然后由执
  • 字符串中的注释和注释中的字符串

    我正在尝试使用 Python 和 Regex 计算 C 代码中包含的注释中的字符数 但没有成功 我可以先删除字符串以删除字符串中的注释 但这也会删除注释中的字符串 结果会很糟糕 是否有机会通过使用正则表达式来询问不匹配注释中的字符串 反之亦
  • ImportError:运行 jupyter Notebook 时没有名为 IPython.paths 的模块?

    我通过以下方式安装了 jupyter usr local opt python bin python2 7 m pip install jupyter 这将安装 ipython 版本 4 1 2 但是 当我运行 jupyter Notebo
  • ValueError:不支持连续[重复]

    这个问题在这里已经有答案了 我正在使用 GridSearchCV 进行线性回归的交叉验证 不是分类器也不是逻辑回归 我还使用 StandardScaler 对 X 进行标准化 我的数据框有 17 个特征 X 和 5 个目标 y 观察 约11
  • 如何使用 javascript/jquery/AJAX 调用 Django REST API?

    我想使用 Javascript jQuery AJAX 在前端调用 Django Rest API 请求方法是 POST 但当我看到 API 调用它的调用 OPTIONS 方法时 所以 我开始了解access control allow o
  • 在相同任务上,Keras 比 TensorFlow 慢

    我正在使用 Python 运行斩首 DCNN 本例中为 Inception V3 来获取图像特征 我使用的是 Anaconda Py3 6 和 Windows7 使用 TensorFlow 时 我将会话保存在变量中 感谢 jdehesa 并
  • 揭秘sharedctypes性能

    在 python 中 可以在多个进程之间共享 ctypes 对象 然而我注意到分配这些对象似乎非常昂贵 考虑以下代码 from multiprocessing import sharedctypes as sct import ctypes
  • Python Django-如何从输入文件标签读取文件?

    我不想将文件保存在我的服务器上 我只想在下一页中读取并打印该文件 现在我有这个 index html
  • GradientTape 根据损失函数是否被 tf.function 修饰给出不同的梯度

    我发现计算的梯度取决于 tf function 装饰器的相互作用 如下所示 首先 我为二元分类创建一些合成数据 tf random set seed 42 np random seed 42 x tf random normal 2 1 y
  • 在 Spyder 的变量资源管理器中查看局部变量

    我是 python 新手 正在使用 Spyder 的 IDE 我欣赏它的一项功能是它的变量资源管理器 然而 根据一些研究 我发现它只显示全局变量 我找到的解决方法是使用检查模块 import inspect local vars def m
  • PIL - 需要抖动,但限制调色板会导致问题

    我是 Python 新手 正在尝试使用 PIL 来执行 Arduino 项目所需的解析任务 这个问题涉及到Image convert 方法以及调色板 抖动等选项 我有一些硬件能够一次仅显示 16 种颜色的图像 但它们可以指定为 RGB 三元
  • 计算互相关函数?

    In R 我在用ccf or acf计算成对互相关函数 以便我可以找出哪个移位给我带来最大值 从它的外观来看 R给我一个标准化的值序列 Python 的 scipy 中是否有类似的东西 或者我应该使用fft模块 目前 我正在这样做 xcor
  • 如何使用Python保存“完整的网页”而不仅仅是基本的html

    我正在使用以下代码来使用 Python 保存网页 import urllib import sys from bs4 import BeautifulSoup url http www vodafone de privat tarife r
  • 使用Multiprocessing和Pool时如何访问全局变量?

    我试图避免将变量冗余地传递到dataList e g 1 globalDict 2 globalDict 3 globalDict 并在全球范围内使用它们 global globalDict然而 在下面的代码中并不是这样做的解决方案 是否有

随机推荐