def get_model(): if model_index == 0: return mobilenet_v1.MobileNetV1() elif model_index == 1: return mobilenet_v2.MobileNetV2() elif model_index == 2: return mobilenet_v3_large.MobileNetV3Large() elif model_index == 3: return mobilenet_v3_small.MobileNetV3Small() elif model_index == 4: return efficientnet.efficient_net_b0() elif model_index == 5: return efficientnet.efficient_net_b1() elif model_index == 6: return efficientnet.efficient_net_b2() elif model_index == 7: return efficientnet.efficient_net_b3() elif model_index == 8: return efficientnet.efficient_net_b4() elif model_index == 9: return efficientnet.efficient_net_b5() elif model_index == 10: return efficientnet.efficient_net_b6() elif model_index == 11: return efficientnet.efficient_net_b7() elif model_index == 12: return resnext.ResNeXt50() elif model_index == 13: return resnext.ResNeXt101() elif model_index == 14: return inception_v4.InceptionV4() elif model_index == 15: return inception_resnet_v1.InceptionResNetV1() elif model_index == 16: return inception_resnet_v2.InceptionResNetV2()
def get_model(): if model_index == 0: return mobilenet_v1.MobileNetV1() elif model_index == 1: return mobilenet_v2.MobileNetV2() elif model_index == 2: return mobilenet_v3_large.MobileNetV3Large() elif model_index == 3: return mobilenet_v3_small.MobileNetV3Small() elif model_index == 4: return efficientnet.efficient_net_b0() elif model_index == 5: return efficientnet.efficient_net_b1() elif model_index == 6: return efficientnet.efficient_net_b2() elif model_index == 7: return efficientnet.efficient_net_b3() elif model_index == 8: return efficientnet.efficient_net_b4() elif model_index == 9: return efficientnet.efficient_net_b5() elif model_index == 10: return efficientnet.efficient_net_b6() elif model_index == 11: return efficientnet.efficient_net_b7() elif model_index == 12: return resnext.ResNeXt50() elif model_index == 13: return resnext.ResNeXt101() elif model_index == 14: return inception_v4.InceptionV4() elif model_index == 15: return inception_resnet_v1.InceptionResNetV1() elif model_index == 16: return inception_resnet_v2.InceptionResNetV2() elif model_index == 17: return se_resnet.se_resnet_50() elif model_index == 18: return se_resnet.se_resnet_101() elif model_index == 19: return se_resnet.se_resnet_152() elif model_index == 20: return squeezenet.SqueezeNet() elif model_index == 21: return densenet.densenet_121() elif model_index == 22: return densenet.densenet_169() elif model_index == 23: return densenet.densenet_201() elif model_index == 24: return densenet.densenet_264() elif model_index == 25: return shufflenet_v2.shufflenet_0_5x() elif model_index == 26: return shufflenet_v2.shufflenet_1_0x() elif model_index == 27: return shufflenet_v2.shufflenet_1_5x() elif model_index == 28: return shufflenet_v2.shufflenet_2_0x()
def get_model(n_class): print('=> Building model {}...'.format(args.model)) if args.model == 'mobilenet_0.5flops': net = mobilenet_v1.MobileNet(n_class, profile='0.5flops') checkpoint_path = './checkpoints/torch/mobilenet_imagenet_0.5flops_70.5.pth.tar' elif args.model == 'mobilenet_0.5time': net = mobilenet_v1.MobileNet(n_class, profile='0.5time') checkpoint_path = './checkpoints/torch/mobilenet_imagenet_0.5time_70.2.pth.tar' elif args.model == 'mobilenetv2': net = mobilenet_v2.MobileNetV2(n_class, profile='normal') checkpoint_path = './checkpoints/torch/mobilenetv2_imagenet_71.814.pth.tar' elif args.model == 'mobilenetv2_0.7flops': net = mobilenet_v2.MobileNetV2(n_class, profile='0.7flops') checkpoint_path = './checkpoints/torch/mobilenetv2_imagenet_0.7amc_70.854.pth.tar' else: raise NotImplementedError print('=> Loading checkpoints..') checkpoint = torch.load(checkpoint_path) if 'state_dict' in checkpoint: checkpoint = checkpoint['state_dict'] # get state_dict net.load_state_dict(process_state_dict(checkpoint)) # remove .module return net
import context import tensorflow as tf from models import mobilenet_v2 physical_devices = tf.config.experimental.list_physical_devices('GPU') for physical_device in physical_devices: tf.config.experimental.set_memory_growth(physical_device, True) model = mobilenet_v2.MobileNetV2([320, 320, 3], 81, 'ssd_mobilenet_v2') model.summary() x = tf.random.normal((1, 320, 320, 3)) outs = model(x) for o in outs: print(o.shape)
def get_model(): if model_index == 0: return mobilenet_v1.MobileNetV1() elif model_index == 1: return mobilenet_v2.MobileNetV2() elif model_index == 2: return mobilenet_v3_large.MobileNetV3Large() elif model_index == 3: return mobilenet_v3_small.MobileNetV3Small() elif model_index == 4: return efficientnet.efficient_net_b0() elif model_index == 5: return efficientnet.efficient_net_b1() elif model_index == 6: return efficientnet.efficient_net_b2() elif model_index == 7: return efficientnet.efficient_net_b3() elif model_index == 8: return efficientnet.efficient_net_b4() elif model_index == 9: return efficientnet.efficient_net_b5() elif model_index == 10: return efficientnet.efficient_net_b6() elif model_index == 11: return efficientnet.efficient_net_b7() elif model_index == 12: return resnext.ResNeXt50() elif model_index == 13: return resnext.ResNeXt101() elif model_index == 14: return inception_v4.InceptionV4() elif model_index == 15: return inception_resnet_v1.InceptionResNetV1() elif model_index == 16: return inception_resnet_v2.InceptionResNetV2() elif model_index == 17: return se_resnet.se_resnet_50() elif model_index == 18: return se_resnet.se_resnet_101() elif model_index == 19: return se_resnet.se_resnet_152() elif model_index == 20: return squeezenet.SqueezeNet() elif model_index == 21: return densenet.densenet_121() elif model_index == 22: return densenet.densenet_169() elif model_index == 23: return densenet.densenet_201() elif model_index == 24: return densenet.densenet_264() elif model_index == 25: return shufflenet_v2.shufflenet_0_5x() elif model_index == 26: return shufflenet_v2.shufflenet_1_0x() elif model_index == 27: return shufflenet_v2.shufflenet_1_5x() elif model_index == 28: return shufflenet_v2.shufflenet_2_0x() elif model_index == 29: return resnet.resnet_18() elif model_index == 30: return resnet.resnet_34() elif model_index == 31: return resnet.resnet_50() elif model_index == 32: return resnet.resnet_101() elif model_index == 33: return resnet.resnet_152() elif model_index == 34: return vgg16.VGG16() elif model_index == 35: return vgg16_mini.VGG16() elif model_index == 36: return VGG16_self.VGG16() elif model_index == 10086: return diy_resnet.resnet_50() else: raise ValueError("The model_index does not exist.")