2024-06-12 08:53:25 发布
网友
我有一个k-fold train数据集,但其结构有一个孙子文件夹,用于:
/monkey / howler monkey - img1 - img2 / japanese macaque - img1 - img2 /dog / bulldog - img1 - img2 / Rottweiler - img1 - img2
在这种情况下,当我使用ImageDataGenerator{}时。找到了8个img,但该类有2个img,而不是4个img。我怎样才能上4节课
ImageDataGenerator
这个问题我已经问了很长时间了,我无法用.flow_from_directory直接找到答案。我所做的是使用.flow_from_dataframe。首先,我刚刚创建了一个带有图像路径及其相应标签的数据框(在您的例子中是howler monkey、japanese macque等)。制作此数据帧时,您不会在任何点实际加载图像
.flow_from_directory
.flow_from_dataframe
事情会是这样的:
images_paths_label = [] for root_class in os.listdir(root_folder): temp_class = os.path.join(root_folder, root_class) for class in os.listdir(temp_class): temp_subclass = os.path.join(temp_class, class) for image in os.listdir(temp_subclass): temp_img_path = os.path.join(temp_subclass, image) images_paths_label.append([temp_img_path, class]) df = pd.DataFrame(images_paths_label, columns = ['image_path', 'label']) # Now the flow_from_dataframe part generator = ImageDataGenerator(validation_split = 0.2) train_generator = generator.flow_from_directory(df, directory = None, x_col = 'image_path', y_col = 'label', seed = 14,...)
您给出了directory = None,因为您在数据帧的image_path列中放置了一个绝对路径。指定种子是因为默认情况下shuffle= True,它应该是真的,因为您的数据帧样本是按类排序的。在这里设置种子,可以确保验证数据保持不变
directory = None
image_path
shuffle= True
这将使您全面了解如何在仍然使用生成器的情况下克服此问题。如果发现任何问题,请告诉我
这个问题我已经问了很长时间了,我无法用
.flow_from_directory
直接找到答案。我所做的是使用.flow_from_dataframe
。首先,我刚刚创建了一个带有图像路径及其相应标签的数据框(在您的例子中是howler monkey、japanese macque等)。制作此数据帧时,您不会在任何点实际加载图像事情会是这样的:
您给出了
directory = None
,因为您在数据帧的image_path
列中放置了一个绝对路径。指定种子是因为默认情况下shuffle= True
,它应该是真的,因为您的数据帧样本是按类排序的。在这里设置种子,可以确保验证数据保持不变这将使您全面了解如何在仍然使用生成器的情况下克服此问题。如果发现任何问题,请告诉我
相关问题 更多 >
编程相关推荐