Is there a way to iterate over all modules of a model, let’s call it Generator, and equip all Conv2d- and ConvTranspose2d-layers with spectral normalization?
Sorry, if this has been discussed already, I couldn’t find it though…
Is that a valid solution? How can you check if Conv-layer is equiped with spectral norm?
# Make all layers to be spectral normalization layer
def add_sn(m):
if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d)):
return spectral_norm(m)
else:
return m
Generator.apply(add_sn)