Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def run_predictions(sess, image_data, softmax_tensor, QP, idx, classNo, sheet, style, gt_label_list, wb):
- global row1
- # Input the image, obtain the softmax prob value(one shape=(1,1008) vector)
- # predictions = sess.run(softmax_tensor,{'DecodeJpeg/contents:0': image_data}) # n, m, 3
- predictions = sess.run(softmax_tensor,{'Cast:0': image_data}) # n, m, 3
- # (1, 1008)->(1008,)
- predictions = np.squeeze(predictions)
- # ID --> English string label.
- node_lookup = NodeLookup()
- N = -1008
- # Current_rank = -1
- current_rank = -1
- # print(gt_label_list[998:1005])
- # print(gt_label_list[idx], (idx))
- #(top-5)
- top_5 = predictions.argsort()[N:][::-1]
- for rank, node_id in enumerate(top_5):
- human_string = node_lookup.id_to_string(node_id)
- score = predictions[node_id]
- # if rank < 5:
- # print('%d: %s (score = %.5f)' % (1 + rank, human_string, score))
- if(gt_label_list[idx+1] == human_string):
- print('%d: %s (score = %.5f)' % (1 + rank, human_string, score))
- # Write the rank and the score
- row = idx+1
- # col = 4 + 2 * int((QP % 22) / 5)
- col = 4
- # Append the coloumn
- for i in range(22, QP, 5):
- col = col + 2
- # Set the current rank (rank starts from 0)
- current_rank = 1 + rank
- # print(row, col)
- sheet.write(row, col, current_rank, style)
- sheet.write(row, 1 + col, score.item(), style)
- wb.save(path_to_excel)
- # Stop looping once you find it in the rank
- break
- col1 = 3
- # Append the coloumn
- for i in range(22, QP, 5):
- col1 = col1 + 3
- sheet1.write(row1, col1, current_rank, style1)
- sheet1.write(row1, 1 + col1, score.item(), style1)
- for idx1, rank_top5 in zip(range(row1+1,row1+6), top_5):
- sheet1.write(idx1, col1-1, int(rank_top5), style1)
- sheet1.write(idx1, col1, node_lookup.id_to_string(rank_top5), style1)
- sheet1.write(idx1, col1+1, float(predictions[rank_top5]), style1)
- print('Top-5 -- NOde_ID: %d : %s (score = %.20f)' % (int(rank_top5), node_lookup.id_to_string(rank_top5), float(predictions[rank_top5])))
- # wb1.save(path_to_excel1)
- return current_rank
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement