......
~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in __call__(self, inputs)
3746 return nest.pack_sequence_as(
3747 self._outputs_structure,
-> 3748 [x._numpy() for x in outputs], # pylint: disable=protected-access
3749 expand_composites=True)
3750
~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in <listcomp>(.0)
3746 return nest.pack_sequence_as(
3747 self._outputs_structure,
-> 3748 [x._numpy() for x in outputs], # pylint: disable=protected-access
3749 expand_composites=True)
3750
ValueError: Cannot convert a Tensor of dtype resource to a NumPy array.
我在TensorFlow 2.0中编写了一个自定义Keras层,当我将张量输入模型时,发生了上述异常。没有定义dtype resource 的张量。此外,当直接使用model.predict(A_NUMPY_ARRAY)
时,该模型也能很好地工作。