forked from naiveHobo/InvoiceNet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloud_scan.py
49 lines (43 loc) · 2.03 KB
/
cloud_scan.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
import argparse
from model import InvoiceNetCloudScan
from extract_features import extract_features
ap = argparse.ArgumentParser()
ap.add_argument("--mode", type=str, choices=["train", "test"],
required=True, help="train|test")
ap.add_argument("--data", default="data/dftrain.pk",
help="path to training data")
ap.add_argument("--model_path", default="./model",
help="path to directory where trained model should be stored")
ap.add_argument("--load_weights", default="./model/InvoiceNetCloudScan.model",
help="path to load weights")
ap.add_argument("--checkpoint_dir", default="./checkpoints",
help="path to directory where checkpoints should be stored")
ap.add_argument("--log_dir", default="./logs",
help="path to directory where tensorboard logs should be stored")
ap.add_argument("--num_hidden", type=int, default=256,
help="size of hidden layer")
ap.add_argument("--epochs", type=int, default=20,
help="number of epochs")
ap.add_argument("--batch_size", type=int, default=128,
help="size of mini-batch")
ap.add_argument("--num_layers", type=int, default=1,
help="number of layers")
ap.add_argument("--num_input", type=int, default=17,
help="size of input layer")
ap.add_argument("--num_output", type=int, default=4,
help="size of output layer")
ap.add_argument("--shuffle", action='store_true',
help="shuffle dataset")
ap.add_argument("--oversample", type=int, default=0,
help="oversample minority classes to prevent class imbalance")
args = ap.parse_args()
net = InvoiceNetCloudScan(config=args)
features = extract_features(args.data)
if args.mode == 'train':
net.train(features)
else:
net.load_weights(args.load_weights)
predictions = net.evaluate(features)
net.f1_score(predictions, features.label.values)
# for i in range(predictions.shape[0]):
# print(predictions[i], features.label.values[i], features.iloc[i])