简体   繁体   中英

lasagne.layers.DenseLayer: "__init__() takes at least 3 arguments"

I'm using Lasagne+Theano to create a ResNet and am struggling with the use of DenseLayer. If i use the example on http://lasagne.readthedocs.io/en/latest/modules/layers/dense.html it works.

l_in = InputLayer((100, 20))
l1 = DenseLayer(l_in, num_units=50)

But if I want to use it in my project:

#other layers

resnet['res5c_branch2c'] = ConvLayer(resnet['res5c_branch2b'], num_filters=2048, filter_size=1, pad=0, flip_filters=False)
resnet['pool5'] = PoolLayer(resnet['res5c'], pool_size=7, stride=1, mode='average_exc_pad', ignore_border=False)
resnet['fc1000'] = DenseLayer(resnet['pool5'], num_filter=1000)

Traceback (most recent call last):File "convert_resnet_101_caffe.py", line 167, in <module>
resnet['fc1000'] = DenseLayer(resnet['pool5'], num_filter=1000)TypeError: __init__() takes at least 3 arguments (2 given)

DenseLayer takes two positional arguments: incoming, num_units . You are instantiating it like this:

DenseLayer(resnet['pool5'], num_filter=1000)

Note that this is different than the example code:

DenseLayer(l_in, num_units=50)

Since you are passing a keyword argument that is not num_units as the second argument, I think num_filter is being interpreted as one of the **kwargs , and DenseLayer is still wanting that num_units` argument, and raising an error since you don't provide it.

You can either provide a num_units argument before num_filter , or if that was just a typo, change num_filter to num_units . (The second option seems more likely to me since, although I am not familiar with the library that you are using, I do not see any reference to num_filter in the documentation you linked, although some classes seem to take a num_filters - note the trailing s - argument.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM