0

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))
4
  • 1
    Could you provide the full traceback? I don't see what line of the provided code would produce that error. It might also help to describe what you're trying to accomplish with this code. Some of it looks strange, but I can't tell what you should be doing instead if I don't know what you're trying to do. Commented Apr 23, 2019 at 18:42
  • Welcome to Stack Overflow! Your code does not run for several reasons (img and octaves are not defined, for example). Please edit your question to include enough code that we can run it. See minimal reproducible example. Commented Apr 23, 2019 at 18:43
  • 1
    import ReponseLayer implies you have a file named ResponseLayer.py somewhere, and the module is distinct from the any class by the same name that might defined in the file. Further, RS is a method, not a class, so it's not clear what code is generating the AttributeError or why you aren't getting a NameError on the use of RS you show. Commented Apr 23, 2019 at 18:48
  • 2
    You should work through the tutorial, though; your code looks like someone trying to write Java in Python, rather than real Python code. Commented Apr 23, 2019 at 18:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.