Posts

Showing posts with the label gather

tf.gather_nd is really slow when used for many times

tf.gather_nd is really slow when used for many times I would like a loss function in tensorflow which is a complex combination of many elements. For example, this code: import tensorflow as tf import numpy as np import time input_layer = tf.placeholder(tf.float64, shape=[64,4]) output_layer = input_layer + 0.5*tf.tanh(tf.Variable(tf.random_uniform(shape=[64,4], minval=-1,maxval=1,dtype=tf.float64))) # random_combination is 2-d numpy array of the form: # [[32, 34, 23, 56],[23,54,33,21],...] random_combination = np.random.randint(64, size=(210000000, 4)) # a collector to collect the values collector= print('start looping') print(time.asctime(time.localtime(time.time()))) # loop through random_combination and pick the elements of output_layer for i in range(len(random_combination)): [i,j,k,l] = [random_combination[i][0],random_combination[i][1], random_combination[i][2],random_combination[i][3]] # pi...