model.predict from example code does not work
See original GitHub issue🐛 Bug
model.predict using the sample code on my own data seems to fail. Not really sure how to interpret this error message.
KeyError: None
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-42-c24524f3eb71> in <module>
14 # ])
15
---> 16 print(model.predict("classifier/test/bad/Image__2021-07-26__12-52-29_aligned-18.jpg"))
~\miniconda3\envs\torch\lib\site-packages\flash\core\model.py in wrapper(self, *args, **kwargs)
76 torch.set_grad_enabled(False)
77
---> 78 result = func(self, *args, **kwargs)
79
80 if is_training:
~\miniconda3\envs\torch\lib\site-packages\flash\core\model.py in predict(self, x, data_source, deserializer, data_pipeline)
234 x = self.transfer_batch_to_device(x, self.device, 0)
235 else:
--> 236 x = self.transfer_batch_to_device(x, self.device)
237 x = data_pipeline.device_preprocessor(running_stage)(x)
238 predictions = self.predict_step(x, 0) # batch_idx is always 0 when running with `model.predict`
~\miniconda3\envs\torch\lib\site-packages\flash\core\data\data_pipeline.py in __call__(self, *args, **kwargs)
599 stage = self.model.trainer.state.stage
600
--> 601 internal_running_state = self.internal_mapping[stage]
602 additional_func = self._stage_mapping.get(internal_running_state, None)
603
KeyError: None
To Reproduce
Steps to reproduce the behavior:
- Follow instructions here
- Observe error
Code sample
from flash.core.classification import Probabilities
model.serializer = Probabilities()
print(model.predict("classifier/some image here..."))
Expected behavior
Example expected to work. model.predict seems to be the culprit. I can train and evaluate just fine.
Environment
- PyTorch Version (e.g., 1.0): 1.9
- OS (e.g., Linux): Windows 10
- How you installed PyTorch (
conda,pip, source): conda - Build command you used (if compiling from source):
- Python version: 3.8
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Trouble with model.predict() - The freeCodeCamp Forum
Hey So I am doing the machine learning with python course with free code camp and I'm stuck with this problem for days....
Read more >python keras neural network prediction not working (outputs 0 ...
I have created with keras a neural network for predicting addition. I have 2 inputs and 1 output (result of adding the 2...
Read more >Keras model.predict does not work with 2 inputs
Now I wanted to predict the Y using 2 inputs, but it fails. The training is done using this code fragment (I think...
Read more >How to use a model to do predictions with Keras - ActiveState
Keras models can be used to detect trends and make predictions, using the model.predict() class and it's variant, ...
Read more >When train a model with Dataset, model.predict() does not ...
The way given by the example to use dataset to train and predict cannot work properly. Version used: 1.12.0. Describe the expected behavior...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Awesome, thanks for that! I’ll look into it and get back to you once I have something 😃
@ethanwharris Here’s the snippet that triggered the bug
lightning version 1.3.8, flash version 0.4.0