I have this kind of problem attributeError: module 'ResponseLayer' has no attribute 'RS'. I am a beginner just started learning python from scratch. What do i need to understand here? Am i wrong coding this?
class ResponseLayer:
def RS(self,_width, _height, _step, _filter):
self.width = _width
self.height = _height
self.step = _step
self.filterr = _filter
class FastHessian:
import ResponseLayer
def buildResponseMap():
responseMap = []
w = int(img.Width / init)
h = int(img.Height / init)
s = int(init)
if (octaves >=1):
responseMap.append(RS(w, h, s, 9))
responseMap.append(RS(w, h, s, 15))
responseMap.append(RS(w, h, s, 21))
responseMap.append(RS(w, h, s, 27))
1 Answer 1
Ianny,
If all the code you've shown live in the same file, then you don't have to import ResponseLayer.
I believe you're adding unique instances of ResponseLayer to a response map.
If I am correct, then you should change that RS method on ResponseLayer class to an instance creation method (init in Python).
So that you just write ResponseLayer(20, 30, 2, 4) to create an example response layer object.
This is what I mean:
class ResponseLayer:
def __init__(self, width, height, step, _filter):
self.width = width
self.height = height
self.step = step
self._filter = _filter
class FastHessian:
def buildResponseMap():
responseMap = []
w = int(img.Width / init)
h = int(img.Height / init)
s = int(init)
if (octaves>= 1):
responseMap.append(ResponseLayer(w, h, s, 9))
responseMap.append(ResponseLayer(w, h, s, 15))
responseMap.append(ResponseLayer(w, h, s, 21))
responseMap.append(ResponseLayer(w, h, s, 27))
I understand you are a Python beginner.
Welcome to the world of Python.
I love helping beginners level up in my areas of strength. Like @chepner mentioned, your code looks too Java for Python. I would love to help you rewrite it to be more Pythonic. Feel free to chat me up here on StackOverflow.
imgandoctavesare not defined, for example). Please edit your question to include enough code that we can run it. See minimal reproducible example.import ReponseLayerimplies you have a file namedResponseLayer.pysomewhere, and the module is distinct from the any class by the same name that might defined in the file. Further,RSis a method, not a class, so it's not clear what code is generating theAttributeErroror why you aren't getting aNameErroron the use ofRSyou show.