當前位置: 首頁>>代碼示例>>Python>>正文


Python implementations.insecure_channel方法代碼示例

本文整理匯總了Python中grpc.beta.implementations.insecure_channel方法的典型用法代碼示例。如果您正苦於以下問題:Python implementations.insecure_channel方法的具體用法?Python implementations.insecure_channel怎麽用?Python implementations.insecure_channel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在grpc.beta.implementations的用法示例。


在下文中一共展示了implementations.insecure_channel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def run(host, port, test_json, model_name, signature_name):

    # channel = grpc.insecure_channel('%s:%d' % (host, port))
    channel = implementations.insecure_channel(host, port)
    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

    with open(test_json, "r") as frobj:
        content = json.load(frobj)
        print(len(content), "======")

    start = time.time()

    for i, input_dict in enumerate(content):
        request = prepare_grpc_request(model_name, signature_name, input_dict)
        result = stub.Predict(request, 10.0)
        print(result, i)

    end = time.time()
    time_diff = end - start
    print('time elapased: {}'.format(time_diff)) 
開發者ID:yyht,項目名稱:BERT,代碼行數:22,代碼來源:test_grpc_serving.py

示例2: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main():
  host = FLAGS.host
  port = FLAGS.port
  model_name = FLAGS.model_name
  model_version = FLAGS.model_version
  request_timeout = FLAGS.request_timeout

  # Generate inference data
  features = numpy.asarray(
      [1, 2, 3, 4, 5, 6, 7, 8, 9])
  features_tensor_proto = tf.contrib.util.make_tensor_proto(features,
                                                            dtype=tf.float32)

  # Create gRPC client and request
  channel = implementations.insecure_channel(host, port)
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  request = predict_pb2.PredictRequest()
  request.model_spec.name = model_name
  request.model_spec.version.value = model_version
  request.inputs['features'].CopyFrom(features_tensor_proto)

  # Send request
  result = stub.Predict(request, request_timeout)
  print(result) 
開發者ID:tobegit3hub,項目名稱:tensorflow_template_application,代碼行數:26,代碼來源:predict_client.py

示例3: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main():
  # Generate inference data
  keys = numpy.asarray([1, 2, 3, 4])
  keys_tensor_proto = tf.contrib.util.make_tensor_proto(keys, dtype=tf.int32)
  features = numpy.asarray(
      [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 1, 1, 1, 1, 1, 1, 1],
       [9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 9, 9, 9, 9, 9, 9, 9, 9]])
  features_tensor_proto = tf.contrib.util.make_tensor_proto(
      features, dtype=tf.float32)

  # Create gRPC client
  channel = implementations.insecure_channel(FLAGS.host, FLAGS.port)
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  request = predict_pb2.PredictRequest()
  request.model_spec.name = FLAGS.model_name
  if FLAGS.model_version > 0:
    request.model_spec.version.value = FLAGS.model_version
  if FLAGS.signature_name != "":
    request.model_spec.signature_name = FLAGS.signature_name
  request.inputs["keys"].CopyFrom(keys_tensor_proto)
  request.inputs["features"].CopyFrom(features_tensor_proto)

  # Send request
  result = stub.Predict(request, FLAGS.request_timeout)
  print(result) 
開發者ID:tobegit3hub,項目名稱:tensorflow_template_application,代碼行數:27,代碼來源:predict_client.py

示例4: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main():
  host = FLAGS.host
  port = FLAGS.port
  model_name = FLAGS.model_name
  model_version = FLAGS.model_version
  request_timeout = FLAGS.request_timeout

  # Generate inference data
  features = numpy.asarray(
      [[1, 2, 3, 4], [5, 6, 7, 8]])
  features_tensor_proto = tf.contrib.util.make_tensor_proto(features,
                                                            dtype=tf.float32)

  # Create gRPC client and request
  channel = implementations.insecure_channel(host, port)
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  request = predict_pb2.PredictRequest()
  request.model_spec.name = model_name
  if model_version > 0:
    request.model_spec.version.value = model_version
  request.inputs['state'].CopyFrom(features_tensor_proto)

  # Send request
  result = stub.Predict(request, request_timeout)
  print(result) 
開發者ID:tobegit3hub,項目名稱:deep_q,代碼行數:27,代碼來源:predict_client.py

