-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpcClient.py
executable file
·74 lines (66 loc) · 2.21 KB
/
rpcClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/python3
import os
import json
import argparse
import xmlrpc.client
parser = argparse.ArgumentParser()
parser.add_argument("--url",
default='http://10.60.150.247:8080',
help="model dirs")
parser.add_argument('--gpuid', default=0, help="gpuid")
args = parser.parse_args()
def rpcWorker(url, gpuid):
s = xmlrpc.client.ServerProxy(url)
if os.path.exists('work_%d' % gpuid):
os.system('rm -rf work_%d' % gpuid)
os.system('cp -lr neuraltalk2-ERNN work_%d' % gpuid)
os.chdir('work_%d' % gpuid)
os.system('rm coco_caption/lock')
os.system('rm coco_caption/*.json')
flag = True
while(flag):
try:
ret = s.born()
except:
continue
try:
val_max = {'CIDEr': -0.01}
nid = ret['id']
lua_code = ret['lua']
args = ret['args']
print('nid', nid)
with open('cell.lua', 'w') as fd:
fd.write(lua_code)
os.system('rm model_.json')
cmd = 'CUDA_VISIBLE_DEVICES=%d th train.lua ' % gpuid
cmd = cmd + ' '.join(['-%s %s' % (k, args[k]) for k in args])
os.system(cmd)
with open('model_.json') as fd:
data = json.load(fd)
val_max = {}
val_data = data["val_lang_stats_history"]
val_data = sorted(val_data.items(), key=lambda t: int(t[0]))
max_result = -0.01
for k, v in val_data:
if v['CIDEr'] > max_result:
max_result = v['CIDEr']
for metric in v:
val_max[metric] = v[metric]
val_max['pos_max'] = k
except FileNotFoundError:
print('FileNotFoundError')
val_max = {'CIDEr': -0.01}
except KeyError:
print('KeyError')
val_max = {'CIDEr': -0.01}
except KeyboardInterrupt:
if flag:
print('return next loop')
flag = False
else:
print('return now')
break
finally:
s.fight(nid, val_max)
if __name__ == '__main__':
rpcWorker(args.url, int(args.gpuid))