Hello,
I am having an issue with the first step of the assignment. I am having an error that says the batch is not the right shape…
Code is:
def windowed_dataset(series, window_size, shuffle=True):
print(series)
"""Create a windowed dataset
Args:
series (np.ndarray): time series
window_size (int): length of window to use for prediction
shuffle (bool): (For testing purposes) Indicates whether to shuffle data before batching or not. Defaults to True
Returns:
td.data.Dataset: windowed dataset
"""
### START CODE HERE ###
# mentor edit: code removed
### END CODE HERE ###
return dataset
Error is:
2 test_dataset = windowed_dataset(series_train, window_size=10,shuffle= False)
4 # Get the first batch of the test dataset
----> 5 batch_of_features, batch_of_labels = next((iter(test_dataset)))
7 print(f"batch_of_features has type: {type(batch_of_features)}\n")
8 print(f"batch_of_labels has type: {type(batch_of_labels)}\n")
File /opt/conda/lib/python3.11/site-packages/tensorflow/python/data/ops/iterator_ops.py:809, in OwnedIterator.next(self)
807 def next(self):
808 try:
→ 809 return self._next_internal()
810 except errors.OutOfRangeError:
811 raise StopIteration
File /opt/conda/lib/python3.11/site-packages/tensorflow/python/data/ops/iterator_ops.py:772, in OwnedIterator._next_internal(self)
769 # TODO(b/77291417): This runs in sync mode as iterators use an error status
770 # to communicate that there is no more data to iterate over.
771 with context.execution_mode(context.SYNC):
→ 772 ret = gen_dataset_ops.iterator_get_next(
773 self._iterator_resource,
774 output_types=self._flat_output_types,
775 output_shapes=self._flat_output_shapes)
777 try:
778 # Fast path for the case self._structure
is not a nested structure.
779 return self._element_spec._from_compatible_tensor_list(ret) # pylint: disable=protected-access
File /opt/conda/lib/python3.11/site-packages/tensorflow/python/ops/gen_dataset_ops.py:3086, in iterator_get_next(iterator, output_types, output_shapes, name)
3084 return _result
3085 except _core._NotOkStatusException as e:
→ 3086 _ops.raise_from_not_ok_status(e, name)
3087 except _core._FallbackException:
3088 pass
File /opt/conda/lib/python3.11/site-packages/tensorflow/python/framework/ops.py:5983, in raise_from_not_ok_status(e, name)
5981 def raise_from_not_ok_status(e, name) → NoReturn:
5982 e.message += (" name: " + str(name if name is not None else “”))
→ 5983 raise core._status_to_exception(e) from None
InvalidArgumentError: {{function_node _wrapped__IteratorGetNext_output_types_2_device/job:localhost/replica:0/task:0/device:CPU:0}} Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [0], [batch]: [9] [Op:IteratorGetNext] name:
I have been looking back through the code and having a grand conversation with ChatGPT, and haven’t been able to see the flaw. I am sure it is something stupid…