Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Fiftyone dataset predictions not working #1111

Closed
RadekZenkl opened this issue Jan 12, 2022 · 1 comment · Fixed by #1136
Closed

Fiftyone dataset predictions not working #1111

RadekZenkl opened this issue Jan 12, 2022 · 1 comment · Fixed by #1136
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@RadekZenkl
Copy link

🐛 Bug

Predicting on a Fiftyone dataset is unable to load the data properly. Training, validating and testing works fine. When loading data for prediction, datamodule created from fifty one dataset yields labels which datamodule cannot handle.

To Reproduce

Steps to reproduce the behavior:

Error:

Traceback (most recent call last):
  File "/home/miniconda3/envs/astrib/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 13, in <module>
  File "/home/miniconda3/envs/astrib/lib/python3.9/site-packages/flash/image/classification/data.py", line 304, in from_fiftyone
    input_cls(RunningStage.PREDICTING, predict_dataset, transform=predict_transform, **ds_kw),
  File "/home/miniconda3/envs/astrib/lib/python3.9/site-packages/flash/core/data/io/input.py", line 140, in wrapper
    fn(self, *args, **kwargs)
  File "/home/miniconda3/envs/astrib/lib/python3.9/site-packages/flash/core/data/io/input.py", line 200, in __init__
    self.data = self._call_load_data(*args, **kwargs)
  File "/home/miniconda3/envs/astrib/lib/python3.9/site-packages/flash/core/data/io/input.py", line 222, in _call_load_data
    return load_data(*args, **kwargs)
TypeError: predict_load_data() got an unexpected keyword argument 'label_field'


Code sample

import fiftyone.zoo as foz
from flash.image import ImageClassificationData

dataset = foz.load_zoo_dataset("caltech101")
# dataset = foz.load_zoo_dataset("imagenet-sample")

train_dataset = dataset[:20]
test_dataset = dataset[20:25]
val_dataset = dataset[25:30]
predict_dataset = dataset[30:40]

# 3 Load data into Flash
datamodule = ImageClassificationData.from_fiftyone(
    train_dataset=train_dataset,
    val_dataset=val_dataset,
    test_dataset=test_dataset,
    predict_dataset=predict_dataset,
    label_field="ground_truth",
    batch_size=4,
)

Expected behavior

When predicting on Fiftyone dataset that also contains labels, these labels should be ignored.

Environment

  • Pytorch lightning flash 0.6.0
  • Fiftyone 0.14.2
  • Ubuntu 20.4
  • Pytorch lighting flash and Fiftyone are both installed with pip
  • Python version: 3.9

Additional context

@RadekZenkl RadekZenkl added bug / fix Something isn't working help wanted Extra attention is needed labels Jan 12, 2022
@Actis92
Copy link
Contributor

Actis92 commented Jan 12, 2022

In my opinion the problem is this method
@staticmethod @requires("fiftyone") def predict_load_data(data: SampleCollection) -> List[Dict[str, Any]]: return super().load_data(data.values("filepath"))

because it is used for the prediction dataloader and in fact it didn't accept the key label_field

A possible solution could be
@requires("fiftyone") def predict_load_data(self, data: SampleCollection, **kwargs) -> List[Dict[str, Any]]: return super().load_data(data.values("filepath"))
in this way is used the method load_data of the class ImageClassificationFilesInput that is able to manage the case in which label_field is None, but maybe exists a different solution

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants