I’ve been trying to feed windows of data into a Conv1D network followed by an LSTM. I keep having data shape errors and want to understand what is being passed into the network.
When I use tf.rank on the windowed dataset I get this error:
ValueError: Attempt to convert a value (<PrefetchDataset element_spec=(TensorSpec(shape=(None, None, 7), dtype=tf.float64, name=None), TensorSpec(shape=(None, None, 7), dtype=tf.float64, name=None))>) with an unsupported type (<class 'tensorflow.python.data.ops.dataset_ops.PrefetchDataset'>) to a Tensor
This is returned when I apply tf.rank() to the dataset returned by the function below. “series” is a time-series of seven variables:
They implement a windowing function (below) where they comment that “Slicing does not preserve static shape information, so set the shapes manually. That way the ‘tf.data.Datasets’ are easier to inspect.”
Note: This calls a class WindowGenerator defined earlier in the tutorial that defines indexes and offsets for the desired window.
def split_window(self, features):
inputs = features[:, self.input_slice, :]
labels = features[:, self.labels_slice, :]
if self.label_columns is not None:
labels = tf.stack(
[labels[:, :, self.column_indices[name]] for name in self.label_columns],
# Slicing doesn't preserve static shape information, so set the shapes
# manually. This way the `tf.data.Datasets` are easier to inspect.
inputs.set_shape([None, self.input_width, None])
labels.set_shape([None, self.label_width, None])
return inputs, labels
The tf.rank function cannot be applied directly to the dataset object returned by the windowed_dataset function. tf.rank is used to return the rank of a tensor, which is the number of dimensions it has.A dataset object is not a tensor.
Want to understand what is being passed into the network?
You can use the element_spec attribute of the dataset object. You can use ds.element_spec to get the type and shape of the elements in your dataset.