def __getitem__(self, idx):
        """
        Args:
            idx: Sample idx for training sample
        Returns:
            tuple of form (sample_class, torch.Tensor() of input image)
        """
        if self.pars.loss == "smoothap" or self.pars.loss == "smoothap_element":
            if self.is_init:
                # self.current_class = self.avail_classes[idx%len(self.avail_classes)]
                self.is_init = False

            if not self.is_validation:
                if self.samples_per_class == 1:
                    return self.image_list[idx][-1], self.transform(
                        self.ensure_3dim(Image.open(self.image_list[idx][0]))
                    )

                if self.n_samples_drawn == self.samples_per_class:
                    # Once enough samples per class have been drawn, we choose another class to draw samples from.
                    # Note that we ensure with self.classes_visited that no class is chosen if it had been chosen
                    # previously or one before that.
                    counter = copy.deepcopy(self.avail_classes)
                    for prev_class in self.classes_visited:
                        if prev_class in counter:
                            counter.remove(prev_class)

                    self.current_class = counter[idx % len(counter)]
                    # self.classes_visited = self.classes_visited[1:]+[self.current_class]
                    # EDIT -> there can be no class repeats
                    self.classes_visited = self.classes_visited + [
                        self.current_class
                    ]
                    self.n_samples_drawn = 0

                class_sample_idx = idx % len(
                    self.image_dict[self.current_class]
                )
                self.n_samples_drawn += 1

                out_img = self.transform(
                    self.ensure_3dim(
                        Image.open(
                            self.image_dict[self.current_class][
                                class_sample_idx
                            ]
                        )
                    )
                )
                return self.current_class, out_img
            else:
                return self.image_list[idx][-1], self.transform(
                    self.ensure_3dim(Image.open(self.image_list[idx][0]))
                )
        else:
            if self.is_init:
                self.current_class = self.avail_classes[
                    idx % len(self.avail_classes)
                ]
                self.is_init = False
            if not self.is_validation:
                if self.samples_per_class == 1:
                    return self.image_list[idx][-1], self.transform(
                        self.ensure_3dim(Image.open(self.image_list[idx][0]))
                    )

                if self.n_samples_drawn == self.samples_per_class:
                    # Once enough samples per class have been drawn, we choose another class to draw samples from.
                    # Note that we ensure with self.classes_visited that no class is chosen if it had been chosen
                    # previously or one before that.
                    counter = copy.deepcopy(self.avail_classes)
                    for prev_class in self.classes_visited:
                        if prev_class in counter:
                            counter.remove(prev_class)

                    self.current_class = counter[idx % len(counter)]
                    self.classes_visited = self.classes_visited[1:] + [
                        self.current_class
                    ]
                    self.n_samples_drawn = 0

                class_sample_idx = idx % len(
                    self.image_dict[self.current_class]
                )
                self.n_samples_drawn += 1

                out_img = self.transform(
                    self.ensure_3dim(
                        Image.open(
                            self.image_dict[self.current_class][
                                class_sample_idx
                            ]
                        )
                    )
                )
                return self.current_class, out_img
            else:
                return self.image_list[idx][-1], self.transform(
                    self.ensure_3dim(Image.open(self.image_list[idx][0]))
                )

        Args:
            idx: Sample idx for training sample
        Returns:
            tuple of form (sample_class, torch.Tensor() of input image)
        
examples/pytorch/hilander/PSS/Smooth_AP/src/datasets.py