Beispiel #1
0
def create_model_cifar(args, num_classes):
    """
    creates a deep neural network for cifar data
    :param args: args
    :type args:
    :param num_classes:
    :type num_classes:
    :return:
    :rtype:
    """
    # Create Model
    if args.model == "resnet":
        from .resnet import ResNet
        model = ResNet(num_classes=num_classes,
                       depth=args.depth,
                       norm_type=args.norm,
                       basicblock=args.basicblock,
                       norm_power=args.norm_power)
    elif args.model == "vgg":
        from models.vgg import vgg

        model = vgg(args.depth,
                    norm_type=args.norm,
                    num_classes=num_classes,
                    norm_power=args.norm_power)
    else:
        print("Model name is wrong")
        model = None

    return model
Beispiel #2
0
def build_ssd(mode, new_size, anchors, class_count):

    base = vgg(config=base_config[str(new_size)], in_channels=3)
    extras = get_extras(config=extras_config[str(new_size)], in_channels=1024)

    head = multibox(config=mbox_config[str(new_size)],
                    base=base,
                    extra_layers=extras,
                    class_count=class_count)

    return SSD(mode, base, extras, head, anchors, class_count)
Beispiel #3
0
def Model_Construct(args, process_name):
    if args.arch.find('vgg') == 0:  ## the required model is vgg structure
        if process_name == 'image_classifier' or process_name == 'part_classifiers':
            model = vgg(args)
            return model
        elif process_name == 'partnet' or process_name == 'download_proposals':
            model = partnet_vgg(args)
            return model
        else:
            raise ValueError('the required process name is not exist')
    elif args.arch.find('resnet') == 0:
        raise ValueError('the resnet structure is not well finished')
    else:
        raise ValueError('the request model is not exist')
Beispiel #4
0
    def define_model(self):
        if self.model_type == 'vgg':
            if self.model_cfg:
                model = vgg(**self.model_cfg,
                            cfg='A',
                            progress=True,
                            num_classes=10)
            else:
                model = vgg(cfg='A',
                            batch_norm=False,
                            pretrained=True,
                            progress=True,
                            num_classes=10)

        elif self.model_type == 'five_conv':
            self.model_cfg.pop('pretrained')
            if self.model_cfg:
                model = five_conv(**self.model_cfg, cfg='A')
            else:
                model = five_conv(cfg='A', batch_norm=False)

        else:
            self.model_cfg.pop('pretrained')
            if self.model_cfg:
                model = two_conv(**self.model_cfg, cfg='A')
            else:
                model = two_conv(cfg='A', batch_norm=False)

        if self.augment:
            model.model_name += '_augment'
        if self.scale:
            model.model_name += '_scale'
        if self.standardize:
            model.model_name += '_standardize'

        return model.to(self.device)
Beispiel #5
0
    # model = resnet(input_shape=input_shape,num_classes=num_classes)
    model = resnet_v2(input_shape=input_shape,
                      depth=resnet_depth,
                      num_classes=num_classes)
if model_name == 'densenet':
    print(model_name)
    model = densenet.DenseNet(nb_classes=num_classes,
                              img_dim=input_shape,
                              depth=40,
                              nb_dense_block=3,
                              growth_rate=12,
                              nb_filter=16,
                              dropout_rate=0,
                              weight_decay=1e-4)
if model_name == 'vgg':
    model = vgg(input_shape=input_shape, num_classes=num_classes)
if model_name == 'wrn':
    model = create_wide_residual_network(input_dim=input_shape,
                                         nb_classes=num_classes,
                                         N=2,
                                         k=8)

if optimizer == 'Adam':
    opt = Adam(lr=init_lr)
elif optimizer == 'SGD':
    opt = SGD(lr=init_lr, momentum=0.9)
elif optimizer == 'RMSprop':
    opt = RMSprop(lr=init_lr)
elif optimizer == 'Adagrad':
    opt = Adagrad(lr=init_lr)
import torch
import time
import numpy as np
from models.efficientnet import efficientnet
from models.vgg import vgg
import torch.nn as nn
from models.resnet import resnet


vgg16 = vgg(False, 'vgg16', 1000, False)
vgg16.classifier = nn.Sequential(*list(vgg16.classifier.children())[:-1])
resnet50 = resnet(False, 'resnet50', 1000, False)
resnet50 = nn.Sequential(*list(resnet50.children())[:-1])
resnet101 = resnet(False, 'resnet101', 1000, False)
resnet101 = nn.Sequential(*list(resnet101.children())[:-1])

models = {
    'efficientnetb0': efficientnet(False, 'b0', 1000, False, 1280),
    'efficientnetb1': efficientnet(False, 'b1', 1000, False, 1280),
    'efficientnetb4': efficientnet(False, 'b4', 1000, False, 1280),
    'vgg16': vgg16,
    'resnet50': resnet50,
    'resnet101': resnet101
}

batch_sizes = [1, 10, 25]
patch_sizes = [168, 224]
devices = ['cpu', 'cuda']
for key, model in models.items():
    print('==> model: {}'.format(key))
    for dev in devices: