Beispiel #1
0
def run_all(root=DATA_FOLDER,
            data_file=DATA_FILE,
            store_path=Path(DATA_FOLDER).joinpath(STORE_FOLDER)):
    ensure_folder(store_path)
    setup_logger(store_path, LOGGER_FILE_NAME, console_output=True)
    setup_seed(SEED)

    # load data
    file_path = Path(root).joinpath(data_file)
    data = load_data(file_path)
    logging.info(">>>>> Summary of original dataset.")
    print_info(data)
    logger_endl()

    # wash data, explicit->implicit
    data = filter_data(data)
    logging.info(">>>>> Summary of filtered dataset.")
    print_info(data)
    logger_endl()

    # index -> make session -> gen neg sample
    data, user_to_idx, item_to_idx = make_index(data)
    logger_endl()

    user_to_seqs, user_to_pos_items = gen_session_sample(data)
    logger_endl()

    user_to_neg_items = gen_neg_sample(user_to_seqs, user_to_pos_items,
                                       set(item_to_idx.values()))
    logger_endl()

    # save all
    save_data(user_to_seqs, user_to_pos_items, user_to_idx, item_to_idx,
              store_path)
    save_neg_data(user_to_neg_items, store_path)
Beispiel #2
0
 def __init__(
         self,
         model,
         output_labels,
         save_checkpoint_path=generate_checkpoint_path(),
         epochs=DEFAULT_EPOCHS,
         mean=DEFAULT_MEAN,
         std=DEFAULT_STD,
         lr=DEFAULT_LR - 3,
         image_resize=DEFAULT_IMAGE_RESIZE,
         batch_size=DEFAULT_BATCH_SIZE,
         images_dir=None,
         only_labels=None,
         use_cpu=False,
         seed=DEFAULT_SEED,
         no_warmup=False,
         no_scheduler=None,
         device=None,
         **kwargs  # to pass values from argparse
 ):
     self.seed = setup_seed(seed)
     self.model = model
     self.device = device
     self.n_epochs = epochs
     self.mean = mean
     self.std = std
     self.lr = lr
     self.image_resize = image_resize
     self.batch_size = batch_size
     self.only_labels = only_labels
     self.images_dir = images_dir
     self.optimizer = None
     self.scheduler = None
     self.save_path = save_checkpoint_path
     self.index_to_label = None
     self.output_labels = [x for x in output_labels]
     self.no_warmup = no_warmup
     self.labels_indices = {}
     self.use_cpu = use_cpu
     self.current_epoch = -1
     self.no_scheduler = no_scheduler
Beispiel #3
0
        parser = student_search_parser(teacher_type=teacher_type)
        args = parser.parse_args(cmd.split(" "))
    else:  # 2. Running
        preset_parser = student_search_preset_parser()
        preset_args, unk = preset_parser.parse_known_args()
        teacher_type, dataset = preset_args.T, preset_args.D
        parser = student_search_parser(teacher_type=teacher_type)
        args = parser.parse_args(unk)
        assert args.search_teacher_folder is not None

    store_folder = setup_folder(store_root=args.aux_store_root,
                                project_name=args.name)
    folder = Path(store_folder)

    setup_logger(folder_path=folder, console_output=args.aux_console_output)
    setup_seed(args.seed)

    if args.gpu_teacher == args.gpu_student:
        gpu_str = args.gpu_teacher
        device_student = torch.device("cuda:0")
        device_teacher = torch.device("cuda:0")
    else:  # args.gpu_teacher != args.gpu_student:
        if args.gpu_teacher > args.gpu_student:
            gpu_str = f"{args.gpu_student},{args.gpu_teacher}"
            device_student = torch.device("cuda:0")
            device_teacher = torch.device("cuda:1")
        else:  # args.gpu_teacher < args.gpu_student:
            gpu_str = f"{args.gpu_teacher},{args.gpu_student}"
            device_student = torch.device("cuda:1")
            device_teacher = torch.device("cuda:0")
    setup_gpu(gpu_str)