[Python] MultiLabel Classification Path errors in pytorch

Discussão em 'Python' iniciado por Stack, Julho 16, 2025.

  1. Stack

    Stack Membro Participativo

    While I am running the following code, it says [Errno 2] No such file or directory: '/content/drive/MyDrive/Image Dataset/images/img_0_7'. But I already have that file or directory in my drive – still it says missing.

    Here is the code portion I have written:

    class MultiLabelDataset(Dataset):
    def __init__(self):

    self.labels, self.images = [], []

    labels_path = '/content/drive/MyDrive/Image Dataset/Binary Dataset/labels.csv'
    images_path = '/content/drive/MyDrive/Image Dataset/images'

    df = pd.read_csv(labels_path)
    column_names = df.columns.tolist()
    df.rename(columns={column_names[1]: 'classes'}, inplace=True)

    for index, row in df.iterrows():
    last_elements = row.iloc[-10: ].tolist()
    self.labels.append(last_elements)

    self.labels = np.array(self.labels)

    image_names = df['Image_Name'].tolist()

    for img_name in image_names:
    image_path = os.path.join(images_path, img_name)
    image = Image.open(image_path)
    image = np.array(image)
    if len(image.shape) == 2:
    copied_images = [image.copy() for _ in range(3)]
    image = np.stack(copied_images, axis=-1)
    image = cv2.resize(image, (32, 32))
    self.images.append(image)

    self.images = np.array(self.images)

    def normalize(self):
    self.image = self.images / 255.0

    def __getitem__(self, index):
    return self.images[index], self.labels[index]

    def __len__(self):
    return len(self.images)

    def __getitem__(self, idx):
    sample = {'images': self.images[idx], 'labels': self.labels[idx]}
    return sample

    d = MultiLabelDataset()


    I just want to know where I am doing mistakes and I can't find it. How to fix this error?

    Continue reading...

Compartilhe esta Página