Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. def run_predictions(sess, image_data, softmax_tensor, QP, idx, classNo, sheet, style, gt_label_list, wb):
  2.     global row1
  3.     # Input the image, obtain the softmax prob value(one shape=(1,1008) vector)
  4. #    predictions = sess.run(softmax_tensor,{'DecodeJpeg/contents:0': image_data}) # n, m, 3
  5.     predictions = sess.run(softmax_tensor,{'Cast:0': image_data}) # n, m, 3
  6.     # (1, 1008)->(1008,)
  7.     predictions = np.squeeze(predictions)
  8.  
  9.     # ID --> English string label.
  10.     node_lookup = NodeLookup()
  11.     N = -1008
  12.  
  13.     # Current_rank = -1
  14.     current_rank = -1
  15.  
  16.  
  17.     # print(gt_label_list[998:1005])
  18.     # print(gt_label_list[idx], (idx))
  19.     #(top-5)
  20.     top_5 = predictions.argsort()[N:][::-1]
  21.     for rank, node_id in enumerate(top_5):
  22.         human_string = node_lookup.id_to_string(node_id)
  23.         score = predictions[node_id]
  24.         # if rank < 5:
  25.         #     print('%d: %s (score = %.5f)' % (1 + rank, human_string, score))
  26.  
  27.         if(gt_label_list[idx+1] == human_string):
  28.             print('%d: %s (score = %.5f)' % (1 + rank, human_string, score))
  29.  
  30.             # Write the rank and the score
  31.             row = idx+1
  32.             # col = 4 + 2 * int((QP % 22) / 5)
  33.             col = 4
  34.  
  35.             # Append the coloumn
  36.             for i in range(22, QP, 5):
  37.                 col = col + 2
  38.  
  39.             # Set the current rank (rank starts from 0)
  40.             current_rank = 1 + rank
  41.  
  42.             # print(row, col)
  43.             sheet.write(row, col, current_rank, style)
  44.             sheet.write(row, 1 + col, score.item(), style)
  45.             wb.save(path_to_excel)
  46.             # Stop looping once you find it in the rank
  47.             break
  48.     col1 = 3
  49.     # Append the coloumn
  50.     for i in range(22, QP, 5):
  51.         col1 = col1 + 3
  52.     sheet1.write(row1, col1, current_rank, style1)
  53.     sheet1.write(row1, 1 + col1, score.item(), style1)
  54.     for idx1, rank_top5 in zip(range(row1+1,row1+6), top_5):
  55.         sheet1.write(idx1, col1-1, int(rank_top5), style1)
  56.         sheet1.write(idx1, col1, node_lookup.id_to_string(rank_top5), style1)
  57.         sheet1.write(idx1, col1+1, float(predictions[rank_top5]), style1)
  58.         print('Top-5 -- NOde_ID: %d : %s (score = %.20f)' % (int(rank_top5), node_lookup.id_to_string(rank_top5), float(predictions[rank_top5])))
  59.     # wb1.save(path_to_excel1)
  60.     return current_rank
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement