示例#1
0
    save_to_ckpt(ckptfile, start_epoch + additional_epoch, net, optimizer,
                 scheduler)

    # save the final model
    torch.save(net.state_dict(), ckptfile)
    ndcg_result = eval_ndcg_at_k(net, device, df_valid, valid_loader, 100000,
                                 [10, 30], start_epoch + additional_epoch,
                                 writer)
    print(
        get_time(), "finish training " + ", ".join(
            ["NDCG@{}: {:.5f}".format(k, ndcg_result[k])
             for k in ndcg_result]), '\n\n')


if __name__ == "__main__":
    parser = get_args_parser()
    parser.add_argument("--sigma", dest="sigma", type=float, default=1.0)
    args = parser.parse_args()
    train(
        args.start_epoch,
        args.additional_epoch,
        args.lr,
        args.optim,
        args.leaky_relu,
        ndcg_gain_in_train=args.ndcg_gain_in_train,
        sigma=args.sigma,
        double_precision=args.double_precision,
        standardize=args.standardize,
        small_dataset=args.small_dataset,
        debug=args.debug,
        output_dir=args.output_dir,
示例#2
0
from datetime import datetime

from flask import request
from flask_restful import Resource

from config import db
from models.user import User
from schemas.user import UserSchema
from utils import get_args_parser

user_schema = UserSchema(many=False)
parser = get_args_parser([
    {'name': "num_mark_tasks", 'type': int, 'required': True,
     'help': 'number of mark tasks the user has'},
    {'name': "password", 'type': str, 'required': False,
     'help': 'unprocessed password of the user'},
    {'name': "name", 'type': str, 'required': True,
     'help': 'name of the user'}
])


class UserResource(Resource):
    """Resource to handle CRUD operations for users table"""

    @staticmethod
    def get(user_id: int):
        """
        Returns single user
        """

        if not user_id:
import numpy as np
import os
import sys
import torch
from torch.utils.data import DataLoader

from augmentation.augmentation import RootAugmentation, RootBaseTransform
from dataloader.Eco2018Loader import DeviceLoader, Eco2018
from loss.loss import loss_fn, loss_fn2
from model.Textnet import Textnet
from model.functions import fit
from utils import get_device, get_args_parser, make_output_dir_name, print_config_file

if __name__ == '__main__':
    args = get_args_parser().parse_args()

    # Create output directory if it doesn't exist
    output_dir = make_output_dir_name(args)
    try:
        os.makedirs(output_dir, exist_ok=True)
    except IOError as e:
        sys.exit(f'[ERROR] Could not create output directory: {e}')

    # Write configuration to log file
    try:
        print_config_file(output_dir, args)
    except IOError as e:
        sys.exit(f'[ERROR] Could not write to output directory: {e}')

    print('Running on device:', get_device())
示例#4
0
import os
import sys
import torch
import torch.nn as nn

import my_model
import model
import utils
import data
import time

start = time.time()

# prepare
eval_batch_size = 10
args = utils.get_args_parser()
print('\n')
print('V ' * 80)
print('\n')
print(args)
print('\n')
print('#' * 80)
print("start!====")

# Set the random seed manually for reproducibility.
torch.manual_seed(args.seed)
device = utils.check_device(args)
if args.use_MyGRU:
    print("train by MyGRU!")
###############################################################################
# Load data