广告图模板廊坊seo网络推广
在学基础的时候没学到过(可能见过但是又忘了),在学习深度学习项目的时候遇见了很多;
以论文Multi-label learning from single positive label
为例;
这些方法都是程序自行调用的,不需要(也不可以)手动调用,比如不可以写model.__init__()
;
init()
前后都有两个下划线_
;
class FCNet(torch.nn.Module):def __init__(self, num_feats, num_classes):super(FCNet, self).__init__()self.fc = torch.nn.Linear(num_feats, num_classes)def forward(self, x):x = self.fc(x)return x
这个比较简单,实在实例化的时候给对象赋初始值的;
getitem()
这个是在对象通过[]
运算时会调用的方法;
class FCNet(torch.nn.Module):def __init__(self, num_feats, num_classes):super(FCNet, self).__init__()self.fc = torch.nn.Linear(num_feats, num_classes)def forward(self, x):x = self.fc(x)return xdef __getitem__(self, x):print("hello!")return
(上面的__getitem__没什么含义,只是为了举例子)
在程序中写:
model = FCNet()
model['hh']
看打印出来是什么;