easy-few-shot-learning icon indicating copy to clipboard operation
easy-few-shot-learning copied to clipboard

Name of the images (files) of the support and query images.

Open vsantjr opened this issue 1 year ago • 3 comments

Problem For each test task, I would like to know precisely which are the name of the images (files) which are part of the task. And the respective classes. For instance, assuming 3-way 5-shots and n_query = 10. Hence, we have 15 images in the support set and 10 images in the query set. What are the name of the files and classes/labels of the 15 support images and of the 10 query images?

Considered solutions Not sure. Maybe change the TaskSampler?

How can we help Please provide a solution.

Thank you.

vsantjr avatar Nov 01 '23 14:11 vsantjr

From the code in TaskSampler, here is how your task is constructed:

    def episodic_collate_fn(
        self, input_data: List[Tuple[Tensor, Union[Tensor, int]]]
    ) -> Tuple[Tensor, Tensor, Tensor, Tensor, List[int]]:
        """
        Collate function to be used as argument for the collate_fn parameter of episodic
            data loaders.
        Args:
            input_data: each element is a tuple containing:
                - an image as a torch Tensor of shape (n_channels, height, width)
                - the label of this image as an int or a 0-dim tensor
        Returns:
            tuple(Tensor, Tensor, Tensor, Tensor, list[int]): respectively:
                - support images of shape (n_way * n_shot, n_channels, height, width),
                - their labels of shape (n_way * n_shot),
                - query images of shape (n_way * n_query, n_channels, height, width)
                - their labels of shape (n_way * n_query),
                - the dataset class ids of the class sampled in the episode
        """

As you can see, you already have the ids of the dataset as the last element of the yielded tuple. But if you also want the image path, you need to:

  1. Add it to the outputs of your dataset's __get_item__() method;
  2. Build a new sampler extending the TaskSampler class and overwriting the episodic_collate_fn() method to handle this additional element. The method's signature would look something like that:
    def episodic_collate_fn(
        self, input_data: List[Tuple[Tensor, Union[Tensor, int], Path]]
    ) -> Tuple[Tensor, Tensor, Tensor, Tensor, List[int], List[Path], List[Path]]:
        """
        Collate function to be used as argument for the collate_fn parameter of episodic
            data loaders.
        Args:
            input_data: each element is a tuple containing:
                - an image as a torch Tensor of shape (n_channels, height, width)
                - the label of this image as an int or a 0-dim tensor
                - the path to this image
        Returns:
            tuple(Tensor, Tensor, Tensor, Tensor, list[int]): respectively:
                - support images of shape (n_way * n_shot, n_channels, height, width),
                - their labels of shape (n_way * n_shot),
                - query images of shape (n_way * n_query, n_channels, height, width)
                - their labels of shape (n_way * n_query),
                - the dataset class ids of the class sampled in the episode,
                - paths of support images of length (n_way * n_shot),
                - paths of query images of length (n_way * n_query),
        """

ebennequin avatar Nov 05 '23 09:11 ebennequin

Thank you @ebennequin. I will try. Regarding this point: "Add it to the outputs of your dataset's __get_item__() method;" In fact, I should change the __get_item__() method in the EasySet class. Just to be sure.

vsantjr avatar Nov 06 '23 18:11 vsantjr

I wouldn't recommend modifying the easyfsl code or interface. The best practice would be to create a new class extending FewShotDataset with your desired interface.

ebennequin avatar Nov 06 '23 18:11 ebennequin