Skip to content

Commit 644a721

Browse files
committed
add warnings and errors if tf-serving-api is not installed
1 parent ae9acc4 commit 644a721

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

deepsegment/deepsegment.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
import logging
88
import time
99

10+
11+
is_tfserving_installed = True
12+
1013
try:
1114
import grpc
1215
import tensorflow as tf
1316
from tensorflow.python.saved_model import signature_constants
1417
from tensorflow_serving.apis import predict_pb2
1518
from tensorflow_serving.apis import prediction_service_pb2_grpc
1619
except Exception as ex:
17-
logging.warning("Tensorflow serving is not installed. Cannot be used with tesnorflow serving docker images.")
20+
is_tfserving_installed = False
21+
logging.warn("Tensorflow serving is not installed. Cannot be used with tesnorflow serving docker images.")
22+
logging.warn("Run pip install tensorflow-serving-api==1.12.0 if you want to use with tf serving.")
1823

1924
model_links = {
2025
'en': {
@@ -109,7 +114,11 @@ def __init__(self, lang_code='en', checkpoint_path=None, params_path=None, utils
109114
DeepSegment.seqtag_model = model_from_json(open(params_path).read(), custom_objects={'CRF': CRF})
110115
DeepSegment.seqtag_model.load_weights(checkpoint_path)
111116

112-
if tf_serving:
117+
elif tf_serving:
118+
if not is_tfserving_installed:
119+
logging.exception("Tensorflow serving is not installed. Cannot be used with tesnorflow serving docker images.")
120+
logging.exception("Run pip install tensorflow-serving-api==1.12.0 if you want to use with tf serving.")
121+
exit()
113122
DeepSegment.seqtag_model = 'deepsegment_' + lang_code
114123

115124
DeepSegment.data_converter = pickle.load(open(utils_path, 'rb'))

0 commit comments

Comments
 (0)