TensorFlow的tensor如何转换为ndarray?
yolo_model.predict返回的是tensor,但我后续做cpu_nms时要求输入的是ndarray类型,我尝试过用.eval()(可能是我写的不对?),但是会出现FailedPreconditionError的错误
img = np.asarray(img, np.float32)img = img[np.newaxis, :] / 255.
with tf.Session() as sess:
input_data = tf.placeholder(tf.float32, [1, args.new_size[1], args.new_size[0], 3], name='input_data')
yolo_model = yolov3(args.num_class, args.anchors)
with tf.variable_scope('yolov3'):
pred_feature_maps = yolo_model.forward(input_data, False)
pred_boxes, pred_confs, pred_probs = yolo_model.predict(pred_feature_maps)
pred_scores = pred_confs * pred_probs
# pred_boxes = pred_boxes.eval()
# pred_scores = pred_scores.eval()
boxes, scores, labels = cpu_nms(pred_boxes, pred_scores, args.num_class, max_boxes=200, score_thresh=0.3, iou_thresh=0.45)
saver = tf.train.Saver()
saver.restore(sess, args.restore_path)
boxes_, scores_, labels_ = sess.run([boxes, scores, labels], feed_dict={input_data: img})
谢谢
以上是 TensorFlow的tensor如何转换为ndarray? 的全部内容, 来源链接: utcz.com/a/159513.html