获取图像数据集的样本
Taking a sample of the image dataset
例如,我想开发一个用于图像分类的深度学习模型,并且我有数千张图像。由于用整个数据集训练模型需要很长时间,所以我想从原始数据集中抽取样本 (10%) 进行初始训练。如何做到这一点?
如果数据集包含在文件夹中,我将尝试以下操作:
import os
import numpy as np
images = os.listdir('Path to your dataset') # list of all the images
n_test_images = int(len(images) * 0.1) # 10% of the total images
subset_images = np.random.choice(images, size=n_test_images, replace=False)
我使用 replace=True 来避免选择相同的元素两次。
在我选择了 10% 的图像后,我加载它们。
实际上我不确定这种方式是否是最佳方式,但这可能是一个很好的起点。
例如,我想开发一个用于图像分类的深度学习模型,并且我有数千张图像。由于用整个数据集训练模型需要很长时间,所以我想从原始数据集中抽取样本 (10%) 进行初始训练。如何做到这一点?
如果数据集包含在文件夹中,我将尝试以下操作:
import os
import numpy as np
images = os.listdir('Path to your dataset') # list of all the images
n_test_images = int(len(images) * 0.1) # 10% of the total images
subset_images = np.random.choice(images, size=n_test_images, replace=False)
我使用 replace=True 来避免选择相同的元素两次。 在我选择了 10% 的图像后,我加载它们。
实际上我不确定这种方式是否是最佳方式,但这可能是一个很好的起点。