示例5: create_stub

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def create_stub(grpc_apiserver_host):
  """Creates a grpc_service.CallHandler stub.

  Args:
    grpc_apiserver_host: String, the host that CallHandler service listens on.
      Should be in the format of hostname:port.

  Returns:
    A CallHandler stub.
  """
  # See http://www.grpc.io/grpc/python/_modules/grpc/beta/implementations.html:
  # the method insecure_channel requires explicitly two parameters (host, port)
  # here our host already contain port number, so the second parameter is None.
  prefix = 'http://'
  if grpc_apiserver_host.startswith(prefix):
    grpc_apiserver_host = grpc_apiserver_host[len(prefix):]
  channel = implementations.insecure_channel(grpc_apiserver_host, None)
  return grpc_service_pb2.beta_create_CallHandler_stub(channel) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:20,代碼來源:grpc_proxy_util.py

示例6: _do_local_inference

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def _do_local_inference(host, port, serialized_examples, model_name):
  """Performs inference on a model hosted by the host:port server."""

  channel = implementations.insecure_channel(host, int(port))
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

  request = predict_pb2.PredictRequest()
  # request.model_spec.name = 'chicago_taxi'
  request.model_spec.name = model_name
  request.model_spec.signature_name = 'predict'

  tfproto = tf.contrib.util.make_tensor_proto([serialized_examples],
                                              shape=[len(serialized_examples)],
                                              dtype=tf.string)
  # The name of the input tensor is 'examples' based on
  # https://github.com/tensorflow/tensorflow/blob/r1.9/tensorflow/python/estimator/export/export.py#L290
  request.inputs['examples'].CopyFrom(tfproto)
  print(stub.Predict(request, _LOCAL_INFERENCE_TIMEOUT_SECONDS)) 
開發者ID:amygdala,項目名稱:code-snippets,代碼行數:20,代碼來源:chicago_taxi_client.py

示例7: _create_stub

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def _create_stub(server):
  host, port = server.split(":")
  channel = implementations.insecure_channel(host, int(port))
  # TODO(bgb): Migrate to GA API.
  return prediction_service_pb2.beta_create_PredictionService_stub(channel) 
開發者ID:akzaidi,項目名稱:fine-lm,代碼行數:7,代碼來源:serving_utils.py

示例8: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main():
  host = FLAGS.host
  port = FLAGS.port
  model_name = FLAGS.model_name
  model_version = FLAGS.model_version
  request_timeout = FLAGS.request_timeout

  # Generate inference data
  keys = numpy.asarray([1, 2, 3])
  keys_tensor_proto = tf.contrib.util.make_tensor_proto(keys, dtype=tf.int32)
  features_tensor_proto = tf.contrib.util.make_tensor_proto(img,
                                                            dtype=tf.float32)

  # Create gRPC client and request
  channel = implementations.insecure_channel(host, port)
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  request = predict_pb2.PredictRequest()
  request.model_spec.name = model_name
  if model_version > 0:
    request.model_spec.version.value = model_version
  request.inputs['inputs'].CopyFrom(features_tensor_proto)
  request.model_spec.signature_name = 'predict'
  #request.inputs['features'].CopyFrom(features_tensor_proto)

  # Send request
  result = stub.Predict(request, request_timeout)
  response = numpy.array(result.outputs['outputs'].float_val)
  prediction = numpy.argmax(response)

  print(prediction) 
開發者ID:llSourcell,項目名稱:Make_Money_with_Tensorflow,代碼行數:32,代碼來源:sample_client.py

示例9: do_inference

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def do_inference(hostport, work_dir, concurrency, num_tests):
  """Tests PredictionService with concurrent requests.

  Args:
    hostport: Host:port address of the PredictionService.
    work_dir: The full path of working directory for test data set.
    concurrency: Maximum number of concurrent requests.
    num_tests: Number of test images to use.

  Returns:
    The classification error rate.

  Raises:
    IOError: An error occurred processing test data set.
  """
  test_data_set = mnist_input_data.read_data_sets(work_dir).test
  host, port = hostport.split(':')
  channel = implementations.insecure_channel(host, int(port))
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  result_counter = _ResultCounter(num_tests, concurrency)
  for _ in range(num_tests):
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'mnist'
    request.model_spec.signature_name = 'predict'
    image, label = test_data_set.next_batch(1)
    request.inputs['inputs'].CopyFrom(
        tf.contrib.util.make_tensor_proto(image[0], shape=[1, 28, 28, 1]))
    result_counter.throttle()
    result_future = stub.Predict.future(request, 5.0)  # 5 seconds
    result_future.add_done_callback(
        _create_rpc_callback(label[0], result_counter))
  return result_counter.get_error_rate() 
