forked from sYeaLumin/SketchGNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
39 lines (35 loc) · 1.19 KB
/
predict.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
import os
import json
import time
import numpy as np
from options import TestOptions
from framework import SketchModel
from utils import load_data
from writer import Writer
if __name__ == "__main__":
opt = TestOptions().parse()
model = SketchModel(opt)
loader = load_data(opt, datasetType='test')
writer = Writer(opt)
predict = np.array([])
for i, data in enumerate(loader):
loss, out = model.test(data, if_eval=True)
predict = np.append(predict, out)
i = 0
predictData = []
with open(os.path.join('data', opt.dataset, 'train',
'{}_{}.ndjson'.format(opt.class_name, 'test')), 'r') as f:
for line in f:
data = json.loads(line)
sketch = data["drawing"]
for stroke in sketch:
l = len(stroke[0])
stroke[2] = predict[i:i+l].astype(np.int32).tolist()
i += l
data["drawing"] = sketch
predictData.append(data)
with open(os.path.join('data', opt.dataset, 'train',
'{}_{}.ndjson'.format(opt.class_name, 'res')), 'w') as f:
for data in predictData:
json.dump(data, f)
f.write("\n")