tensorflow: how to do numpy-like range with a tensor -


def inference(arg1, arg2):      #something      x in np.range(arg2):           #to 

in above code, define model, , want range in arg2, numpy: for in numpy.range(arg2), problem arg2 tensor, maybe tf.placeholder(), how??

edit:

in fact, code this:

def inference(arg1, arg2):    #to     return loss  loss = inference(arg1, arg2) #do tf.optimizer   sess = tf.session() sess.run() 

so first question in function inference() can define session, , call session.run() again?

second, this, turns out that: tensorflow.python.framework.errors.invalidargumenterror: cannot assign device node 'tower_3/train/shuffle_batch/random_shuffle_queue': not satisfy explicit device specification '/device:gpu:3' because no supported kernel gpu devices available. colocation debug info: colocation group had following types , 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"]()]] same problem on cpu

so not know, in tensorflow many functions tf.range() accept python int, when have tensor, can do? makes me crazy

edit again

for example, mnist in tutorials, model defined in function inference() uses tf.placeholder(), in funciont run_training() of fully_connected_feed.py, feed images , labels, sess.run(), in function inference(), if want tensor images code:

sess = tf.session() sess.run(images) 

it turn out:

tensorflow.python.framework.errors.invalidargumenterror: must feed value placeholder tensor 'placeholder' dtype float , 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"]()]]

it looks in moment, there no image has been feed tensor images

edit again again

i doing nlp, arg1 maybe sentence diffrent length, have make max_len, while record real length in arg2

it's encoder , decoder program using lstm, in phase of decoder, want add attention model, must know length of sentence compute importance of every word in sentence, length tensor, can not like:

for x in len:    #do 

you can run evaluation on tensor value:

def inference(arg1, arg2):     sess.as_default():         #something         x in np.range(arg2.eval()):             #to 

or:

def inference(arg1, arg2):     #something     x in np.range(sess.run(arg2)):         #to 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -