Darren
Darren

Reputation: 63

'RecursionError: maximum recursion depth exceeded' for Neural Net in Python

I'm trying to train a neural net to produce a synthetic image of a cat. I'm currently getting this error and it's the first time I've seen it:

Traceback (most recent call last):
  File "gan10.py", line 43, in loadImages
    (x_train, y_train), (x_test, y_test) = loadImages()
  File "gan10.py", line 43, in loadImages
    (x_train, y_train), (x_test, y_test) = loadImages()
  File "gan10.py", line 43, in loadImages
    (x_train, y_train), (x_test, y_test) = loadImages()
  [Previous line repeated 997 more times]
RecursionError: maximum recursion depth exceeded

This first line is line 43:

def loadImages():
    (x_train, y_train), (x_test, y_test) = loadImages()
    x_train = (x_train.astype(np.float32) - 127.5)/127.5
    x_train = x_train.reshape(60000, 784)
    return (x_train, y_train, x_test, y_test)

Do I need to rewrite this iteratively rather than recursively? I have already tried to set a new recursion limit with:

import sys
sys.setrecursionlimit(2000) 

This did not appear to do anything.

Any help would be appreciated.

Upvotes: 0

Views: 512

Answers (1)

Óscar López
Óscar López

Reputation: 236014

Do I need to rewrite this iteratively rather than recursively?

No, you need to fix your logic:

def loadImages():
    (x_train, y_train), (x_test, y_test) = loadImages()

This is an infinite loop, the function loadImages() is calling itself without an exit condition.

Upvotes: 5

Related Questions