Douzero_Resnet/evaluate.py

127 lines
4.4 KiB
Python
Raw Normal View History

2021-12-08 17:16:27 +08:00
import os
2021-09-07 16:38:34 +08:00
import argparse
2021-12-24 17:44:30 +08:00
from pickle import FALSE
2021-12-24 18:17:51 +08:00
import csv
2021-09-07 16:38:34 +08:00
from douzero.evaluation.simulation import evaluate
2021-12-08 17:16:27 +08:00
2021-12-12 16:49:54 +08:00
def make_evaluate(args, vs_config):
landlord_config = vs_config['landlord']
farmer_config = vs_config['farmer']
if landlord_config['prefix'] == 'random':
args.landlord = 'random'
2021-12-12 16:49:54 +08:00
else:
args.landlord = '%s/%s_landlord_%i.ckpt' % (
landlord_config['folder'], landlord_config['prefix'], landlord_config['frame']
)
if farmer_config['prefix'] == 'random':
args.landlord_up = 'random'
args.landlord_front = 'random'
args.landlord_down = 'random'
2021-12-12 16:49:54 +08:00
else:
args.landlord_up = '%s/%s_landlord_up_%i.ckpt' % (
farmer_config['folder'], farmer_config['prefix'], farmer_config['frame']
)
args.landlord_front = '%s/%s_landlord_front_%i.ckpt' % (
farmer_config['folder'], farmer_config['prefix'], farmer_config['frame']
)
args.landlord_down = '%s/%s_landlord_down_%i.ckpt' % (
farmer_config['folder'], farmer_config['prefix'], farmer_config['frame']
)
print('%s %i\tvs\t%s %i' % (
landlord_config['prefix'], landlord_config['frame'], farmer_config['prefix'], farmer_config['frame']))
2021-12-08 17:16:27 +08:00
2021-12-24 18:17:51 +08:00
landlord_wp, farmer_wp, landlord_adp, farmer_adp = evaluate(args.landlord,
2021-12-08 17:16:27 +08:00
args.landlord_up,
2021-12-11 20:07:41 +08:00
args.landlord_front,
2021-12-08 17:16:27 +08:00
args.landlord_down,
args.eval_data,
args.num_workers,
args.output,
args.title)
2021-12-24 18:17:51 +08:00
with open('result.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([
landlord_wp,
farmer_wp,
landlord_adp,
farmer_adp
])
2021-12-08 17:16:27 +08:00
2021-09-07 16:38:34 +08:00
if __name__ == '__main__':
parser = argparse.ArgumentParser(
2021-12-08 17:16:27 +08:00
'Dou Dizhu Evaluation')
2021-09-07 16:38:34 +08:00
parser.add_argument('--landlord', type=str,
2021-12-08 17:16:27 +08:00
default='baselines/douzero_12/landlord_weights_39762328900.ckpt')
2021-09-07 16:38:34 +08:00
parser.add_argument('--landlord_up', type=str,
2021-12-08 17:16:27 +08:00
default='baselines/douzero_12/landlord_up_weights_39762328900.ckpt')
2021-12-05 12:03:30 +08:00
parser.add_argument('--landlord_front', type=str,
2021-12-08 17:16:27 +08:00
default='baselines/douzero_12/landlord_front_weights_39762328900.ckpt')
2021-09-07 16:38:34 +08:00
parser.add_argument('--landlord_down', type=str,
2021-12-08 17:16:27 +08:00
default='baselines/douzero_12/landlord_down_weights_39762328900.ckpt')
2021-09-07 16:38:34 +08:00
parser.add_argument('--eval_data', type=str,
2021-12-08 17:16:27 +08:00
default='eval_data_200.pkl')
2021-12-12 16:49:54 +08:00
parser.add_argument('--num_workers', type=int, default=3)
2021-09-07 16:38:34 +08:00
parser.add_argument('--gpu_device', type=str, default='0')
parser.add_argument('--output', type=bool, default=True)
parser.add_argument('--title', type=str, default='New')
args = parser.parse_args()
2021-12-19 17:19:32 +08:00
# args.output = True
args.output = False
if args.output:
2021-09-07 16:38:34 +08:00
args.num_workers = 1
2021-12-08 17:16:27 +08:00
2021-09-07 16:38:34 +08:00
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu_device
2021-12-24 17:44:30 +08:00
baselines = [
{'folder': 'baselines', 'prefix': 'legacy_general', 'frame': 736107200},
{'folder': 'baselines', 'prefix': 'legacy_general', 'frame': 479412800},
{'folder': 'baselines', 'prefix': 'legacy_general', 'frame': 262529600},
{'folder': 'baselines', 'prefix': 'legacy_general', 'frame': 143539200},
]
evaluations = [
{'folder': 'baselines', 'prefix': 'lite_general', 'frame': 299457600},
{'folder': 'baselines', 'prefix': 'lite_resnet', 'frame': 124064400},
]
2021-12-08 17:16:27 +08:00
eval_list = [
2021-12-19 17:19:32 +08:00
{
2021-12-24 17:44:30 +08:00
'farmer': baseline,
'landlord': evaluation,
2021-12-12 16:49:54 +08:00
'two_way': True
2021-12-24 17:44:30 +08:00
}
for evaluation in evaluations for baseline in baselines
2021-12-08 17:16:27 +08:00
]
2021-12-24 19:12:09 +08:00
eval_list.extend([
2021-12-24 17:44:30 +08:00
{
'farmer': evaluation,
'landlord': evaluation,
'two_way': False
}
for evaluation in evaluations
])
# eval_list = [
# {
# 'farmer': { 'folder': 'baselines', 'prefix': 'lite_general', 'frame': 221553600},
# 'landlord': { 'folder': 'baselines', 'prefix': 'lite_resnet', 'frame': 102494400},
# 'two_way': False
# },
# ]
for vs in eval_list:
2021-12-12 16:49:54 +08:00
make_evaluate(args, vs)
if vs['two_way']:
vs['landlord_bak'] = vs['landlord']
vs['landlord'] = vs['farmer']
vs['farmer'] = vs['landlord_bak']
make_evaluate(args, vs)