Guest User

Untitled

a guest
Nov 21st, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 KB | None | 0 0
  1. syntax = "proto3";
  2.  
  3. package tensorflow.serving;
  4.  
  5. import "model.proto";
  6. import "tensor.proto";
  7.  
  8. message PredictRequest {
  9.  
  10. float satisfaction_level = 1;
  11. float last_evaluation = 2;
  12. int32 number_project = 3;
  13. int32 average_monthly_hours = 4;
  14. int32 time_spend_company = 5;
  15. int32 work_accident = 6;
  16. int32 promotion_last_5years = 7;
  17. string sales = 8;
  18. string salary = 9;
  19.  
  20. };
  21.  
  22. message PredictResponse {
  23. // Matching probability of digit 0-9 in range [0.0, 1.0].
  24. repeated int32 left = 1;
  25. };
  26.  
  27. service PredictService {
  28. // Classifies image into digits.
  29. rpc Predict (PredictRequest) returns (PredictResponse);
  30. };
  31.  
  32. var PROTO_PATH = __dirname + '/predict.proto';
  33. var grpc = require('grpc');
  34. var attrition = grpc.load(PROTO_PATH).tensorflow.serving;
  35. function main() {
  36. var client = new attrition.PredictService('localhost:8500', grpc.credentials.createInsecure());
  37.  
  38. var req = new attrition.PredictRequest();
  39. req.satisfaction_level = 0.38;
  40. req.last_evaluation = 0.53;
  41. req.number_project = 2;
  42. req.average_monthly_hours = 157;
  43. req.time_spend_company = 3;
  44. req.work_accident = 0;
  45. req.promotion_last_5years = 0;
  46. req.sales = 'sales';
  47. req.salary = 'low';
  48.  
  49. function run() {
  50. client.predict(req, (err, predictResponse) => {
  51. if (err) {
  52. console.log(err)
  53. } else {
  54. var results = predictResponse ? predictResponse.value : [];
  55. console.log(results)
  56. }
  57. });
  58. };
  59.  
  60. run();
  61. }
  62.  
  63. main();
  64.  
  65. var PROTO_PATH = __dirname + '/protos/prediction_service.proto';
  66.  
  67. var grpc = require('grpc');
  68. var attrition = grpc.load(PROTO_PATH).tensorflow;
  69. function main() {
  70. var client = new attrition.PredictionService('localhost:8500', grpc.credentials.createInsecure());
  71.  
  72. var features = {
  73. model_spec: {name: 'attrition', signature_name: 'predict'},
  74. inputs: {
  75. average_monthly_hours: {
  76. dtype: "DT_INT32",
  77. tensor_shape: {
  78. dim: {
  79. size: 1
  80. }
  81. },
  82. int_val: 157
  83. }, last_evaluation: {
  84. dtype: "DT_FLOAT",
  85. tensor_shape: {
  86. dim: {
  87. size: 1
  88. }
  89. },
  90. float_val: 0.53
  91. }, number_project: {
  92. dtype: "DT_INT32",
  93. tensor_shape: {
  94. dim: {
  95. size: 1
  96. }
  97. },
  98. int_val: 2
  99. }, promotion_last_5years: {
  100. dtype: "DT_INT32",
  101. tensor_shape: {
  102. dim: {
  103. size: 1
  104. }
  105. },
  106. int_val: 0
  107. }, salary: {
  108. dtype: "DT_STRING",
  109. tensor_shape: {
  110. dim: {
  111. size: 1
  112. }
  113. },
  114. string_val: 'low'
  115. }, sales: {
  116. dtype: "DT_STRING",
  117. tensor_shape: {
  118. dim: {
  119. size: 1
  120. }
  121. },
  122. string_val: "sales"
  123. }, satisfaction_level: {
  124. dtype: "DT_FLOAT",
  125. tensor_shape: {
  126. dim: {
  127. size: 1
  128. }
  129. },
  130. float_val: 0.38
  131. }, time_spend_company: {
  132. dtype: "DT_INT32",
  133. tensor_shape: {
  134. dim: {
  135. size: 1
  136. }
  137. },
  138. int_val: 3
  139. }, work_accident: {
  140. dtype: "DT_INT32",
  141. tensor_shape: {
  142. dim: {
  143. size: 1
  144. }
  145. },
  146. int_val: 0
  147. }
  148. }
  149. }
  150.  
  151. function run() {
  152. client.predict(features, (err, predictResponse) => {
  153. if (err) {
  154. console.log("Received error running prediction:")
  155. console.log(err)
  156. } else {
  157. var results = predictResponse ? predictResponse.value : [];
  158. console.log(results)
  159. }
  160. });
  161. };
  162.  
  163. run();
  164. }
  165.  
  166. main();
  167.  
  168. feature_inputs = {
  169. 'satisfaction_level': tf.placeholder(dtype=tf.float32, shape=[1,], name='satisfaction_level'),
  170. 'last_evaluation': tf.placeholder(dtype=tf.float32, shape=[1,], name='last_evaluation'),
  171. 'number_project': tf.placeholder(dtype=tf.int32, shape=[1,], name='number_project'),
  172. 'average_monthly_hours': tf.placeholder(dtype=tf.int32, shape=[1,], name='average_monthly_hours'),
  173. 'time_spend_company': tf.placeholder(dtype=tf.int32, shape=[1,], name='time_spend_company'),
  174. 'work_accident': tf.placeholder(dtype=tf.int32, shape=[1,], name='work_accident'),
  175. 'promotion_last_5years': tf.placeholder(dtype=tf.int32, shape=[1,], name='promotion_last_5years'),
  176. 'sales': tf.placeholder(dtype=tf.string, shape=[1,], name='sales'),
  177. 'salary': tf.placeholder(dtype=tf.string, shape=[1,], name='salary')
  178. }
  179. serving_input_receiver_fn = tf.estimator.export.build_raw_serving_input_receiver_fn(feature_inputs)
  180. model.export_savedmodel("./exported_model", serving_input_receiver_fn)
  181.  
  182. saved_model_cli show --dir ../python/notebooks/exported_model/1510845524/ --all
  183. MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
  184.  
  185. signature_def['predict']:
  186. The given SavedModel SignatureDef contains the following input(s):
  187. inputs['average_monthly_hours'] tensor_info:
  188. dtype: DT_INT32
  189. shape: (-1, 1)
  190. name: average_monthly_hours_1:0
  191. inputs['last_evaluation'] tensor_info:
  192. dtype: DT_FLOAT
  193. shape: (-1, 1)
  194. name: last_evaluation_1:0
  195. inputs['number_project'] tensor_info:
  196. dtype: DT_INT32
  197. shape: (-1, 1)
  198. name: number_project_1:0
  199. inputs['promotion_last_5years'] tensor_info:
  200. dtype: DT_INT32
  201. shape: (-1, 1)
  202. name: promotion_last_5years_1:0
  203. inputs['salary'] tensor_info:
  204. dtype: DT_STRING
  205. shape: (-1, 1)
  206. name: salary_1:0
  207. inputs['sales'] tensor_info:
  208. dtype: DT_STRING
  209. shape: (-1, 1)
  210. name: sales_1:0
  211. inputs['satisfaction_level'] tensor_info:
  212. dtype: DT_FLOAT
  213. shape: (-1, 1)
  214. name: satisfaction_level:0
  215. inputs['time_spend_company'] tensor_info:
  216. dtype: DT_INT32
  217. shape: (-1, 1)
  218. name: time_spend_company_1:0
  219. inputs['work_accident'] tensor_info:
  220. dtype: DT_INT32
  221. shape: (-1, 1)
  222. name: work_accident_1:0
  223. The given SavedModel SignatureDef contains the following output(s):
  224. outputs['class_ids'] tensor_info:
  225. dtype: DT_INT64
  226. shape: (-1, 1)
  227. name: dnn/head/predictions/classes:0
  228. outputs['classes'] tensor_info:
  229. dtype: DT_STRING
  230. shape: (-1, 1)
  231. name: dnn/head/predictions/str_classes:0
  232. outputs['logistic'] tensor_info:
  233. dtype: DT_FLOAT
  234. shape: (-1, 1)
  235. name: dnn/head/predictions/logistic:0
  236. outputs['logits'] tensor_info:
  237. dtype: DT_FLOAT
  238. shape: (-1, 1)
  239. name: dnn/head/predictions/logits:0
  240. outputs['probabilities'] tensor_info:
  241. dtype: DT_FLOAT
  242. shape: (-1, 2)
  243. name: dnn/head/predictions/probabilities:0
  244. Method name is: tensorflow/serving/predict
  245.  
  246. tensorflow_model_server --port=8500 --model_name=attrition --model_base_path=`pwd`/exported_model/
  247.  
  248. 2017-11-20 12:18:20.380088: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:155] Restoring SavedModel bundle.
  249. 2017-11-20 12:18:20.386764: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:190] Running LegacyInitOp on SavedModel bundle.
  250. 2017-11-20 12:18:20.393305: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:284] Loading SavedModel: success. Took 44036 microseconds.
  251. 2017-11-20 12:18:20.393473: I tensorflow_serving/core/loader_harness.cc:86] Successfully loaded servable version {name: attrition version: 1510845524}
  252. 2017-11-20 12:18:20.397036: I tensorflow_serving/model_servers/main.cc:288] Running ModelServer at 0.0.0.0:8500 ...
Add Comment
Please, Sign In to add comment