Search code examples
pythonpython-3.xludwig

Issue Training Model From Images in Uber Ludwig


When executing my training python script, the following is returned.

Traceback (most recent call last):
  File "train.py", line 14, in <module>
    train_stats = model.train(data_csv="./dataset.csv")
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/api.py", line 441, in train
    debug=debug,
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/train.py", line 252, in full_train
    random_seed=random_seed
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 403, in preprocess_for_training
    random_seed
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 525, in _preprocess_csv_for_training
    random_seed=random_seed
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 62, in build_dataset
    **kwargs
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 83, in build_dataset_df
    global_preprocessing_parameters
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 116, in build_metadata
    feature['preprocessing']
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/utils/misc.py", line 97, in merge_dict
    for k, v in merge_dct.items():
AttributeError: 'list' object has no attribute 'items'

I've looked through ludwig's documentation, and became stumped on this.

from ludwig.api import LudwigModel

model_definition = {
    "input_features":[
        {"name":"image_path", "type":"image", "preprocessing":[{"height": "128", "width": "128"}],"resize_method": "interpolate"}
    ],
    "output_features":[
        {"name":"plate","type":"text"}
    ]
}

model = LudwigModel(model_definition)

train_stats = model.train(data_csv="./dataset.csv")

My CSV source is formatted like this.

image_path, plate
./crop_m1/I00000.png, 9B52145
./crop_h1/I00000.png, 9B52145
./crop_m1/I00001.png, 6B94558
./crop_h1/I00001.png, 6B94558
./crop_m1/I00002.png, 8B90164
./crop_h1/I00002.png, 8B90164
./crop_m1/I00003.png, 5B11181
./crop_h1/I00003.png, 5B11181
./crop_m1/I00004.png, 8B79697
./crop_h1/I00004.png, 8B79697
./crop_m1/I00005.png, 8B90164

Expected behavior was for ludwig to train model without any errors.


Solution

  • Your pre-proccesing should be a dictionary not a list: You have:

    "preprocessing":[{"height": "128", "width": "128"}]
    

    should be:

    "preprocessing":{"height": "128", "width": "128"}