Hi,
I was creating the data for CNN model using the following format:
## Get the location of the image and list of class

img_data_dir = "/Flowers"

## Get the contents in the image folder. This gives the folder list of each image "class"

contents = os.listdir(img_data_dir)

## This gives the classes of each folder. We will use these classes to classify each image type

classes = [each for each in contents if os.path.isdir(img_data_dir + "/" + each)]


batch = [] ## Empty list of image list
labels = []  ## Empty image labels list

for each in classes:  ## looping over each class
	

	class_path = img_data_dir + "/" + each  ## create the path of each image class

	files = os.listdir(class_path)  ## list of all files in each image class folder

	for ii, file in enumerate(files, 1):  ## Enumerate over each image list

		img = skimage.io.imread(os.path.join(class_path, file))  ## each the images from the folder. We are passing the file path + name in "imread"
		img = img / 255.0 ## standardize the data

		batch.append(img.reshape(1, 224, 224, 3))  ## reshaping images and append in one file list
		labels.append(each) ## appending the labels of each image


trX, teX, trY, teY = train_test_split(batch, labels, test_size=0.2, random_state=0)

But when I’m running the CNN model, I’m getting the following error:

image.png694×132 21 KB

Following this 14 method, I tried
trX = torch.stack(trX).float()
But I was getting the following error:

image.png731×206 34 KB

Could anyone please help me how to convert list of images into tensor, so that I can incorporate it into CNN models?
Thank you!