From 8c7cc72b515c6e53edd82cfc9e68cbb7edd480ef Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Thu, 15 Dec 2016 15:28:28 +0800 Subject: [PATCH] add python api_predict for quick start --- demo/quick_start/api_predict.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/demo/quick_start/api_predict.py b/demo/quick_start/api_predict.py index 9c224e3cd..a1a9ef7bc 100755 --- a/demo/quick_start/api_predict.py +++ b/demo/quick_start/api_predict.py @@ -18,13 +18,12 @@ from optparse import OptionParser from py_paddle import swig_paddle, DataProviderConverter from paddle.trainer.PyDataProvider2 import sparse_binary_vector from paddle.trainer.config_parser import parse_config - - """ Usage: run following command to show help message. python api_predict.py -h """ + class QuickStartPrediction(): def __init__(self, train_conf, dict_file, model_dir=None, label_file=None): """ @@ -72,9 +71,7 @@ class QuickStartPrediction(): transform word into integer index according to the dictionary. """ words = data.strip().split() - word_slot = [ - self.word_dict[w] for w in words if w in self.word_dict - ] + word_slot = [self.word_dict[w] for w in words if w in self.word_dict] return word_slot def batch_predict(self, data_batch): @@ -84,6 +81,7 @@ class QuickStartPrediction(): print("predicting labels is:") print prob + def option_parser(): usage = "python predict.py -n config -w model_dir -d dictionary -i input_file " parser = OptionParser(usage="usage: %s [options]" % usage) @@ -144,5 +142,6 @@ def main(): print labels predict.batch_predict(batch) + if __name__ == '__main__': main() -- GitLab