python - Tensorflow Grab Predictions and Indices for values above thresholds -


what easiest way grab corresponding prediction values , indices based on above threshold?

consider problem:

sess = tf.interactivesession()  predictions = tf.constant([[ 0.32957435,  0.82079124,  0.54503286,  0.51966476,  0.63359714,          0.92034972,  0.13774526,  0.45154464,  0.18284607,  0.14604568],        [ 0.78612137,  0.98291659,  0.4841609 ,  0.63260579,  0.21568334,          0.82978213,  0.05054879,  0.09517837,  0.28309393,  0.01788473],        [ 0.05706763,  0.24366784,  0.04608512,  0.32987678,  0.2342416 ,          0.91725373,  0.60084391,  0.51787591,  0.74161232,  0.30830121],        [ 0.67310858,  0.6250236 ,  0.42477703,  0.37107778,  0.65123832,          0.97282803,  0.59533679,  0.49564457,  0.54935825,  0.63008392],        [ 0.70233917,  0.48129809,  0.59114349,  0.63535333,  0.71188867,          0.4799161 ,  0.90896237,  0.86089945,  0.47896886,  0.83451629],        [ 0.82923532,  0.8950938 ,  0.99231505,  0.05526769,  0.98151541,          0.18153167,  0.63851702,  0.07426929,  0.91846335,  0.81246626],        [ 0.12850153,  0.23018432,  0.29871917,  0.71228445,  0.13235569,          0.41061044,  0.98215759,  0.90024149,  0.53385031,  0.92247963],        [ 0.87011361,  0.44218826,  0.01772344,  0.87317121,  0.52231467,          0.86476815,  0.25352192,  0.31709731,  0.38249743,  0.74694788],        [ 0.15262914,  0.49544573,  0.49644637,  0.07461977,  0.13706958,          0.18619633,  0.86163998,  0.03700352,  0.51173556,  0.40018845]])  score_idx = tf.where(predictions > 0.8)  scores = tf.sparsetensor(prediction_idx, tf.gather_nd(predictions, score_idx), dense_shape=tf.shape(predictions, out_type=tf.int64))  scores.eval() 

i can sparse tensor has of predictions above 0.8, looking return 2 separate 1d tensors:

  • predicted indices = list of indexes above threshold (0.8 in example)
  • scores = scores corresponding examples

so first row is:

[ 0.32957435,  0.82079124,  0.54503286,  0.51966476,  0.63359714,          0.92034972,  0.13774526,  0.45154464,  0.18284607,  0.14604568] 

i looking return:

  • predicted_indices = [1,5]
  • scores = [0.821, 0.920]

is there simple solution missing?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -