Ludwig: Can't predict images

Created on 14 Nov 2019  路  10Comments  路  Source: ludwig-ai/ludwig

Describe the bug
Can't predict images from any kind of method

To Reproduce
Steps to reproduce the behavior:

  1. Install ludwig from master
  2. serve the model using: ludwig serve -m model/
  3. try to predict image using: curl http://0.0.0.0:8000/predict -X POST -F'image=@/media/flo/data/KIs/image_classification/dataset1/3100.jpg'
  4. See error
    {"error":"Unexpected Error: could not run inference on model"}
    from curl command

INFO: Started server process [8659] INFO: Waiting for application startup. INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) Error: 'DataFrame' object has no attribute 'csv' ERROR: Error: 'DataFrame' object has no attribute 'csv'
from serve

Traceback (most recent call last): File "app.py", line 19, in <module> pred = modell.predict(data_df=df) File "/home/flo/venv/lib/python3.6/site-packages/ludwig/api.py", line 890, in predict gpu_fraction=gpu_fraction, File "/home/flo/venv/lib/python3.6/site-packages/ludwig/api.py", line 748, in _predict self.model_definition['preprocessing'] File "/home/flo/venv/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 171, in build_data preprocessing_parameters File "/home/flo/venv/lib/python3.6/site-packages/ludwig/features/image_feature.py", line 309, in add_feature_data data_fp = os.path.splitext(dataset_df.csv)[0] + '.hdf5' File "/home/flo/venv/lib/python3.6/site-packages/pandas/core/generic.py", line 5179, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'csv'

error while trying to predict using python script

Please provide code, yaml definition file and a sample of data in order to entirely reproduce the issue.
Issues that are not reproducible will be ignored.

`input_features:
-
name: image
type: image
encoder: stacked_cnn
preprocessing:
width: 128
height: 128
num_channels: 3
in_memory: false

output_features:
-
name: labels
type: set`

my definition file

Environment (please complete the following information):

  • OS: Linux

    • Python version: 3.6 in virtualenv

    • Ludwig version from master

bug looking into it

All 10 comments

Thanks for pointing this out, we are going to look into it and get back to you.

Aaaaaaand of course I got into this too :)
Can confirm it's happening on Windows, Python 3.6, Ludwig from master

Issue is due to the "in_memory: false" in the model_hyperparameters.json (that causes a different preprocessing to happen, and that's the real source of the issue). If changed back to "in_memory: true" it all works fine as expected.

I'm running the predict within python code via APIs, using LudwingModel.predict(data_df=pd.DataFrame({"ImageFile": [temp_filename_1]}))

@flozi00 : try setting that flag to true within the model definition if you have a small enough dataset you want to infer on, as a workaround for now.

@ydudin3 can you take a look at this? Thank you for helping out @carlogrisetti , much appreciated.

@w4nderlust No problem. Also on this one if you need something to be tested, I should have some time invested in closely related projects, so I can help if needed.

@carlogrisetti it's actually not supported at the moment. If you're training / predicting using the API you would have to set have in_memory = True or use the cli.

@ydudin3 yes, but when you are predicting on a model that was trained with in_memory=false, Ludwig is restoring that hyperparameter too, trying to predict using in_memory=false, and you have to force it to true by manually modifying the json in the model folder.
If predicting from disk is not supported (no objection to that) you should never restore in_memory value from the model hyperparameters and always use the "true" value regardless of how it was trained.

Do I make sense? :)

Yes, totally makes sense. I think as a short term fix we could just override in_memory flag for all of the API functions.

@w4nderlust but this brings an interesting point, when training a model it's fine to keep this flag in the model definition but it's really a property of the dataset, so that when one calls predict they should be able to feed datasets with in_memory true or false, depending on the dataset and not the model.

@ydudin3 That's correct, it's not really about the model but the dataset, so we should probably mode that parameter somewhere else, like in the preprocessing section of the model definition.

@ydudin3 's PR should have solved this, can you confirm @flozi00 ?

Confirmation, it works
Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

allenkao picture allenkao  路  5Comments

BenMacKenzie picture BenMacKenzie  路  7Comments

loretoparisi picture loretoparisi  路  7Comments

gogasca picture gogasca  路  3Comments

catr1ne55 picture catr1ne55  路  4Comments