1

I was going through pytorch codebase for face generation using DCGAN and come across this code.

def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv') != -1:
        nn.init.normal_(m.weight.data, 0.0, 0.02)
    elif classname.find('BatchNorm') != -1:
        nn.init.normal_(m.weight.data, 1.0, 0.02)
        nn.init.constant_(m.bias.data, 0)

I don't understand line 2 classname = m.__class__.__name__ and line 3 if classname.find('Conv') != -1: from above method weights_init.

0

1 Answer 1

3

To answer your title question, Python's language reference standard types documentation explains it best.

My class Hero is basically user defined callable type and it has special attribute __name__. These attributes are writable and I can modify it as well.

enter image description here

Python String's .find() method quote from official doc:

Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.

Basically, your sample code is trying to find Conv in the class name and proceed further accordingly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.