def inference(arg1, arg2):
#something to do
for x in np.range(arg2):
#to do
와 NumPy와 같은 다양한 작업을 수행하는 방법을, 나는 NumPy와 같은 모델을 정의하고 ARG2에 범위 할 : for i in numpy.range(arg2)
는 문제는 ARG2가 텐서입니다 , 어쩌면 tf.placeholder()
에서,하지만 어떻게?tensorflow은 : 위의 코드에서 텐서
편집 : 사실
,이 같은 내 코드 :
def inference(arg1, arg2):
#to do
return loss
loss = inference(arg1, arg2)
#do something about tf.optimizer
sess = tf.Session()
sess.run()
그래서 내 첫 번째 질문은 기능 inference()
내가 세션을 정의하고, 다시) (session.run를 호출 할 수있는?
초, 나는이 작업을 수행하지만, 밝혀 : 단지 파이썬 INT을 받아() tf.range 같은 tensorflow 많은 기능에, 는 CPU에 tensorflow.python.framework.errors.InvalidArgumentError: Cannot assign a device to node 'tower_3/train/shuffle_batch/random_shuffle_queue': Could not satisfy explicit device specification '/device:GPU:3' because no supported kernel for GPU devices is available. Colocation Debug Info: Colocation group had the following types and devices: QueueEnqueue: CPU QueueSize: CPU QueueClose: CPU QueueDequeueMany: CPU RandomShuffleQueue: CPU [[Node: tower_3/train/shuffle_batch/random_shuffle_queue = RandomShuffleQueue[capacity=3, component_types=[DT_INT64, DT_INT64, DT_INT64], container="", min_after_dequeue=0, seed=0, seed2=0, shapes=[[260], [], []], shared_name="", _device="/device:GPU:3"]()]]
같은 문제
그래서 난 잘 모르겠지만, 나는 텐서가있을 때 무엇을 할 수 있습니까? 그것은 나를 미치게
편집을 다시
예를 들어, 튜토리얼의 mnist, 모델이의 funciont fully_connected_feed.py의 run_training()
에서는, tf.placeholder()
을 사용하는 기능 inference()
에 정의되어이 피드 그것은 이미지와 라벨, 다음 sess.run()
, 기능 inference()
에서,이 코드로 텐서 images
을 얻으려면 너무 :
sess = tf.Session()
sess.run(images)
그것이 판명됩니다
,536,913,632 (10)는 그 순간처럼 보이는tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [100,784] [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[100,784], _device="/job:localhost/replica:0/task:0/gpu:0"]()]] [[Node: Placeholder/_2 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_5_Placeholder", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
은 ARG1 어쩌면 문장, 어떤 이미지가 텐서 images
편집 다시 다시
나는 NLP에 대해 뭔가를하고있는 중이 야에 공급되지 않은이 다른 길이와 함께, 그래서 내가 arg2에 실제 길이를 기록하는 동안 max_len을 만들었습니다
디코더의 위상에서 lstm을 사용하는 그것의 인코더와 디코더 프로그램, 나는주의 모델을 추가하고 싶습니다, 그래서 나는 길이를 알아야합니다. imp를 계산하기위한 문장 그 값 얻기 위해 당신은 텐서에 대한 평가를 실행할 수 있습니다
for x in len:
#do something
먼저'session.run'을 사용하여'arg2'를 평가해야합니다. 그건 당신에게 numpy 배열을 다시 제공합니다 –
@ YaroslavBulatov 작동하지 않습니다 – wang
당신은이 루프로 무엇을 하려는지 설명해 주시겠습니까? 'tf.range (arg2)'를 쉽게 만들거나'tf.while()'루프를 사용할 수 있습니다. 그것은 당신이 루프 안에서 무엇을하려고하는지에 달려 있습니다. –