Exemple #1
0
def demo_test(args):
    if args.doc:
        args = config_loader(args.doc, args)
    # config
    # model_config(args, save=False)     # print model configuration of evaluation

    # set cuda
    torch.cuda.set_device(args.gpu_id)

    # model
    model = model_builder(args.model_name, args.scale, **args.model_args).cuda()

    # criteriohn
    criterion = criterion_builder(args.criterion)

    # dataset
    test_set = AxisDataSet(args.test_path, args.target_path)

    test_loader = DataLoader(test_set,
                             batch_size=args.batch_size,
                             shuffle=False,
                             num_workers=args.num_workers,
                            #  pin_memory=True,
                             pin_memory=False,
                             )

    # test
    test(model, test_loader, criterion, args)
Exemple #2
0
def model_env(args):
    """building model environment avoiding to instantiate model.

    Args:
        args : model arguments which is control by demo_utils.argument_setting

    Returns:
        model (torch.nn): build model in cuda device
        criterion(torch.nn): build criterion. Default to mse loss
        extractor(torch.nn): build vgg content loss in cuda device
    """

    if args.doc:
        args = config_loader(args.doc, args)

    # set cuda device
    torch.cuda.set_device(args.gpu_id)

    # model version control
    version = args.load if type(args.load) is int else 0

    # model path and parameter
    model_path = os.path.join(
        args.log_path, args.model_name, f'version_{version}',f'{args.model_name}_{args.scale}x.pt')

    checkpoint = torch.load(model_path, map_location=f'cuda:{args.gpu_id}')

    # loading model
    model = model_builder(args.model_name, args.scale, **args.model_args).cuda()
    model.load_state_dict(checkpoint['state_dict'])

    # build criterion
    criterion = criterion_builder(args.criterion)

    # loading feature extractor
    extractor = FeatureExtractor().cuda() if args.content_loss else None

    return model, criterion, extractor
Exemple #3
0
import uuid
import json

import time
import traceback
"""
Note: Adding eventlet and monkey_patching it to ensure that emit messages are not
    accumulated and sent out in bursts
"""
import eventlet
eventlet.monkey_patch()
"""
Load config
"""
config = config_loader()

app = Flask(__name__)
socketio = SocketIO(app)


@socketio.on('authenticate')
def handle_authenticate(args):
    """
        Handles authentication for a particular
        API_KEY and challenge_id pair

        Request Params:
            API_KEY : String
                Holds the API Key of the participant
            challenge_id : String
                    'state_dict': model.state_dict(),
                    'epoch': epoch,
                    'train_iter': checkpoint['train_iter'],
                    'valid_iter': checkpoint['valid_iter'],
                }, model_path)

    writer.close()


if __name__ == '__main__':
    # argument setting
    train_args = train_argument()

    # replace args by document file
    if train_args.doc:
        train_args = config_loader(train_args.doc, train_args)
    # set cuda
    torch.cuda.set_device(train_args.gpu_id)

    # model
    model = model_builder(train_args.model_name, train_args.scale,
                          **train_args.model_args).cuda()

    # optimizer and critera
    optimizer = optimizer_builder(train_args.optim)  # optimizer class
    optimizer = optimizer(  # optmizer instance
        model.parameters(),
        lr=train_args.lr,
        weight_decay=train_args.weight_decay)
    criterion = criterion_builder(train_args.criterion)
Exemple #5
0
        content_loss = args.beta * criterion(gen_feature, real_feature)

        # for compatible
        loss = content_loss + mse_loss
        err += loss.sum().item() * inputs.size(0)

    err /= len(test_loader.dataset)
    print(f'test error:{err:.4f}')


if __name__ == '__main__':
    # argument setting
    test_args = test_argument()

    if test_args.doc:
        test_args = config_loader(test_args.doc, test_args)
    # config
    model_config(test_args,
                 save=False)  # print model configuration of evaluation

    # set cuda
    torch.cuda.set_device(test_args.gpu_id)

    # model
    model = model_builder(test_args.model_name, test_args.scale,
                          **test_args.model_args).cuda()

    # criteriohn
    criterion = criterion_builder(test_args.criterion)
    # optimizer = None # don't need optimizer in test
    def __init__(self):
        self.clean = Clean()
        self.despesas_getter = Despesas()
        self.config = config_loader('configuration.yaml')

        self.data = self.get_data()
Exemple #7
0
 def __init__(self):
     self.config = config_loader('configuration.yaml')
Exemple #8
0
 def __init__(self, data: Optional[datetime] = None):
     self.data = data if data else datetime.today()
     self.config = config_loader('configuration.yaml')