【发布时间】:2021-07-23 06:55:05
【问题描述】:
我是 PyTorch 的新手,正在尝试创建迁移学习模型。
我正在使用来自 Kaggle 的 dogs vs cats dataset。
我正在使用 ImageFolder 加载数据,每个类都需要一个文件夹。但是测试文件夹中的照片是混合的。所以我无法将测试文件夹中的图像分开。除了用手标记所有的测试数据,我还能做些什么来解决这个问题?
【问题讨论】:
标签: pytorch
我是 PyTorch 的新手,正在尝试创建迁移学习模型。
我正在使用来自 Kaggle 的 dogs vs cats dataset。
我正在使用 ImageFolder 加载数据,每个类都需要一个文件夹。但是测试文件夹中的照片是混合的。所以我无法将测试文件夹中的图像分开。除了用手标记所有的测试数据,我还能做些什么来解决这个问题?
【问题讨论】:
标签: pytorch
您可以创建自定义数据集类并将其包装在 Pytorch 中的数据加载器中。
link 提供有关此主题的大量信息
要遵循的总体结构是
class Dog_and_Cat():
def __init__(self, ...):
... # replace with a zipped list of image paths and labels (Cat or Dog)
# You can use glob.glob
# Overall ask how do I know the label of the image and install that reasoning in code
# result is a zipped list like [("img1.jpg", 0), ("img2.jpg", 1)] where 0 and 1 represent Cat and Dog
def __getitem__(self, idx):
#describe the func when indexing your class. This is where you open your image and do transforms and return it.
def __len__(self):
# This is where you describe the length of the dataset.
# Ideally should return len of zipped list mentioned above.
您可以初始化刚刚创建的此类而不是 Image Folder,然后将该类的对象放入数据加载器中。这将解决您的任务
萨塔克
【讨论】: