You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtensorflowimportkerasimportnumpyasnpX_test_data= [np.random.rand(20, 20, 1).astype(np.float32) for_inrange(5)]
y_test_data= [np.random.randint(0, 2, (20, 20, 1)).astype(np.float32) for_inrange(5)]
classSimpleDataLoader(keras.utils.Sequence):
def__init__(
self,
x_data,
y_data,
batch_size=1,
shuffle=True,
):
self.x_data=x_dataself.y_data=y_dataself.batch_size=batch_sizeself.shuffle=shuffleself.on_epoch_end()
def__len__(self):
returnint(np.floor(len(self.x_data) /self.batch_size))
def__getitem__(self, index):
print(f"__getitem__ called with index: {index})")
indices=self.indices[index*self.batch_size:(index+1) *self.batch_size]
x_batch= [self.x_data[k] forkinindices]
y_batch= [self.y_data[k] forkinindices]
ifnotx_batch:
print(f"Warning: x_batch is empty for index {index})")
ifnoty_batch:
print(f"Warning: y_batch is empty for index {index})")
X=np.stack(x_batch, axis=0)
y=np.stack(y_batch, axis=0)
returnX, ydefon_epoch_end(self):
self.indices=np.arange(len(self.x_data))
ifself.shuffle:
np.random.shuffle(self.indices)
batch_size=1vl=SimpleDataLoader(
x_data=X_test_data,
y_data=y_test_data,
batch_size=1,
shuffle=False,
)
print(len(vl))
forx, yinvl:
print(f"Shape: x={x.shape}, y={y.shape}")
The length of the input is simply 5, if for validation, it should stop after iterating over the dataset but it keeps trying more and ended up error.
5
__getitem__ called with index: 0)
Shape: x=(1, 20, 20, 1), y=(1, 20, 20, 1)
__getitem__ called with index: 1)
Shape: x=(1, 20, 20, 1), y=(1, 20, 20, 1)
__getitem__ called with index: 2)
Shape: x=(1, 20, 20, 1), y=(1, 20, 20, 1)
__getitem__ called with index: 3)
Shape: x=(1, 20, 20, 1), y=(1, 20, 20, 1)
__getitem__ called with index: 4)
Shape: x=(1, 20, 20, 1), y=(1, 20, 20, 1)
__getitem__ called with index: 5)
Warning: x_batch is empty for index 5)
Warning: y_batch is empty for index 5)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_31/1498463694.py in<cell line: 0>()
54
55 print(len(vl))
---> 56 forx, yin vl:
57 print(f"Shape: x={x.shape}, y={y.shape}")
/tmp/ipykernel_31/1498463694.py in __getitem__(self, index)
34 print(f"Warning: y_batch is empty for index {index})")
35
---> 36 X = np.stack(x_batch, axis=0)
37 y = np.stack(y_batch, axis=0)
38
/usr/local/lib/python3.11/dist-packages/numpy/core/shape_base.py in stack(arrays, axis, out, dtype, casting)
443 arrays = [asanyarray(arr) forarrin arrays]
444 if not arrays:
--> 445 raise ValueError('need at least one array to stack')
446
447 shapes = {arr.shape forarrin arrays}
ValueError: need at least one array to stack
The text was updated successfully, but these errors were encountered:
Code
The length of the input is simply 5, if for validation, it should stop after iterating over the dataset but it keeps trying more and ended up error.
The text was updated successfully, but these errors were encountered: