How to iterate over a batch?

I’m currently training with this loop

for epoch in range(EPOCH):
	for step, (x, y) in enumerate(train_loader):

However, x and y have the shape of (num_batchs, width, height), where width and height are the number of dimensions in the image. So, how do I iterate over the x and y to get a 3d tensor with the dimensions (1, width, height), for both the x and y, and how do I convert the 3d tensor to a 4d tensor, for a 2d CNN?

Hey, can you try this…

for epoch in range(EPOCH):
    for step, (x, y) in enumerate(train_loader):
        for i in range(len(x)):
             xi = x[i, ...][None, ...]
             yi = y[i, ...][None, ...]

1 Like