Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python InvalidArgumentError:必须为占位符张量';占位符1';使用数据类型float和shape[?,?,3]_Python_Tensorflow - Fatal编程技术网

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,问题就解决了