def __init__(self, args, X=None, Y=None, optimizer=None, use_gpu=-1, collect_output=False, activation=F.tanh): ## We only instantitate the descendant of this class assert hasattr(self, "_all_models"), "Shoudln't instantitate this class." ## Default configuration self._opt = optimizer self._xp, use_gpu = UF.setup_gpu(use_gpu) self._collect_output = collect_output self._gpu_id = use_gpu self._train_state = self._train_state = { "loss": 150, "epoch": 0 } ## Loading Classifier if args.init_model: serializer = ModelSerializer(args.init_model) serializer.load(self, self._all_models, xp=self._xp) self._model.report(sys.stderr, verbosity=1) else: args.input = len(X) args.output = len(Y) self._model = UF.select_model(args.model, self._all_models)(X, Y, args, xp=self._xp) ## Use GPU or not? if use_gpu >= 0: self._model = self._model.to_gpu(use_gpu) ## Setup Optimizer if optimizer is not None: self._opt.setup(self._model) if args.init_model: serializer.load_optimizer(self._opt)