TypeError:无法散列的类型:调用.iloc()

时间:2018-09-20 15:23:18

标签: python python-3.x pytorch

我目前正在为一个项目进行一些AI研究,为此,我必须习惯于称为“ 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中像框架一样读取数据集: Dataset Inspector

第一张图片清晰可见的位置。我还检查了它是否在我要查找的文件夹中。

有人可以帮忙吗? :)

1 个答案:

答案 0 :(得分:2)

您不需要带有iloc的括号:

self.landmarks_frame.iloc[index, 0]