def alexnet(pretrained=True, **kwargs): cust_nc = None if pretrained and 'nc' in kwargs: cust_nc = kwargs['nc']; kwargs['nc'] = 1000 net = Alexnet(**kwargs) if pretrained: return load_pretrained(net, urls.alexnet_url, 'alexnet', nc=cust_nc, attr='net[21]', inn=4096) return net
def alexnet_mnist(pretrained=True, **kwargs): cust_nc = kwargs['nc'] if 'nc' in kwargs else None kwargs['ic'] = 1; kwargs['nc'] = 10 net = Alexnet(**kwargs) if pretrained: return load_pretrained(net, urls.alexnet_mnist_url, 'alexnet_mnist', nc=cust_nc, attr='net[21]', inn=4096) return net
def resnet34(pretrained=True, **kwargs): kwargs['layers'] = [3, 4, 6, 3] cust_nc = None if pretrained and 'nc' in kwargs: cust_nc = kwargs['nc']; kwargs['nc'] = 1000 net = Resnet(**kwargs) if pretrained: return load_pretrained(net, urls.resnet34_url, 'resnet34', nc=cust_nc) return net
def resnet18(pretrained=True, **kwargs): kwargs['layers'] = [2, 2, 2, 2] cust_nc = None if pretrained and 'nc' in kwargs: cust_nc = kwargs['nc']; kwargs['nc'] = 1000 net = Resnet(**kwargs) if pretrained: # TODO check inspect module and change the fname return load_pretrained(net, urls.resnet18_url, 'resnet18', nc=cust_nc) return net
def resnet152(pretrained=True, **kwargs): kwargs['layers'] = [3, 8, 36, 3] kwargs['btype'] = 'bottleneck' kwargs['ex'] = 4; kwargs['fdown'] = True cust_nc = None if pretrained and 'nc' in kwargs: cust_nc = kwargs['nc']; kwargs['nc'] = 1000 net = Resnet(**kwargs) if pretrained: return load_pretrained(net, urls.resnet152_url, 'resnet152', nc=cust_nc, inn=512*kwargs['ex']) return net
def alexnet(pretrained=True, **kwargs): cust_nc = None if pretrained and 'nc' in kwargs: cust_nc = kwargs['nc'] kwargs['nc'] = 1000 net = Alexnet(**kwargs) if pretrained: return load_pretrained(net, urls.alexnet_url, 'alexnet', nc=cust_nc, attr='classifier', inn=9216) return net
def get_net(net, pretrained=True, pretrain_url=None, fname=None, kwargs_net=None, **kwargs_load_pretrained): """ Function to load a model and do some required cutting and splitting on it. Arguments --------- net : scratchai.nets.* The class which to initialize, *not an initialized net.* pretrained : bool Whether to load a pretrained net or not. pretrain_url : str The url from which to load a pretrained model. It should be just the file id, if the file is hosted on Google Drive. fname : str The file name with which to store the pretrained file. kwargs_net : dict The extra parameters which are passed while initializing the net kwargs_load_pretrained : dict The extra parameters passed to load_pretrained. """ cust_nc = kwargs_net['nc'] if 'nc' in kwargs_net else None if pretrained and cust_nc is not None: kwargs_net.pop('nc') net = net(**kwargs_net) if pretrained: return load_pretrained(net, pretrain_url, fname, nc=cust_nc, **kwargs_load_pretrained) return net