当前位置: 首页>>代码示例>>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;未经允许,请勿转载。