[grpc-io] grpc mnist with tensroflow "Tensor("Const:0", shape=(1,), dtype=int32) must be from the same graph"

2018-01-11 Thread heidi
Hello.
When I run tensorflow on grpc, it fails. Is it a thread problem?
Or is it a problem with the tensroflow code?
Can I run the tensorflow code with grpc?

I used a very simple example of mnist tensroflow.
However, the following error occurs.

Tensor("Const:0", shape=(1,), dtype=int32) must be from the same graph as 
Tensor("Cast:0", shape=(?,), dtype=float32).

-mnist code--

# MNIST 데이터를 다운로드 한다.
from tensorflow.examples.tutorials.mnist import input_data


# TensorFlow 라이브러리를 추가한다.
import tensorflow as tf


class tensormnist(object):

  def __init__(self):
self.mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

  def set(self):
# 변수들을 설정한다.
self.x = tf.placeholder(tf.float32, [None, 784])
self.W = tf.Variable(tf.zeros([784, 10]))
self.b = tf.Variable(tf.zeros([10]))
self.y = tf.nn.softmax(tf.matmul(self.x, self.W) + self.b)

# cross-entropy 모델을 설정한다.
self.y_ = tf.placeholder(tf.float32, [None, 10])
self.cross_entropy = tf.reduce_mean(-tf.reduce_sum(self.y_ * 
tf.log(self.y), reduction_indices=[1]))
self.train_step = 
tf.train.GradientDescentOptimizer(0.5).minimize(self.cross_entropy)
# 경사하강법으로 모델을 학습한다.
self.init = tf.global_variables_initializer()
self.sess = tf.Session()

  def teinmnist(self):

self.sess.run(self.init)
for i in range(1000):
  batch_xs, batch_ys = self.mnist.train.next_batch(100)
  self.sess.run(self.train_step, feed_dict={self.x: batch_xs, self.y_: 
batch_ys})

  def mnistrun(self):
