示例#1
0
 def __init__(self):
     self._opt = TrainOptions().parse()
     PRESET_VARS = PATH(self._opt)
     self._model = ModelsFactory.get_by_name(self._opt.model_name,
                                             self._opt)
     train_transforms = self._model.resnet50.backbone.augment_transforms
     val_transforms = self._model.resnet50.backbone.compose_transforms
     self.training_dataloaders = Multitask_DatasetDataLoader(
         self._opt, train_mode='Train', transform=train_transforms)
     self.training_dataloaders = self.training_dataloaders.load_multitask_train_data(
     )
     self.validation_dataloaders = Multitask_DatasetDataLoader(
         self._opt, train_mode='Validation', transform=val_transforms)
     self.validation_dataloaders = self.validation_dataloaders.load_multitask_val_test_data(
     )
     print("Traning Tasks:{}".format(self._opt.tasks))
     actual_bs = self._opt.batch_size * len(self._opt.tasks)
     print("The actual batch size is {}*{}={}".format(
         self._opt.batch_size, len(self._opt.tasks), actual_bs))
     print("Training sets: {} images ({} images per task)".format(
         len(self.training_dataloaders) * actual_bs,
         len(self.training_dataloaders) * self._opt.batch_size))
     print("Validation sets")
     for task in self._opt.tasks:
         data_loader = self.validation_dataloaders[task]
         print("{}: {} images".format(
             task,
             len(data_loader) * self._opt.batch_size *
             len(self._opt.tasks)))
     self.visual_dict = {
         'training': pd.DataFrame(),
         'validation': pd.DataFrame()
     }
     self._train()
 def __init__(self):
     self._opt = TestOptions().parse()
     PRESET_VARS = PATH()
     self._model = ModelsFactory.get_by_name(self._opt.model_name,
                                             self._opt)
     val_transforms = self._model.resnet50_GRU.backbone.backbone.compose_transforms
     self.validation_dataloaders = Multitask_DatasetDataLoader(
         self._opt, train_mode=self._opt.mode, transform=val_transforms)
     self.validation_dataloaders = self.validation_dataloaders.load_multitask_val_test_data(
     )
     print("{} sets".format(self._opt.mode))
     for task in self._opt.tasks:
         data_loader = self.validation_dataloaders[task]
         print("{}: {} images".format(
             task,
             len(data_loader) * self._opt.batch_size *
             len(self._opt.tasks) * self._opt.seq_len))
     if self._opt.mode == 'Validation':
         self._validate()
     else:
         raise ValueError("do not call val.py with test mode.")
import torch
import torch.nn as nn
from collections import OrderedDict
from torch.autograd import Variable
from .models import BaseModel
from .models import ModelsFactory
import os
import numpy as np
import torch.nn.functional as F
from PATH import PATH
PRESET_VARS = PATH()
MODEL_DIR = PRESET_VARS.MODEL_DIR
from copy import deepcopy
from utils.model_utils import AU_Losses, EXPR_Losses, VA_Losses, BackBone, Head, GRU_Head, Seq_Model, Model, AU_metric, EXPR_metric, VA_metric


class ResNet50(BaseModel):
    def __init__(self, opt):
        super(ResNet50, self).__init__(opt)
        self._name = 'ResNet50_GRU'
        self._output_size_per_task = {
            'AU': self._opt.AU_label_size,
            'EXPR': self._opt.EXPR_label_size,
            'VA': self._opt.VA_label_size * self._opt.digitize_num
        }
        self._criterions_per_task = {
            'AU': self._opt.AU_criterion,
            'EXPR': self._opt.EXPR_criterion,
            'VA': self._opt.VA_criterion
        }
        self.lambdas_per_task = {