TypeError: Expected tensorflow.python.framework.tensor_spec.TensorSpec, found numpy.ndarray

TypeError: Expected tensorflow.python.framework.tensor_spec.TensorSpec, found numpy.ndarray

In version 0.13.0 the sample_batch parameter was deprecated. The input_spec parameter must be a tff.Type or tf.TensorSpec as per the documentation.

To build a structure of tf.TensorSpec from a numpy.ndarray:

def tensor_spec_from_ndarray(a):
  return tf.TensorSpec(dtype=tf.dtypes.as_dtype(a.dtype),
                       shape=a.shape)

sample_batch = (images,labels)  # assumes images and labels are np.ndarray
input_spec = tf.nest.map_structure(
  tensor_spec_from_ndarray, sample_batch)

TypeError: Expected tensorflow.python.framework.tensor_spec.TensorSpec, found numpy.ndarray

Related Posts

Leave a Reply

Your email address will not be published.