Ad

Paralleling Python 'for' Loop With 'if' Statement Using TensorFlow

- 1 answer

Could anyone please help convert this code to TensorFlow? I am attempting to find the data point positions in the set for which the CNN outputs a value bigger than 0.95, so as to aid in pseudo-labeling.

   positions = []

   for t in range(int(dataset.shape[0] // batch_size)):
        data = dataset.next_batch
        model_output = sess.run([output], feed_dict={model_input_pl: data})

        for i in range(model_output[0].shape[0]):
            if model_output[0][i][some_nodal_position] > 0.95:
                 positions.append(batch_start_position + i)

Paralleling this code would allow for many more models to be tested, but having the code as above takes a long time.

Ad

Answer

This could be implemented as follows:

tf.where(tf.greater(output, 0.95))

This returns a tensor with the indices where output is greater than 0.95.

Ad
source: stackoverflow.com
Ad