Python InvalidArgumentError:必须为占位符张量';占位符1';使用数据类型float和shape[?,?,3]
当我运行下面的代码,试图对测试图像进行预测时,我遇到了这个错误Python InvalidArgumentError:必须为占位符张量';占位符1';使用数据类型float和shape[?,?,3],python,tensorflow,Python,Tensorflow,当我运行下面的代码,试图对测试图像进行预测时,我遇到了这个错误 class HFNet: def __init__(self, model_path, outputs): self.session = tf.Session() self.image_ph = tf.placeholder(tf.float32, shape=(None, None, 3)) net_input = tf.image.rgb_to_grayscale(sel
class HFNet:
def __init__(self, model_path, outputs):
self.session = tf.Session()
self.image_ph = tf.placeholder(tf.float32, shape=(None, None, 3))
net_input = tf.image.rgb_to_grayscale(self.image_ph[None])
tf.saved_model.loader.load(
self.session, [tag_constants.SERVING], str(model_path),
clear_devices=True,
input_map={'image:0': net_input})
graph = tf.get_default_graph()
self.outputs = {n: graph.get_tensor_by_name(n+':0')[0] for n in outputs}
self.nms_radius_op = graph.get_tensor_by_name('pred/simple_nms/radius:0')
self.num_keypoints_op = graph.get_tensor_by_name('pred/top_k_keypoints/k:0')
def inference(self, image, nms_radius=4, num_keypoints=1000):
inputs = {
self.image_ph: image[..., ::-1].astype(np.float),
self.nms_radius_op: nms_radius,
self.num_keypoints_op: num_keypoints,
}
return self.session.run(self.outputs, feed_dict=inputs)
model_path = Path(EXPER_PATH, 'saved_models/hfnet')
outputs = ['global_descriptor', 'keypoints', 'local_descriptors']
hfnet = HFNet(model_path, outputs)
db = [hfnet.inference(i) for i in images_db]
global_index = np.stack([d['global_descriptor'] for d in db])
query = hfnet.inference(image_query)
谢谢您,我们将非常感谢您的帮助。问题是由于Tensorflow版本造成的。我将Tensorflow降级到1.12.0,问题就解决了