devendrachaplot / Neural-SLAM

Pytorch code for ICLR-20 Paper "Learning to Explore using Active Neural SLAM"
http://www.cs.cmu.edu/~dchaplot/projects/neural-slam.html
MIT License
761 stars 144 forks source link

Code questions #7

Closed rainbow979 closed 4 years ago

rainbow979 commented 4 years ago

What does this code(filter(bool, [])) mean? `self.conv = nn.Sequential(filter(bool, [ nn.Conv2d(512, 64, (1, 1), stride=(1, 1)), nn.ReLU() ]))` https://github.com/devendrachaplot/Neural-SLAM/blob/master/model.py#L80

devendrachaplot commented 4 years ago

(*filter(bool, [x])) removes None layers in x. For example, if the block was the following:

self.conv = nn.Sequential(*filter(bool, [
            nn.Conv2d(512, 64, (1, 1), stride=(1, 1)),
            nn.ReLU() if args.use_relu else None,
        ]))

Here, I believe the filter would remove None layers if args.use_relu was False.

It is redundant in the referred line, you can ignore it.