コード例 #1
0
    def __init__(self, opt):
        BaseModel.__init__(self, opt)  # call the initialization method of BaseModel

        # specify the images you want to save and display. The program will call base_model.get_current_visuals to save and display these images.
        self.visual_names = []

        # specify the models you want to save to the disk. The program will call base_model.save_networks and base_model.load_networks to save and load networks.
        # you can use opt.isTrain to specify different behaviors for training and test. For example, some networks will not be used during test, and you don't need to load them.
        # define networks; you can use opt.isTrain to specify different behaviors for training and test.
        self.net_names = ["main"]
        self.net_main = create_net(opt)

        self.loss_criterion = create_loss(opt)

        self.init_optimizers(opt)

        self.loss_names = getattr(self.loss_criterion, "loss_names")

        """
        unfreeze shared_cnn_layers, shared_fc_layers and other_layers,
            calculate other loss
            not backward
        """

        self.plus_other_loss = True
        self.need_backward = False
        self.max_step = 1
コード例 #2
0
 def loss(self):
     losses = {}
     loss_weights = {}
     for i, (loss, data) in enumerate(self.losses.items()):
         losses.update(
             {loss: create_loss(data["func"], **data.get("kwargs", {}))})
         loss_weights.update({loss: data.get("weight", 1)})
     return losses, loss_weights
コード例 #3
0
class JointTrainModel(BaseModel):

    @staticmethod
    def modify_commandline_options(parser):
        """Add new dataset-specific options, and rewrite default values for existing options.

        num_classes is the number of classes  per task
        for example, num_classes = [10,10,10], means the number of classes on taks1 is 10, and then so on.

        Parameters:
            parser          -- original option parser


        Returns:
            the modified parser.

        """
		parser.add_argument('--net_name', type=str, default="alexnet", choices=["alexnet", "imagenet"],
							help='network select from alexnet|imagenet', )
		parser.add_argument('--loss_name', type=str, default="total", choices=["total"],
							help='loss select from total', )
		parser.add_argument('--taskdataset_name', type=str, default="total", choices=["total"],
							help='loss from total', )

		return parser

	@staticmethod
	def default_value(opt):
		return opt

	def __init__(self, opt):
		BaseModel.__init__(self, opt)  # call the initialization method of BaseModel

		# specify the images you want to save and display. The program will call base_model.get_current_visuals to save and display these images.
		self.visual_names = []

		# specify the models you want to save to the disk. The program will call base_model.save_networks and base_model.load_networks to save and load networks.
		# you can use opt.isTrain to specify different behaviors for training and test. For example, some networks will not be used during test, and you don't need to load them.
		# define networks; you can use opt.isTrain to specify different behaviors for training and test.
        self.net_names = ["main"]
        self.net_main = create_net(opt)

        self.loss_criterion = create_loss(opt)

		self.init_optimizers(opt)
		self.loss_names = getattr(self.loss_criterion, "loss_names")

		"""
		unfreeze shared_cnn_layers, shared_fc_layers and other_layers,
			calculate other loss
			not backward
		"""

		self.plus_other_loss = False

		self.need_backward = False

		self.max_step = self.nb_tasks
コード例 #4
0
    if args.arch == 'ssd300':
        config = cfg['SSD300']
    else:
        config = cfg['SSD512']

    default_boxes = generate_default_boxes(config)

    dataloader, info = create_dataloader(args.data_dir, args.batch_size,
                                         config['image_size'], default_boxes,
                                         args.augmentation, args.num_examples)

    ssd = create_ssd(NUM_CLASSES, args.arch, 'base', args.pretrained_path)
    ssd.to(device)

    criterion = create_loss(args.neg_ratio, NUM_CLASSES)

    optimizer = optim.SGD(ssd.parameters(),
                          lr=args.lr,
                          momentum=args.momentum,
                          weight_decay=args.weight_decay)
    scheduler = optim.lr_scheduler.MultiStepLR(
        optimizer,
        milestones=[int(args.num_epochs * 0.65),
                    int(args.num_epochs * 0.8)],
        gamma=0.1,
        last_epoch=-1)

    for epoch in range(args.num_epochs):
        scheduler.step()
        avg_loss = 0.0