OverflowError: Range exceeds valid bounds

1,445 views
Skip to first unread message

chris....@gmail.com

unread,
May 9, 2016, 7:16:46 PM5/9/16
to Keras-users, cha...@fordham.edu, jst...@fordham.edu, ajohn...@fordham.edu
Hey everyone,

I am currently trying to set up a Convolutional Neural Network using Keras, but I keep getting an error on one of the dense layers saying "OverflowError: Range exceeds valid bounds". I am not sure what I am doing wrong here because it seems like it should be working based upon other models that I have seen.

IMAGE_HEIGHT = 6
IMAGE_WIDTH = 200
NUM_PEOPLE = 18

def gen_model():
   
"""
    Generates the model to be used
    :return: the model, untrained
    """
    model = Sequential()
   

    model.add(Convolution2D(5, 5, 5, input_shape=(1, IMAGE_HEIGHT, IMAGE_WIDTH)))
    model
.add(AveragePooling2D(pool_size=(2, 2)))
    model
.add(Convolution2D(5, 5, 5))
    model
.add(AveragePooling2D(pool_size=(2, 2)))
    model
.add(Flatten())
    model
.add(Dense(output_dim=20))
    model
.add(Activation('relu'))
    model
.add(Dense(output_dim=18))
    model
.add(Activation('softmax'))
    model
.compile(optimizer="adagrad", loss="categorical_crossentropy", metrics=['accuracy'])
   
return model

Is there something that I could do to improve upon my code and resolve this issue?

Matias Valdenegro

unread,
May 10, 2016, 3:55:12 AM5/10/16
to keras...@googlegroups.com
Given the input image height and kind of downsampling (by convolution and
average pooling) that you are using, eventually the feature maps will have a
height equal to zero, which will trigger this error.

vigneshwer dhinakaran

unread,
May 11, 2016, 8:57:45 AM5/11/16
to Keras-users
PFB the simillar error which I had got while executing the fit command of my model,

Traceback (most recent call last):
  File "model_sample_data_test_lfw_testing.py", line 138, in <module>
    model.add(LocallyConnected2D(nb_filter[4], nb_row[4], nb_col[4],border_mode=border_mode, init=weight_init))
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.0.2-py2.7.egg/keras/models.py", line 146, in add
    output_tensor = layer(self.outputs[0])
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.0.2-py2.7.egg/keras/engine/topology.py", line 458, in __call__
    self.build(input_shapes[0])
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.0.2-py2.7.egg/keras/layers/local.py", line 303, in build
    self.W = self.init(self.W_shape, name='{}_W'.format(self.name))
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.0.2-py2.7.egg/keras/initializations.py", line 73, in he_uniform
    return uniform(shape, s, name=name)
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.0.2-py2.7.egg/keras/initializations.py", line 30, in uniform
    return K.variable(np.random.uniform(low=-scale, high=scale, size=shape),
  File "mtrand.pyx", line 1565, in mtrand.RandomState.uniform (numpy/random/mtrand/mtrand.c:17303)
OverflowError: Range exceeds valid bounds

I had a got a simillar error, which I solved by increasing the size of my image.

Is this the correct way to proceed to with this error? 

According to my calculations the feature maps do not reduce to 0 in my model architecture. Are their any contraints associated with this ?  

Matias Valdenegro

unread,
May 11, 2016, 9:17:04 AM5/11/16
to keras...@googlegroups.com
This is not a similar error, it happens inside some custom layer
(LocallyConnected2D) that is not part of Keras, make sure that custom layer
works correctly, seems that the shapes are not computed correctly.
> > On Monday, 9 May 2016 16:16:45 BST chris....@gmail.com <javascript:>
Message has been deleted

acharya...@gmail.com

unread,
Aug 11, 2017, 11:23:30 AM8/11/17
to Keras-users, cha...@fordham.edu, jst...@fordham.edu, ajohn...@fordham.edu
Solutions/suggestions has been provided in https://github.com/fchollet/keras/issues/2558
Mentioning the link here if someone else is also looking for solution.

In my case: Passing dim_ordering="th" in Convolution2D worked which represents channel dimension=1 (for gray scale image)
Reply all
Reply to author
Forward
0 new messages