Ejemplo n.º 1
0
Archivo: dice.py Proyecto: Qcactus/CPR
    def fit(self, args, model_dir):

        init_variables(self.sess, self.saver, args.load_model, model_dir)

        # Create evaluators and early_stoppings
        # evaluators: for different eval_set
        self.evaluators = {}

        if args.eval_epoch is not None:
            self.evaluators = create_evaluators(self.dataset, args.eval_types,
                                                args.metrics, args.ks,
                                                args.n_thread)
            self.early_stopping = EarlyStopping(args.early_stop)

        # Start training and evaluation.
        print_seperate_line()
        if args.eval_epoch is not None:
            self.eval(args)
            print_seperate_line()

        self.int_weight_v = args.int_weight
        self.pop_weight_v = args.pop_weight

        for epoch in range(1, args.epoch + 1):
            self.train_1_epoch(epoch, args)
            self.int_weight_v *= args.loss_decay
            self.pop_weight_v *= args.loss_decay
            self.sampler.margin *= args.margin_decay

            if args.eval_epoch is not None and epoch % args.eval_epoch == 0:
                print_seperate_line()
                self.eval(args)
                print_seperate_line()

                if self.early_stopping.check_stop(self.evaluators, epoch):
                    break

        print(self.early_stopping)
        print_seperate_line()

        # Save model.
        if args.save_model:
            save_model(self.sess, self.saver, args.verbose_name, args.epoch,
                       model_dir)
Ejemplo n.º 2
0
Archivo: DICE.py Proyecto: Qcactus/CPR
import os
from recq.recommenders.dice import DICE
from recq.utils import Dataset
from recq.tools.parser import parse_args
from recq.tools.io import print_seperate_line

args = parse_args("dice")
print_seperate_line()
for key, value in vars(args).items():
    print(key + '=' + str(value))
print_seperate_line()

curr_dir = os.path.dirname(__file__)
if args.gpu_id is not None:
    os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu_id)

data_dir = os.path.join(curr_dir, "data", args.dataset)
model_dir = os.path.join(curr_dir, "output", "model")

dataset = Dataset(args, data_dir)
model = DICE(args, dataset)
model.fit(args, model_dir)