我安装了OpenCV 4.5.2.52 版本,尝试对我想阅读但太模糊的图片使用超分辨率。
为此,我遵循此站点中的代码: https: //programmer.group/opencv-advanced-super-resolution-based-on-opencv.html
我可以复制此页面上的不同代码,我想尝试一下这个:
import cv2
import matplotlib.pyplot as plt
# Read picture
img = cv2.imread("AI-Courses-By-OpenCV-Github.png")
img = img[5:60,700:755]
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "ESPCN_x3.pb"
sr.readModel(path)
sr.setModel("espcn",3)
result = sr.upsample(img)
# Resize image
resized = cv2.resize(img,dsize=None,fx=3,fy=3)
plt.figure(figsize=(6,2))
plt.subplot(1,3,1)
# original image
plt.imshow(img[:,:,::-1])
plt.subplot(1,3,2)
# SR up sampling image
plt.imshow(result[:,:,::-1])
plt.subplot(1,3,3)
## Sampling images on OpenCV
plt.imshow(resized[:,:,::-1])
plt.show()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误“ AttributeError:模块'cv2'没有属性'dnn_superres' ”。所以我检查了这些页面“https://blog.csdn.net/qq_48455792/article/details/120258336”(翻译自中文)和“https://github.com/opencv/opencv-python/issues/441”其中据报道,对于 4.5.x 以上的 openCV 版本,库已移至“旧版”。
我明白我只需要改变sr = cv2.dnn_superres.DnnSuperResImpl_create()它就sr = cv2.legacy.dnn_superres.DnnSuperResImpl_create()可以工作。
但随着这个改变我得到了错误
AttributeError: …
客户使用Python 2.5.5使用我的软件出现此错误.怎么会这样?_empty是否已从队列中消失?我根本不明白这一点.我没有从队列继承,只有Queue类的正常实例.在我的机器上似乎一切正常,但是,在客户的机器上出现了错误.任何人都可以给我一些建议,问题是什么?
这个问题发生在这里:
import Queue
self.requests.mutex.acquire()
allCount = self.requests._qsize()
while not self.requests._empty():
try:
(sock, addr, _) = self.requests._get()
# ... do some things
self.requests.mutex.release()
Run Code Online (Sandbox Code Playgroud)
之前,队列已初始化
self.requests = Queue(self.reqQLen)
Run Code Online (Sandbox Code Playgroud)
并且这些队列方法也用在模块中:put_nowait,qsize,get.队列用于多线程的上下文中.这可能是原因吗?
我想知道:错误消息告诉我变量请求被识别为队列实例,但属性_empty不存在.但是,这是Queue类中的常规方法.
当我将这段代码输入到python shell中时,它可以正常工作,但是在程序中它会产生错误.
import os
h = os.environ['HOME']
Run Code Online (Sandbox Code Playgroud)
在脚本中它给出了这个错误:
AttributeError: 'str' object has no attribute 'environ'
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,有什么方法可以解决它吗?
(我有点像学习python所以我不太了解.谷歌没有帮助)
我正在尝试学习python中的类:
#!/usr/bin/env python
# *-* coding: utf-8 *-*
import urllib2
from BeautifulSoup import BeautifulSoup as bs
class Crawler:
def visit(self, url):
self.request = urllib2.Request(self.url)
self.response = urllib2.urlopen(self.request)
return self.response.read()
if __name__ == "__main__":
x = Crawler()
print x.visit("http://google.com/")
Run Code Online (Sandbox Code Playgroud)
当我尝试开始收到错误时:
sigo@sarch ~/sources $ python test.py
Traceback (most recent call last):
File "test.py", line 16, in <module>
print x.visit("http://google.com/")
File "test.py", line 10, in visit
self.request = urllib2.Request(self.url)
AttributeError: Crawler instance has no attribute 'url'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我一直在寻找一个解决方案,但没有找到一个所以这里是我的代码:
class snakeGame:
def _init_(self):
pygame.init()
self._isRunning = False
self._surface = None
self.drawList = None
self.updateList = None
self.resources = loadResources()
self.width = 640
self.height = 400
self.size = [self.width,self.height]
def run(self,args):
self._surface = pygame.display.set_mode(self.size,pygame.HWSURFACE | pygame.DOUBLEBUF)
self._isRunning = True
Run Code Online (Sandbox Code Playgroud)
当调用"run"方法时,python会抛出一个AttributeError,告诉我snakeGame的实例没有属性"size"
我是python的新手,有NNNOOO的线索,为什么它没有看到它.有人能帮我吗?
这也只是我代码中的一个小片段.如果您需要更多,请询问.我只是觉得这个问题可能就在这里.
我正在学习第一个Paraboloid教程的 OpenMDAO .但是,在我使用约束情况(add_constraint(...))运行代码时,我得到错误:AttributeError:'float'对象没有属性'size'.我只是复制粘贴了教程中的代码,但我无法解决错误.这是代码:
from __future__ import print_function
from openmdao.api import IndepVarComp, Component, Problem, Group
from openmdao.api import ScipyOptimizer
from openmdao.api import ExecComp
class Paraboloid(Component):
def __init__(self):
super(Paraboloid, self).__init__()
self.add_param('x', val=0.0)
self.add_param('y', val=0.0)
self.add_output('f_xy', shape=1)
def solve_nonlinear(self, params, unknowns, resids):
"""f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3
"""
x = params['x']
y = params['y']
unknowns['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0
def linearize(self, params, unknowns, resids):
""" Jacobian for our paraboloid."""
x = params['x']
y = …Run Code Online (Sandbox Code Playgroud) 我如图所示安装了 SpeechRecognition。我的代码正确运行了几次。
我试图输入不同的文件。现在我开始收到以下错误:
import speech_recognition as sr
Traceback (most recent call last):
File "<ipython-input-1-a4d5c9aae5d0>", line 1, in <module>
import speech_recognition as sr
File "/Users/Sashank/Documents/Deep_Learning_A_Z/Personal Projects/Speech recognition/speech_recognition.py", line 7, in <module>
r = sr.Recognizer()
AttributeError: module 'speech_recognition' has no attribute 'Recognizer'
Run Code Online (Sandbox Code Playgroud)
令人困惑的是,我只执行了代码的第一行,也就是导入库。它返回错误。
import speech_recognition as sr
Run Code Online (Sandbox Code Playgroud)
错误似乎与我尚未执行的下一行代码相对应:
r = sr.Recognizer()
Run Code Online (Sandbox Code Playgroud)
我对编程和 python 都是新手。我正在使用 spyder3。我已经重新启动了内核几次。我尝试在终端上再次安装 SpeechRecognition。我也关闭并打开了 spyder 几次,但现在一次又一次地面临同样的错误。
请帮忙。
完整代码:
# Speech Recognition
# Importing Library
import speech_recognition as sr
# Creating a recognition object
r = sr.Recognizer() …Run Code Online (Sandbox Code Playgroud) 我有一个文件名列表,需要根据字符串中的某个部分进行排序。但是,它仅在我将文件扩展名作为排序字典的一部分时才有效。如果文件是 .jpg 或 .png,我希望它可以工作,所以我试图在 '_' 和 '.' 上进行拆分。特点。
sorting = ['FRONT', 'BACK', 'LEFT', 'RIGHT', 'INGREDIENTS', 'INSTRUCTIONS', 'INFO', 'NUTRITION', 'PRODUCT']
filelist = ['3006345_2234661_ENG_PRODUCT.jpg', '3006345_2234661_ENG_FRONT.jpg', '3006345_2234661_ENG_LEFT.jpg', '3006345_2234661_ENG_RIGHT.jpg', '3006345_2234661_ENG_BACK.jpg', '3006345_2234661_ENG_INGREDIENTS.jpg', '3006345_2234661_ENG_NUTRITION.jpg', '3006345_2234661_ENG_INSTRUCTIONS.jpg', '3006345_2234661_ENG_INFO.jpg']
sort = sorted(filelist, key = lambda x : sorting.index(x.re.split('_|.')[3]))
print(sort)
Run Code Online (Sandbox Code Playgroud)
这将返回错误“AttributeError: 'str' object has no attribute 're'”
我需要做什么才能在 _ 和 . 拆分我的字符串进行排序时?我只想使用拆分进行排序,而不是重新形成字符串。
我正在使用卷积神经网络,在使用顺序神经网络时,我在训练数据时遇到了问题。使用顺序是不可能获得最好的分数吗?
from numpy import array
from numpy import reshape
import numpy as np
def model_CNN(X_train,Y_train,X_test,Y_test):
model = Sequential()
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu', input_shape=(256, 1)))
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2)) # This is the dropout layer. It's main function is to inactivate 20% of neurons in order to prevent overfitting
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2))
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Flatten())
optimizer = keras.optimizers.SGD(lr=0.01, momentum=0.5)
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=64,verbose=1, validation_data=(X_test, Y_test))
print(convolutional_model.score(X_train,Y_train))
model.summary()
return …Run Code Online (Sandbox Code Playgroud) 好的,所以我一直在尝试输入命令:python但它最终会吐出来:
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 62, in <module>
import os
File "C:\Python27\lib\os.py", line 398, in <module>
import UserDict
File "C:\Python27\lib\UserDict.py", line 83, in <module>
import _abcoll
File "C:\Python27\lib\_abcoll.py", line 70, in <module>
Iterable.register(str)
File "C:\Python27\lib\abc.py", line 107, in register
if not isinstance(subclass, (type, types.ClassType)):
AttributeError: 'module' object has no attribute 'ClassType'
Run Code Online (Sandbox Code Playgroud)
我将types.py重命名为nottypes.py但它仍然给我完全相同的消息.