Пример #1
0
logger = logging.getLogger('')
logger.setLevel(logging.INFO)
logger.addHandler(filehandler)
logger.addHandler(streamhandler)
logger.info(opt)

# number of GPUs to use
num_gpus = opt.num_gpus
ctx = [mx.gpu(i) for i in range(num_gpus)]
#ctx = [mx.gpu(1)]

# Get the model
net = myget(name=opt.model,
            nclass=opt.num_classes,
            num_segments=opt.num_segments,
            input_channel=opt.input_channel,
            batch_normal=opt.partial_bn,
            use_lateral=opt.use_lateral,
            use_kinetics_pretrain=opt.use_kinetics_pretrain)
net.cast(opt.dtype)
net.collect_params().reset_ctx(ctx)

net1 = myget(name=opt.TranConv_model)
net1.cast(opt.dtype)
net1.collect_params().reset_ctx(ctx)

#logger.info(net)
if opt.resume_params is not '':
    net.load_parameters(opt.resume_params, ctx=ctx)

#if opt.use_pretrained:
Пример #2
0
        self.clip_grad = 40
        self.log_interval = 10
        self.scale_ratios = [1.0, 0.875, 0.75, 0.66]
        self.save_frequency = 5
        self.mode = None#'hybrid'
        self.lr_mode ='step'
        self.accumulate = 1.0

opt = config()
makedirs(opt.save_dir)
# number of GPUs to use
#ctx = [mx.gpu(i) for i in range(opt.num_gpus)]
ctx = [mx.gpu(1)]
#ctx = [mx.cpu()]
# Get the model 
net = myget(name=opt.model, nclass=opt.num_classes, num_segments=opt.num_segments,input_channel=opt.input_channel,partial_bn=opt.partial_bn)
net.cast(opt.dtype)
net.collect_params().reset_ctx(ctx)
#print(net)

if opt.mode == 'hybrid':
    net.hybridize(static_alloc=True, static_shape=True)
    
transform_train = video.VideoGroupTrainTransform(size=(opt.input_size, opt.input_size), scale_ratios=opt.scale_ratios, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
transform_test = video.VideoGroupValTransform(size=opt.input_size, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
# Calculate effective total batch size

#
train_dataset = UCF101(setting=opt.train_setting, root=opt.train_dir, train=True,
                               new_width=opt.new_width, new_height=opt.new_height, new_length= (opt.new_length if opt.new_length==opt.new_length_diff else opt.new_length_diff),
                               target_width=opt.input_size, target_height=opt.input_size,
Пример #3
0
from gluoncv.data.transforms import video
from gluoncv.data import ucf101
from gluoncv.model_zoo import get_model
from gluoncv.utils import makedirs, LRSequential, LRScheduler, split_and_load, TrainingHistory

from model_zoo import get_model as myget

# number of GPUs to use
num_gpus = 1
#ctx = [mx.gpu(i) for i in range(num_gpus)]
ctx = [mx.gpu(1)]
# Get the model
#net = get_model(name='vgg16_ucf101', nclass=101, num_segments=3)
#net = myget(name='simple', nclass=101, num_segments=3)
net = myget('mseloss_vgg16', nclass=101, num_segments=3)

net.collect_params().reset_ctx(ctx)
#print(net)

transform_train = transforms.Compose([
    # Fix the input video frames size as 256×340 and randomly sample the cropping width and height from
    # {256,224,192,168}. After that, resize the cropped regions to 224 × 224.
    video.VideoMultiScaleCrop(size=(224, 224),
                              scale_ratios=[1.0, 0.875, 0.75, 0.66]),
    # Randomly flip the video frames horizontally
    video.VideoRandomHorizontalFlip(),
    # Transpose the video frames from height*width*num_channels to num_channels*height*width
    # and map values from [0, 255] to [0,1]
    video.VideoToTensor(),
    # Normalize the video frames with mean and standard deviation calculated across all images
Пример #4
0
streamhandler = logging.StreamHandler()
logger = logging.getLogger('')
logger.setLevel(logging.INFO)
logger.addHandler(filehandler)
logger.addHandler(streamhandler)
logger.info(opt)

# number of GPUs to use
num_gpus = opt.num_gpus
ctx = [mx.gpu(i) for i in range(num_gpus)]
#ctx = [mx.gpu(1)]

# Get the model
net = myget(name=opt.model,
            nclass=opt.num_classes,
            num_segments=opt.num_segments,
            input_channel=opt.input_channel,
            batch_normal=opt.partial_bn,
            pretrained_base=opt.pretrained_base)
net.cast(opt.dtype)
net.collect_params().reset_ctx(ctx)
#logger.info(net)
if opt.resume_params is not '':
    net.load_parameters(opt.resume_params, ctx=ctx)

transform_train = video.VideoGroupTrainTransform(
    size=(opt.input_size, opt.input_size),
    scale_ratios=[1.0, 0.875, 0.75, 0.66],
    mean=[0.485, 0.456, 0.406],
    std=[0.229, 0.224, 0.225])
transform_test = video.VideoGroupValTransform(size=opt.input_size,
                                              mean=[0.485, 0.456, 0.406],
Пример #5
0
logger = logging.getLogger('')
logger.setLevel(logging.INFO)
logger.addHandler(filehandler)
logger.addHandler(streamhandler)
logger.info(opt)

# number of GPUs to use
num_gpus = opt.num_gpus
ctx = [mx.gpu(i) for i in range(num_gpus)]
#ctx = [mx.gpu(1)]

# Get the model
#net = get_dualnet(fgs_model=opt.fgsmodel,bgs_model=opt.bgsmodel,fgs_path=opt.fgs_params,bgs_path=opt.bgs_params, nclass=opt.num_classes, num_segments=opt.num_segments,input_channel=opt.input_channel,fusion_method=opt.fusion_method)
net_bgs = myget(name=opt.bgsmodel,
                nclass=opt.num_classes,
                num_segments=opt.num_segments,
                input_channel=opt.input_channel,
                batch_normal=opt.partial_bn)
net_fgs = myget(name=opt.fgsmodel,
                nclass=opt.num_classes,
                num_segments=opt.num_segments,
                input_channel=opt.input_channel,
                batch_normal=opt.partial_bn)
net_bgs.cast(opt.dtype)
net_bgs.collect_params().reset_ctx(ctx)
net_fgs.cast(opt.dtype)
net_fgs.collect_params().reset_ctx(ctx)
#logger.info(net)
if opt.bgs_params is not '':
    net_bgs.load_parameters(opt.bgs_params, ctx=ctx)
if opt.fgs_params is not '':