Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory used in models vgg #64

Open
ProgRoman opened this issue May 13, 2016 · 3 comments
Open

Memory used in models vgg #64

ProgRoman opened this issue May 13, 2016 · 3 comments

Comments

@ProgRoman
Copy link

For classification problems, I use the model vgg. I have a computer with Debian 6.0.9, 32 bit, RAM 15.8Gb. When I try to load a model vgg19 or vgg16. I receive a memory error

cnn_vgg19 = build_model_vgg19()
output_layer = cnn_vgg19['prob']

MemoryError Traceback (most recent call last)
in ()
----> 1 cnn_vgg19 = build_model_vgg19()
2 output_layer = cnn_vgg19['prob']

in build_model_vgg19()
39 net['conv5_3'], 512, 3, pad=1, flip_filters=False)
40 net['pool5'] = PoolLayer(net['conv5_4'], 2)
---> 41 net['fc6'] = DenseLayer(net['pool5'], num_units=4096)
42 net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5)
43 net['fc7'] = DenseLayer(net['fc6_dropout'], num_units=4096)

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/layers/dense.pyc in init(self, incoming, num_units, W, b, nonlinearity, **kwargs)
69 num_inputs = int(np.prod(self.input_shape[1:]))
70
---> 71 self.W = self.add_param(W, (num_inputs, num_units), name="W")
72 if b is None:
73 self.b = None

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/layers/base.pyc in add_param(self, spec, shape, name, **tags)
212 name = "%s.%s" % (self.name, name)
213 # create shared variable, or pass through given variable/expression
--> 214 param = utils.create_param(spec, shape, name)
215 # parameters should be trainable and regularizable by default
216 tags['trainable'] = tags.get('trainable', True)

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/utils.pyc in create_param(spec, shape, name)
349
350 elif hasattr(spec, 'call'):
--> 351 arr = spec(shape)
352 try:
353 arr = floatX(arr)

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/init.pyc in call(self, shape)
29 their :meth:sample() method.
30 """
---> 31 return self.sample(shape)
32
33 def sample(self, shape):

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/init.pyc in sample(self, shape)
175
176 std = self.gain * np.sqrt(2.0 / ((n1 + n2) * receptive_field_size))
--> 177 return self.initializer(std=std).sample(shape)
178
179

/home/roman/anaconda/lib/python2.7/site-packages/lasagne/init.pyc in sample(self, shape)
98 def sample(self, shape):
99 return floatX(get_rng().uniform(
--> 100 low=self.range[0], high=self.range[1], size=shape))
101
102

mtrand.pyx in mtrand.RandomState.uniform (numpy/random/mtrand/mtrand.c:13575)()

mtrand.pyx in mtrand.cont2_array_sc (numpy/random/mtrand/mtrand.c:2902)()

MemoryError:

There is a second computer RAM 32 Gb 64bit
on this computer is working correctly
i.e. 16 GB RAM is not enough
is it normal?

@f0k
Copy link
Member

f0k commented May 13, 2016

is it normal?

16 GiB would be enough -- but your other machine is 32 bit, so any given process can just address 4 GiB of memory. I'm still a bit surprised you're hitting an error on build_model_vgg19() already, when creating the weight matrix of the first dense layer. Is this the original model with an input layer of 224x224 or did you increase that? Is there anything else in your memory that's large?

@ProgRoman
Copy link
Author

code is exactly the same

def build_model_vgg19():
    net = {}
    net['input'] = InputLayer((None, 3, 224, 224))
    net['conv1_1'] = ConvLayer(
        net['input'], 64, 3, pad=1, flip_filters=False)
    net['conv1_2'] = ConvLayer(
        net['conv1_1'], 64, 3, pad=1, flip_filters=False)
    net['pool1'] = PoolLayer(net['conv1_2'], 2)
    net['conv2_1'] = ConvLayer(
        net['pool1'], 128, 3, pad=1, flip_filters=False)
    net['conv2_2'] = ConvLayer(
        net['conv2_1'], 128, 3, pad=1, flip_filters=False)
    net['pool2'] = PoolLayer(net['conv2_2'], 2)
    net['conv3_1'] = ConvLayer(
        net['pool2'], 256, 3, pad=1, flip_filters=False)
    net['conv3_2'] = ConvLayer(
        net['conv3_1'], 256, 3, pad=1, flip_filters=False)
    net['conv3_3'] = ConvLayer(
        net['conv3_2'], 256, 3, pad=1, flip_filters=False)
    net['conv3_4'] = ConvLayer(
        net['conv3_3'], 256, 3, pad=1, flip_filters=False)
    net['pool3'] = PoolLayer(net['conv3_4'], 2)
    net['conv4_1'] = ConvLayer(
        net['pool3'], 512, 3, pad=1, flip_filters=False)
    net['conv4_2'] = ConvLayer(
        net['conv4_1'], 512, 3, pad=1, flip_filters=False)
    net['conv4_3'] = ConvLayer(
        net['conv4_2'], 512, 3, pad=1, flip_filters=False)
    net['conv4_4'] = ConvLayer(
        net['conv4_3'], 512, 3, pad=1, flip_filters=False)
    net['pool4'] = PoolLayer(net['conv4_4'], 2)
    net['conv5_1'] = ConvLayer(
        net['pool4'], 512, 3, pad=1, flip_filters=False)
    net['conv5_2'] = ConvLayer(
        net['conv5_1'], 512, 3, pad=1, flip_filters=False)
    net['conv5_3'] = ConvLayer(
        net['conv5_2'], 512, 3, pad=1, flip_filters=False)
    net['conv5_4'] = ConvLayer(
        net['conv5_3'], 512, 3, pad=1, flip_filters=False)
    net['pool5'] = PoolLayer(net['conv5_4'], 2)
    net['fc6'] = DenseLayer(net['pool5'], num_units=4096)
    net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5)
    net['fc7'] = DenseLayer(net['fc6_dropout'], num_units=4096)
    net['fc7_dropout'] = DropoutLayer(net['fc7'], p=0.5)
    net['fc8'] = DenseLayer(
        net['fc7_dropout'], num_units=1000, nonlinearity=None)
    net['prob'] = NonlinearityLayer(net['fc8'], softmax)

    return net

@f0k
Copy link
Member

f0k commented May 17, 2016

Still, try to find out where your memory goes. Possibly step through the code in pdb and watch memory usage in top, or use a memory profiler. Maybe you're unintentionally using up a major portion of the 4 GiB your process has available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants