lucidrains / byol-pytorch

Usable Implementation of "Bootstrap Your Own Latent" self-supervised learning, from Deepmind, in Pytorch
MIT License
1.76k stars 248 forks source link

Singleton Class Members #5

Closed wentaoyuan closed 4 years ago

wentaoyuan commented 4 years ago

Forgive me for my unfamiliarity with software design, but I'm wondering why it is necessary to write a singleton wrapper for projector and target_encoder. Is there any disadvantage of initializing them in __init__?

lucidrains commented 4 years ago

@wentaoyuan Hello! The reason is because at initialization, we don't really know the dimensions of the representation emitted by the designated hidden layer (to be fed into the projection network).

I decide to lazy instantiate it to save users from having to run a torch summary and specify it manually.

wentaoyuan commented 4 years ago

That's brilliant. Thanks!

lucidrains commented 4 years ago

Glad you like it! Go make some neural nets smarter :)