'last_branch': 1, 'last_down': True, 'last_expand': 0, 'poolmode': 'avg', 'active': 'relu', 'summer': 'split', 'nclass': 10, 'afisok': False, 'afkeys': ('af1', 'af2'), 'convon': True, 'convlayers': 1, 'convdepth': 4} wv2s = {'stages': 2, 'rock': 'Q', 'branch': 3, 'indepth': 24, 'growth': 12, 'multiway': 4, 'layers': (3, 3, 0), 'blocks': ('D', 'D', '-'), 'bottle': (3, 3, 3), 'classify': (0, 0, 0), 'trans': ('A', 'A', '-'), 'reduction': (0.5, 0, 0), 'last_branch': 1, 'last_down': True, 'last_expand': 0, 'poolmode': 'avg', 'active': 'relu', 'summer': 'split', 'nclass': 10, 'afisok': False, 'afkeys': ('af1', 'af2'), 'convon': True, 'convlayers': 1, 'convdepth': 4} wv3s = {'stages': 3, 'rock': 'Q', 'branch': 3, 'indepth': 24, 'growth': 12, 'multiway': 4, 'layers': (10, 10, 10), 'blocks': ('D', 'D', 'S'), 'bottle': (0, 0, 0), 'classify': (0, 0, 0), 'trans': ('A', 'A', 'A'), 'reduction': (0.5, 0.5, 0), 'last_branch': 1, 'last_down': False, 'last_expand': 10, 'poolmode': 'avg', 'active': 'relu', 'summer': 'split', 'nclass': 10, 'afisok': False, 'afkeys': ('af1', 'af2', 'af3'), 'convon': True, 'convlayers': 1, 'convdepth': 4} model = WaveNet(**wv3s) print('\n', model, '\n') out = model(torch.randn(4, 3, 32, 32)) # utils.tensorboard_add_model(model, x) xtils.calculate_params_scale(model, format='million') xtils.calculate_FLOPs_scale(model, input_size=32, use_gpu=False, multiply_adds=False) xtils.calculate_layers_num(model, layers=('conv2d', 'deconv2d', 'fc')) xtils.calculate_time_cost(model, insize=32, toc=3, use_gpu=False)
model = MultiScaleNet(**ms6) print(model) model.set_train_which(part=['bone+mhead', 'auxhead', 'summary'][2], name_which='head-8-2-2@6') # model.set_eval_which(part=['bone+mhead', 'bone+mhead+auxhead', 'bone+mhead+auxhead+summary'][1]) # paramsx = [p for p in model.parameters() if p.requires_grad] # # model.set_train_which(part=['bone+mhead', 'auxhead', 'summary'][0]) # paramsy = [p for p in model.parameters() if p.requires_grad] # # share = list(set(paramsx).intersection(set(paramsy))) insize = [32, 224][model.dataset == 'imagenet'] x = torch.randn(1, 3, insize, insize) z = model(x) print('z-->', len(z), '\n') xtils.calculate_layers_num(model) xtils.calculate_FLOPs_scale(model, input_size=insize, use_gpu=False, multiply_adds=False) xtils.calculate_params_scale(model, format='million') xtils.calculate_time_cost(model, insize=insize, toc=1, pritout=True, use_gpu=False)
# def test(): # net = MobileNetV3_Small() # x = torch.randn(2, 3, 224, 224) # y = net(x) # print(y.size()) # test() if __name__ == '__main__': import xtils, os model = [MobileNetV3_Large(), MobileNetV3_Small()][0] print('\n', model, '\n') ckpt = ['mobilev3_x_large.pth.tar', 'mobilev3_x_small.pth.tar'][0] ckpt = os.path.join('/data/zhangjp/PreTrainedModels', ckpt) model = xtils.load_ckpt_weights(model, ckptf=ckpt, device='cpu', mgpus_to_sxpu='m2s') # utils.tensorboard_add_model(model, x) xtils.calculate_params_scale(model, format='million') xtils.calculate_FLOPs_scale(model, use_gpu=False, input_size=224, multiply_adds=True) xtils.calculate_layers_num(model, layers=('conv2d', 'deconv2d', 'fc')) xtils.calculate_time_cost(model, insize=224, use_gpu=False)
import xtils, time, random seed = [2019, time.time()][0] random.seed(seed) torch.manual_seed(seed) # # # ImageNet model = XResNet(**xresnet_imgnet) print(model) xtils.calculate_layers_num(model, layers=('conv2d', 'deconv2d', 'classifier')) xtils.calculate_FLOPs_scale(model, input_size=224, multiply_adds=True, use_gpu=False) xtils.calculate_params_scale(model, format='million') xtils.calculate_time_cost(model, insize=224, toc=1, use_gpu=False, pritout=True) # CIFAR10 & CIFAR100 # # model = XResNet(**xresnet_cifar100) # print(model) # utils.calculate_layers_num(model, layers=('conv2d', 'classifier')) # utils.calculate_FLOPs_scale(model, input_size=32, multiply_adds=True, use_gpu=False) # utils.calculate_params_scale(model, format='million') # utils.calculate_time_cost(model, insize=32, toc=3, use_gpu=False, pritout=True)