示例#1
0
    def __init__(
            self,
            args_flow,
            model_name="FlowNet2C",
            restore_path="flow_inference/models/FlowNet2-C_checkpoint.pth.tar",
            train_flow=False,
            resume=None):
        super(Inference_flow, self).__init__()
        args_flow.rgb_max = 255.0
        args_flow.fp16 = False
        args_flow.grads = {}

        if model_name == 'FlowNet2':
            self.model = models.FlowNet2(args_flow).cuda()
        elif model_name == 'FlowNet2C':
            self.model = models.FlowNet2C(args_flow).cuda()
        elif model_name == 'FlowNet2S':
            self.model = models.FlowNet2S(args_flow).cuda()
        elif model_name == 'FlowNet2SD':
            self.model = models.FlowNet2SD(args_flow).cuda()
        elif model_name == 'FlowNet2CS':
            self.model = models.FlowNet2CS(args_flow).cuda()
        elif model_name == 'FlowNet2CSS':
            self.model = models.FlowNet2CSS(args_flow).cuda()
        else:
            assert False, "No such model %s" % (model_name)
        print("loading %s pretrained model..." % (model_name))
        if train_flow:
            self.model.train()
        else:
            self.model.eval()
        if resume is not None:
            self.model.load_state_dict(torch.load(resume)['flow'])
        else:
            self.model.load_state_dict(torch.load(restore_path)['state_dict'])
示例#2
0
    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(
        state,
        os.path.join(args.flownet2_pytorch, 'FlowNet2_checkpoint.pth.tar'))

elif 'FlowNet2-C/' in args.caffe_model:
    model = models.FlowNet2C(args)

    parse_flownetc(model.modules(), weights, biases)
    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(
        state,
        os.path.join(args.flownet2_pytorch, 'FlowNet2-C_checkpoint.pth.tar'))

elif 'FlowNet2-CS/' in args.caffe_model:
    model = models.FlowNet2CS(args)

    parse_flownetc(model.flownetc.modules(), weights, biases)
    parse_flownets(model.flownets_1.modules(),
                   weights,
                   biases,
                   param_prefix='net2_')

    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(
        state,
        os.path.join(args.flownet2_pytorch, 'FlowNet2-CS_checkpoint.pth.tar'))

elif 'FlowNet2-CSS/' in args.caffe_model:
    model = models.FlowNet2CSS(args)
示例#3
0
                        param_prefix='fuse_')

    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(state,
               os.path.join(opt.weights_path, 'FlowNet2_checkpoint.pth.tar'))

elif 'FlowNet2-C/' in opt.caffe_model:
    model = models.FlowNet2C(opt)

    parse_flownetc(model.modules(), weights, biases)
    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(state,
               os.path.join(opt.weights_path, 'FlowNet2-C_checkpoint.pth.tar'))

elif 'FlowNet2-CS/' in opt.caffe_model:
    model = models.FlowNet2CS(opt)

    parse_flownetc(model.flownetc.modules(), weights, biases)
    parse_flownets(model.flownets_1.modules(),
                   weights,
                   biases,
                   param_prefix='net2_')

    state = {'epoch': 0, 'state_dict': model.state_dict(), 'best_EPE': 1e10}
    torch.save(
        state, os.path.join(opt.weights_path,
                            'FlowNet2-CS_checkpoint.pth.tar'))

elif 'FlowNet2-CSS/' in opt.caffe_model:
    model = models.FlowNet2CSS(opt)