I have 4 folders: Cat, Dog, Tiger and Kangaroo, each with 100 images save in the respective folders.
When I use chainer library to import mnist dataset, I get tuple of images and their corresponding labels. I wish to read and bring my dataset in the same format.
Chainer code looks like:
train, test = chainer.datasets.get_mnist()
train_data, train_targets = np.array(train).transpose()
test_data, test_targets = np.array(test).transpose()
train_data = np.array(list(train_data)).reshape(train_data.shape[0],1,28,28)
test_data = np.array(list(test_data)).reshape(test_data.shape[0],1,28,28)
I tried following code but it does not bring the code in same format.
img_dict=dict()
for root, dirs, files in os.walk(path):
print(os.path.basename(root))
my_key = os.path.basename(root)
dir_images = []
for file_ in files:
full_file_path = os.path.join(root, file_)
img = cv2.imread(full_file_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
dir_images.append(img)
img_dict[my_key] = dir_images
What is the correct way to read these images and bring it in the same format as mentioned above for MNIST from chainer library?