A less Lua way of doing that would be to check if some module is an instance of a class. This is the recommended way:
def weights_init(m):
if isinstance(m, nn.Conv2d):
xavier(m.weight.data)
xavier(m.bias.data)
@Atcold another thing, accessing members prefixed with underscore is not recommended. They’re internal and subject to change without notice. If you want to get a iterator over modules use .modules()
(searches recusrively) or .children()
(only one level).