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

Python 3.7 --- model prediction and object detection #979

Closed
gianscarpe opened this issue Nov 19, 2021 · 4 comments
Closed

Python 3.7 --- model prediction and object detection #979

gianscarpe opened this issue Nov 19, 2021 · 4 comments
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@gianscarpe
Copy link
Contributor

gianscarpe commented Nov 19, 2021

🐛 Bug

I got this error
~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/integrations/icevision/adapter.py in (.0)
86 DefaultDataKeys.INPUT: collate_fn(
---> 87 [to_icevision_record({**sample, DefaultDataKeys.METADATA: m}) for sample, m in zip(samples, metadata)]
88 ),

TypeError: 'str' object is not a mapping

To Reproduce

Launch model prediction for object-detection, master version of flash and python3.7

TypeError Traceback (most recent call last)
~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/data/batch.py in forward(self, samples)
230 try:
--> 231 samples = self.collate_fn(samples, metadata)
232 except TypeError:

~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(

~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/data/utils.py in forward(self, *args, **kwargs)
192 def forward(self, *args, **kwargs) -> Any:
--> 193 return self.func(*args, **kwargs)
194

~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/data/process.py in collate(self, samples, metadata)
439 if len(parameters) > 1 and DefaultDataKeys.METADATA in parameters:
--> 440 return collate_fn(samples, metadata)
441 return collate_fn(samples)

~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/integrations/icevision/adapter.py in _collate_fn(collate_fn, samples, metadata)
86 DefaultDataKeys.INPUT: collate_fn(
---> 87 [to_icevision_record({**sample, DefaultDataKeys.METADATA: m}) for sample, m in zip(samples, metadata)]
88 ),

~/.local/share/virtualenvs/cell_instance_segm-TWYpWSyU/lib/python3.7/site-packages/flash/core/integrations/icevision/adapter.py in (.0)
86 DefaultDataKeys.INPUT: collate_fn(
---> 87 [to_icevision_record({**sample, DefaultDataKeys.METADATA: m}) for sample, m in zip(samples, metadata)]
88 ),

TypeError: 'str' object is not a mapping

Code sample

Expected behavior

Environment

  • PyTorch Version (e.g., 1.0):
  • OS (e.g., Linux): linux
  • How you installed PyTorch (conda, pip, source): pip
  • Build command you used (if compiling from source):
  • Python version: 3.7
  • CUDA/cuDNN version:
  • GPU models and configuration:
  • Any other relevant information:

Additional context

@gianscarpe gianscarpe added bug / fix Something isn't working help wanted Extra attention is needed labels Nov 19, 2021
@gianscarpe gianscarpe changed the title Python 3.7 list explosion inside dict Python 3.7 --- model prediction and object detection Nov 19, 2021
@ethanwharris
Copy link
Collaborator

Hi @gianscarpe thanks for reporting this! I thought this should have been fixed following #857 - could you share a reproducible script which gives the error?

@kurtjcu
Copy link

kurtjcu commented Nov 25, 2021

I can reproduce the error.

installation via:
pip install git+git://github.com/airctic/icevision.git#egg=icevision[all] --upgrade
pip install 'git+https://github.com/PyTorchLightning/lightning-flash.git#egg=lightning-flash[image]'

use the example program from https://lightning-flash.readthedocs.io/en/latest/reference/object_detection.html
append the following lines to the end of the file to load weights from saved file and attempt inference

model_2 = ObjectDetector.load_from_checkpoint(
    "object_detection_model.pt"
)

predictions = model_2.predict(
    [
        "data/coco128/images/train2017/000000000625.jpg",
        "data/coco128/images/train2017/000000000626.jpg",
        "data/coco128/images/train2017/000000000629.jpg",
    ]
)
print("with reloaded weights", predictions)

@jspablo
Copy link

jspablo commented Dec 2, 2021

I can reproduce the error.

installation via: pip install git+git://github.com/airctic/icevision.git#egg=icevision[all] --upgrade pip install 'git+https://github.com/PyTorchLightning/lightning-flash.git#egg=lightning-flash[image]'

use the example program from https://lightning-flash.readthedocs.io/en/latest/reference/object_detection.html append the following lines to the end of the file to load weights from saved file and attempt inference

model_2 = ObjectDetector.load_from_checkpoint(
    "object_detection_model.pt"
)

predictions = model_2.predict(
    [
        "data/coco128/images/train2017/000000000625.jpg",
        "data/coco128/images/train2017/000000000626.jpg",
        "data/coco128/images/train2017/000000000629.jpg",
    ]
)
print("with reloaded weights", predictions)

Got same error with that code, any workaround using Trainer.predict?

@ethanwharris
Copy link
Collaborator

Hey all, this issue should now be fixed as we now only support prediction via a Trainer with a datamodule where this error shouldn't occur. Closing this, but please feel free to re-open if needed 😃

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

No branches or pull requests

4 participants