我目前正在为一个项目做一些人工智能研究,为此我必须习惯一个叫做“Pytorch”的框架。这很好,但都遵循官方教程(发现)
here
)代码运行不正常。
我的想法是,我从一个准备好的数据集中分析一组面部特征,然后用它做一些事情(还没有到那部分)。但当我运行这段代码时:
img_name = os.path.join(self.root_dir, self.landmarks_frame.iloc([index, 0])) # At this point 'index' is 0
数据集的初始化方式如下:
face_dataset = fDataset(csv_file='faces/face_landmarks.csv', root_dir='faces/')
这里是错误出现的地方:
for i in range(len(face_dataset)):
sample = face_dataset[i] # <-- right there
这就产生了getter函数:
def __getitem__(self, index):
img_name = os.path.join(self.root_dir, self.landmarks_frame.iloc([index, 0]))
image = io.imread(img_name)
landmarks = self.landmarks_frame.iloc[index, 1:].as_matrix()
landmarks = landmarks.astype('float').reshape(-1, 2)
sample = {'image': image, 'landmarks': landmarks}
FaceLandmarksDataset(Dataset):
我只是得到了标题的错误。我发现这很奇怪,因为我在PyCharm中可以很好地读取数据集作为一个帧:
第一张照片清晰可见。我也检查过,它是在文件夹中,我正在寻找。