import os
import sys
import torch
import yaml
from functools import partial
sys.path.append('../../../../')
from trainers import trainer, frn_train
from datasets import dataloaders
from models.FRN import FRN


args = trainer.train_parser()
with open('../../../../config.yml', 'r') as f:
    temp = yaml.safe_load(f)
data_path = os.path.abspath(temp['data_path'])
fewshot_path = os.path.join(data_path,'CUB_fewshot_raw')

pm = trainer.Path_Manager(fewshot_path=fewshot_path,args=args)

train_way = args.train_way
shots = [args.train_shot, args.train_query_shot]

train_loader = dataloaders.meta_train_dataloader(data_path=pm.train,
                                                way=train_way,
                                                shots=shots,
                                                transform_type=args.train_transform_type)

model = FRN(way=train_way,
            shots=[args.train_shot, args.train_query_shot],
            resnet=args.resnet)

train_func = partial(frn_train.default_train,train_loader=train_loader)

tm = trainer.Train_Manager(args,path_manager=pm,train_func=train_func)

tm.train(model)

tm.evaluate(model)
[(6, 'sys.path.append', 'sys.path.append', False, 'import sys\n'), (12, 'trainers.trainer.train_parser', 'trainer.train_parser', False, 'from trainers import trainer, frn_train\n'), (15, 'os.path.abspath', 'os.path.abspath', False, 'import os\n'), (16, 'os.path.join', 'os.path.join', False, 'import os\n'), (18, 'trainers.trainer.Path_Manager', 'trainer.Path_Manager', False, 'from trainers import trainer, frn_train\n'), (23, 'datasets.dataloaders.meta_train_dataloader', 'dataloaders.meta_train_dataloader', False, 'from datasets import dataloaders\n'), (28, 'models.FRN.FRN', 'FRN', False, 'from models.FRN import FRN\n'), (32, 'functools.partial', 'partial', False, 'from functools import partial\n'), (34, 'trainers.trainer.Train_Manager', 'trainer.Train_Manager', False, 'from trainers import trainer, frn_train\n'), (14, 'yaml.safe_load', 'yaml.safe_load', False, 'import yaml\n')]