開發者ID:llSourcell,項目名稱:Make_Money_with_Tensorflow,代碼行數:34,代碼來源:mnist_client.py

示例10: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main(_):
    if not FLAGS.text:
        raise ValueError("No --text provided")
    host, port = FLAGS.server.split(':')
    channel = implementations.insecure_channel(host, int(port))
    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
    request = Request(FLAGS.text, FLAGS.ngrams)
    result = stub.Classify(request, 10.0)  # 10 secs timeout
    print(result) 
開發者ID:apcode,項目名稱:tensorflow_fasttext,代碼行數:11,代碼來源:predictor_client.py

示例11: run

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def run():
  channel = implementations.insecure_channel('localhost', 50051)
  stub = helloworld_pb2.beta_create_Greeter_stub(channel)
  response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS)
  print "Greeter client received: " + response.message 
開發者ID:Akagi201,項目名稱:learning-python,代碼行數:7,代碼來源:greeter_client.py

示例12: do_inference

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def do_inference(num_tests, concurrency=1):
  channel = implementations.insecure_channel(host, int(port))
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

  coord = _Coordinator(num_tests, concurrency)

  for _ in range(num_tests):
    # dummy audio
    duration, sr, n_fft, win_length, hop_length, n_mels, max_db, min_db = 4, 16000, 512, 512, 128, 80, 35, -55
    filename = librosa.util.example_audio_file()
    wav = read_wav(filename, sr=sr, duration=duration)
    mel = wav2melspec_db(wav, sr, n_fft, win_length, hop_length, n_mels)
    mel = normalize_db(mel, max_db=max_db, min_db=min_db)
    mel = mel.astype(np.float32)
    mel = np.expand_dims(mel, axis=0)  # single batch
    n_timesteps = sr / hop_length * duration + 1

    # build request
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'voice_vector'
    request.model_spec.signature_name = 'predict'
    request.inputs['x'].CopyFrom(tf.contrib.util.make_tensor_proto(mel, shape=[1, n_timesteps, n_mels]))

    coord.throttle()

    # send asynchronous response (recommended. use this.)
    result_future = stub.Predict.future(request, 10.0)  # timeout
    result_future.add_done_callback(_create_rpc_callback(coord))

    # send synchronous response (NOT recommended)
    # result = stub.Predict(request, 5.0)

  coord.wait_all_done() 
開發者ID:andabi,項目名稱:voice-vector,代碼行數:35,代碼來源:client.py

示例13: main

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def main(_):
    host, port = FLAGS.server.split(':')
    channel = implementations.insecure_channel(host, int(port))
    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
    # Send request
    image = tf.gfile.FastGFile(FLAGS.image, 'rb').read()
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'tensorflow-serving'
    request.model_spec.signature_name = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
    request.inputs['image'].CopyFrom(tf.contrib.util.make_tensor_proto(image))
    #request.inputs['input'].CopyFrom()

    result = stub.Predict(request, 10.0)  # 10 secs timeout
    print(result) 
開發者ID:microsoft,項目名稱:MMdnn,代碼行數:16,代碼來源:client.py

示例14: _open_tf_server_channel

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def _open_tf_server_channel(server_name, server_port):
    channel = implementations.insecure_channel(
        server_name,
        int(server_port))
    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

    return stub 
開發者ID:carlomazzaferro,項目名稱:kryptoflow,代碼行數:9,代碼來源:tf_serving_client.py

示例15: connect

# 需要導入模塊: from grpc.beta import implementations [as 別名]
# 或者: from grpc.beta.implementations import insecure_channel [as 別名]
def connect(self):
        for i in range(self.pool_size):
            channel = implementations.insecure_channel(self.host, self.port)
            stub = server_pb2.beta_create_SimpleService_stub(channel)
            # we need to make channels[i] == stubs[i]->channel
            self.channels.append(channel)
            self.stubs.append(stub) 
開發者ID:qiajigou,項目名稱:c3po-grpc-gateway,代碼行數:9,代碼來源:client.py


注:本文中的grpc.beta.implementations.insecure_channel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。