Your code snippet uses undefined modules such as mem_update and it’s also unclear how and where self.layerX are defined and used.
Could you post an executable code snippet, which would reproduce this issue?