print('self.sess,',self.sess)
correct_prediction = tf.equal(tf.argmax(self.y,1), tf.argmax(self.y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print(self.sess.run(accuracy, feed_dict={self.x: self.mnist.test.images, 
self.y_: self.mnist.test.labels}))


---mnist code end-



-server code---



from concurrent import futures
import time
import os

import grpc

import helloworld_pb2
import helloworld_pb2_grpc

from mnist_test import tensormnist

_ONE_DAY_IN_SECONDS = 60 * 60 * 24


class Greeter(helloworld_pb2_grpc.GreeterServicer):
  def __init__(self):

self.tclass = tensormnist()
self.tclass.set()
self.tclass.teinmnist()
print('mnist model load...')


  def SayHello(self, request, context):
print('[{0}]SayHello request.name: {1}'.format(os.getpid(), 
request.name))
try:
  self.tclass.mnistrun()
except Exception as e:
  print(e)

return helloworld_pb2.HelloReply(message='Hello %s %s' % (str(os.getpid()), 
request.name))


def serve():
  server = grpc.server(futures.ThreadPoolExecutor(max_workers=24))
  helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
  server.add_insecure_port('0.0.0.0:5000')
  server.start()
  print(" SERVER RUNNING =")
  try:
#pass
while True:
  time.sleep(_ONE_DAY_IN_SECONDS)
  except KeyboardInterrupt:
server.stop(0)

if __name__ == '__main__':

  serve()


server code end-



-client code ---



from __future__ import print_function

import os
import grpc

import helloworld_pb2
import helloworld_pb2_grpc


def run():
  print('client run')
  channel = grpc.insecure_channel('localhost:5000')
  stub = helloworld_pb2_grpc.GreeterStub(channel)

  response = stub.SayHello(helloworld_pb2.HelloRequest(name=str(os.getpid(
  print("Greeter client received: " + response.message)

  return response.message


if __name__ == '__main__':
  run()



from __future__ import print_function

import os
import grpc

import helloworld_pb2
import helloworld_pb2_grpc


def run():
  print('client run')
  channel = grpc.insecure_channel('localhost:5000')
  stub = helloworld_pb2_grpc.GreeterStub(channel)

  response = stub.SayHello(helloworld_pb2.HelloRequest(name=str(os.getpid(
  print("Greeter client received: " + response.message)

  return response.message


if __name__ == '__main__':
  run()

--client code end--




Thnaks!

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/031b168f-2694-43ae-ae07-6f1311f9ce67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[grpc-io] [python]How to run python packages with gprc

2018-01-09 Thread heidi
How do I configure grpc to impersonate a Python package or xxx.py file?
I ran the helloworld example.
I want to implement some specific logic with grpc. Certain logic is written 
in Python.
When requested by the clien.pyt, the server.py wants to execute the Python 
package.

How do I implement grpc to execute xxx.py instead of a simple print 
function?

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/2b6cb107-b884-4bd7-8235-fe857f740d36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] python grpc worker or thread setting

2018-01-09 Thread heidi
Thanks for the reply.
As you said, I confirmed that it runs concurrently through the time.sleep 
() function.
It seems to run concurrently internally.
However, adding the function below is not simultaneous.
I printed a pid, which has the same pid.


  server.py  ---

def SayHello(self, request, context):

## run function
a = my_class().detect_face() ##<
> If you add a 3 second sleep to SayHello and then run 
>
> python client.py & python client.py & python client.py & wait
>
> Does this command take 9 seconds? I would expect it to take 3.
>
> On Thu, Jan 4, 2018 at 7:19 PM, <he...@snaps.com > wrote:
>
>> my server.py code:
>>
>>
>>
>> 
>> from concurrent import futures
>> import time
>> import os
>> import grpc
>>
>> import helloworld_pb2
>> import helloworld_pb2_grpc
>>
>>
>> ## my function
>> from my_function import my_class
>>
>> _ONE_DAY_IN_SECONDS = 60 * 60 * 24
>>
>>
>> class Greeter(helloworld_pb2_grpc.GreeterServicer):
>>
>>   def SayHello(self, request, context):
>>
>> ## run function
>> a = my_class().detect_face()
>>
>> return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
>>
>>
>> def serve():
>>   server = grpc.server(futures.ThreadPoolExecutor(max_workers=20))
>>   helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
>>   server_port = os.environ.get('PORT', 50051)
>>   server.add_insecure_port('[::]:' + str(server_port))
>>   server.start()
>>
>>
>>   print(" SERVER RUNNING =")
>>   try:
>> while True:
>>   time.sleep(_ONE_DAY_IN_SECONDS)
>>   except KeyboardInterrupt:
>> server.stop(0)
>>
>> if __name__ == '__main__':
>>
>>   serve()
>>
>>
>> 
>>
>> Like my code, I set the number of worker to 20.
>> And I added my function inside SayHello code.
>> When I run server.py and run client.py, there is no error.
>> There are 20 workers, but it slows down when I request client.py at the 
>> same time.
>>
>> Only three requests at the same time are three times slower.
>> Thank you.
>>
>>
>>
>>
>>
>>
>> 2018년 1월 5일 금요일 오전 11시 39분 45초 UTC+9, Ken Payson 님의 말:
>>>
>>>
>>>
>>> On Thu, Jan 4, 2018 at 6:25 PM, <he...@snaps.com> wrote:
>>>
>>>> Hi! I'm Heidi.
>>>> I'm trying to build an api with python.
>>>> I try to build with grpc.
>>>> Post the image file to grpc server.
>>>> The gprc server detects the object by deep-running the requested image 
>>>> file.
>>>>
>>>> First question: How do I transfer an image file to the server?
>>>>
>>> The easiest way to do this to convert the image to a string, and create 
>>> a simple protobuf with a string field.
>>>
>>> This might not be practical depending on the size of your images, but 
>>> its a good place to start.  You can
>>> explore using a streaming API if your images are too large.
>>>
>>>
>>>> Show me an example.
>>>> For example, when sending a string:
>>>> response = stub.SayHello (helloworld_pb2.HelloRequest (name = 'you'))
>>>>
>>>>
>>>> Second question. I want to request grpc server concurrently, not 
>>>> sequential. What should I do?
>>>>
>>>> I run one server .py. Then I run client.py at the same time. But it 
>>>> seems to be running sequentially.
>>>> For example, one client.py
>>>>
>>>> Second question. I want to request grpc server concurrently, not 
>>>> sequential. What should I do?
>>>>
>>>> I run one server .py. Then I run client.py at the same time. But it 
>>>> seems to be running sequentially.
>>>> For example, it takes 1 second to run one client.py.
>>>> But if you run 3 client.py at the same time, it takes 3 seconds.
>>>>
>>>>
>>>> I want to know how to set up grpc worker or thread. Please let me know 
>>>> python code example.
>>>>
>>>
>>> Python gRPC servers can handle concurrent requests.  Look at 
>>> examples/python/helloworld/greeter_server.py for an example:
>>>
>>> server = grpc.server(futures.T

[grpc-io] gRPC is it accessible from the external ip?

2018-01-04 Thread heidi
Hi guys.
I want to access the grpc ip in an external environment.

This is my server.py IP configuration.

*server.add_insecure_port ('192. ***. ***. ***: 5000')*


And this is the client.py IP configuration.

*channel = grpc.insecure_channel ('192. ***. ***. ***: 5000')*


Running server.py and client.py on the same machine works fine.
However, I get an error when I use a computer that runs server.py and a 
different external ip.

Is it accessible from the external IP?
If so, how do I set it up?
Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/bee2f25b-5d9a-4697-a02f-98f7d0357d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] python grpc worker or thread setting

2018-01-04 Thread heidi
my server.py code:




from concurrent import futures
import time
import os
import grpc

import helloworld_pb2
import helloworld_pb2_grpc


## my function
from my_function import my_class

_ONE_DAY_IN_SECONDS = 60 * 60 * 24


class Greeter(helloworld_pb2_grpc.GreeterServicer):

  def SayHello(self, request, context):

## run function
a = my_class().detect_face()

return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
  server = grpc.server(futures.ThreadPoolExecutor(max_workers=20))
  helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
  server_port = os.environ.get('PORT', 50051)
  server.add_insecure_port('[::]:' + str(server_port))
  server.start()


  print(" SERVER RUNNING =")
  try:
while True:
  time.sleep(_ONE_DAY_IN_SECONDS)
  except KeyboardInterrupt:
server.stop(0)

if __name__ == '__main__':

  serve()




Like my code, I set the number of worker to 20.
And I added my function inside SayHello code.
When I run server.py and run client.py, there is no error.
There are 20 workers, but it slows down when I request client.py at the 
same time.

Only three requests at the same time are three times slower.
Thank you.






2018년 1월 5일 금요일 오전 11시 39분 45초 UTC+9, Ken Payson 님의 말:
>
>
>
> On Thu, Jan 4, 2018 at 6:25 PM, <he...@snaps.com > wrote:
>
>> Hi! I'm Heidi.
>> I'm trying to build an api with python.
>> I try to build with grpc.
>> Post the image file to grpc server.
>> The gprc server detects the object by deep-running the requested image 
>> file.
>>
>> First question: How do I transfer an image file to the server?
>>
> The easiest way to do this to convert the image to a string, and create a 
> simple protobuf with a string field.
>
> This might not be practical depending on the size of your images, but its 
> a good place to start.  You can
> explore using a streaming API if your images are too large.
>
>
>> Show me an example.
>> For example, when sending a string:
>> response = stub.SayHello (helloworld_pb2.HelloRequest (name = 'you'))
>>
>>
>> Second question. I want to request grpc server concurrently, not 
>> sequential. What should I do?
>>
>> I run one server .py. Then I run client.py at the same time. But it seems 
>> to be running sequentially.
>> For example, one client.py
>>
>> Second question. I want to request grpc server concurrently, not 
>> sequential. What should I do?
>>
>> I run one server .py. Then I run client.py at the same time. But it seems 
>> to be running sequentially.
>> For example, it takes 1 second to run one client.py.
>> But if you run 3 client.py at the same time, it takes 3 seconds.
>>
>>
>> I want to know how to set up grpc worker or thread. Please let me know 
>> python code example.
>>
>
> Python gRPC servers can handle concurrent requests.  Look at 
> examples/python/helloworld/greeter_server.py for an example:
>
> server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
>
> max_workers is the number of concurrent requests the Python server can 
> handle.
>
> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "grpc.io" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to grpc-io+u...@googlegroups.com .
>> To post to this group, send email to grp...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/grpc-io.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/grpc-io/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/grpc-io/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/2e5ccc67-4e78-4147-8eec-ac386743fc05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] python grpc worker or thread setting

2018-01-04 Thread heidi
Thank you. I'll check it again.

2018년 1월 5일 금요일 오전 11시 39분 45초 UTC+9, Ken Payson 님의 말:
>
>
>
> On Thu, Jan 4, 2018 at 6:25 PM, <he...@snaps.com > wrote:
>
>> Hi! I'm Heidi.
>> I'm trying to build an api with python.
>> I try to build with grpc.
>> Post the image file to grpc server.
>> The gprc server detects the object by deep-running the requested image 
>> file.
>>
>> First question: How do I transfer an image file to the server?
>>
> The easiest way to do this to convert the image to a string, and create a 
> simple protobuf with a string field.
>
> This might not be practical depending on the size of your images, but its 
> a good place to start.  You can
> explore using a streaming API if your images are too large.
>
>
>> Show me an example.
>> For example, when sending a string:
>> response = stub.SayHello (helloworld_pb2.HelloRequest (name = 'you'))
>>
>>
>> Second question. I want to request grpc server concurrently, not 
>> sequential. What should I do?
>>
>> I run one server .py. Then I run client.py at the same time. But it seems 
>> to be running sequentially.
>> For example, one client.py
>>
>> Second question. I want to request grpc server concurrently, not 
>> sequential. What should I do?
>>
>> I run one server .py. Then I run client.py at the same time. But it seems 
>> to be running sequentially.
>> For example, it takes 1 second to run one client.py.
>> But if you run 3 client.py at the same time, it takes 3 seconds.
>>
>>
>> I want to know how to set up grpc worker or thread. Please let me know 
>> python code example.
>>
>
> Python gRPC servers can handle concurrent requests.  Look at 
> examples/python/helloworld/greeter_server.py for an example:
>
> server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
>
> max_workers is the number of concurrent requests the Python server can 
> handle.
>
> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "grpc.io" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to grpc-io+u...@googlegroups.com .
>> To post to this group, send email to grp...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/grpc-io.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/grpc-io/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/grpc-io/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/fe2fb006-1561-4f02-9841-1fdbd4d4c586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[grpc-io] python grpc worker or thread setting

2018-01-04 Thread heidi
Hi! I'm Heidi.
I'm trying to build an api with python.
I try to build with grpc.
Post the image file to grpc server.
The gprc server detects the object by deep-running the requested image file.

First question: How do I transfer an image file to the server?

Show me an example.
For example, when sending a string:
response = stub.SayHello (helloworld_pb2.HelloRequest (name = 'you'))


Second question. I want to request grpc server concurrently, not 
sequential. What should I do?

I run one server .py. Then I run client.py at the same time. But it seems 
to be running sequentially.
For example, one client.py

Second question. I want to request grpc server concurrently, not 
sequential. What should I do?

I run one server .py. Then I run client.py at the same time. But it seems 
to be running sequentially.
For example, it takes 1 second to run one client.py.
But if you run 3 client.py at the same time, it takes 3 seconds.


I want to know how to set up grpc worker or thread. Please let me know 
python code example.

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.