ludwig-ai / ludwig

Low-code framework for building custom LLMs, neural networks, and other AI models
http://ludwig.ai
Apache License 2.0
11.09k stars 1.19k forks source link

ERROR while training - runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) #333

Closed absint0o closed 5 years ago

absint0o commented 5 years ago

Hi there, i'm trying to train ludwig with images, my dataset.csv looks like this:

image_path,class dataset/chest_xray/train/NORMAL/IM-0115-0001.jpeg,normal dataset/chest_xray/train/NORMAL/IM-0117-0001.jpeg,normal

my model_definition.yaml: input_features:

    name: image_path
    type: image

output_features:

    name: class
    type: category

training: epochs: 5

and when i try to train i get the error:

Using full raw csv, no hdf5 and json file with the same name have been found Building dataset (it may take a while) Traceback (most recent call last): File "c:\users\anaconda3\envs\ludwig\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "c:\users\anaconda3\envs\ludwig\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Anaconda3\envs\ludwig\Scripts\ludwig.exe__main.py", line 9, in File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 94, in main CLI() File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 60, in init__ getattr(self, args.command)() File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 70, in train train.cli(sys.argv[2:]) File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\train.py", line 764, in cli full_train(vars(args)) File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\train.py", line 252, in full_train random_seed=random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 403, in preprocess_for_training random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 525, in _preprocess_csv_for_training random_seed=random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 62, in build_dataset kwargs File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 90, in build_dataset_df global_preprocessing_parameters File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 165, in build_data preprocessing_parameters File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\features\image_feature.py", line 215, in add_feature_data data[feature['name']][i, :, :, :] = img ValueError: could not broadcast input array from shape (1152,1422,1) into shape (1858,2090,1)

Can you please help me understand what i'm doing wrong?

Thank you very much!

Regards, João

w4nderlust commented 5 years ago

either you reshape your images during preprocessing as explained here or all the images you provide have to be of the same size.Moreover, the size of your images is way too big, depending on the task I suggest not to exceed 256 x 256.

absint0o commented 5 years ago

either you reshape your images during preprocessing as explained here or all the images you provide have to be of the same size.Moreover, the size of your images is way too big, depending on the task I suggest not to exceed 256 x 256.

Thank you for your reply.

so i've tested out what you've said and still got the same error. i've changed the model_definition.yaml to this:

input_features:

    name: image_path
    type: image
    height: 256
    width: 265

output_features:

    name: class
    type: category

training: epochs: 5

w4nderlust commented 5 years ago

I just updated that section to reflect this possible misunderstanding. To resize the image you have to use the preprocessing part of the model definition:

input_features:
  -
    name: image_path
    type: image
    preprocessing:
      height: 256
      width: 265
absint0o commented 5 years ago

thank you for your help! i've changed the model_definition.yaml for what you've said and now i'me getting this error:

Using full raw csv, no hdf5 and json file with the same name have been found Building dataset (it may take a while) Traceback (most recent call last): File "c:\users\anaconda3\envs\ludwig\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "c:\users\anaconda3\envs\ludwig\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Anaconda3\envs\ludwig\Scripts\ludwig.exe__main.py", line 9, in File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 94, in main CLI() File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 60, in init__ getattr(self, args.command)() File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\cli.py", line 70, in train train.cli(sys.argv[2:]) File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\train.py", line 764, in cli full_train(vars(args)) File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\train.py", line 252, in full_train random_seed=random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 403, in preprocess_for_training random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 525, in _preprocess_csv_for_training random_seed=random_seed File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 62, in build_dataset kwargs File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 90, in build_dataset_df global_preprocessing_parameters File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\data\preprocessing.py", line 165, in build_data preprocessing_parameters File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\features\image_feature.py", line 213, in add_feature_data user_specified_num_channels File "c:\users\anaconda3\envs\ludwig\lib\site-packages\ludwig\features\image_feature.py", line 110, in _read_image_and_resize num_channels)) ValueError: Image C:\Users\Anaconda3\envs\ludwig\data\pneumonia\dataset\chest_xray\train\PNEUMONIA\person1_bacteria_1.jpeg has 3 channels, unlike the first image, which has 1 channels

msaisumanth commented 5 years ago

@absint0o So it looks like some of your images only have 1 channel (greyscale) while others have 3 channels. This is expected behavior. There are two solutions here:

  1. Set num_channels: 3 in the preprocessing section. Ludwig will append channels with zeros for the images that have <3 channels.
  2. Fix the number of channels for all your images in the training data.
absint0o commented 5 years ago

@absint0o So it looks like some of your images only have 1 channel (greyscale) while others have 3 channels. This is expected behavior. There are two solutions here:

1. Set num_channels: 3 in the preprocessing section. Ludwig will append channels with zeros for the images that have <3 channels.

2. Fix the number of channels for all your images in the training data.

Hi there, so i have more images with 1 channel than images with the 3 channels so i've set my num_channels to 1 so it ignores the images with 3 channels. There's any way that in preprocessing ludwig converts the 3 channel images to 1 channel image?

offtopic subject: Ludwig is amazing! congrats to all!

w4nderlust commented 5 years ago

@absint0o thank you! At the moment if you specify 1 channel and the image had 3 channels, Ludwig uses just the first channel. I just created a pull request that applies greyscaling instead of just using the first channel: https://github.com/uber/ludwig/pull/339

w4nderlust commented 5 years ago

Just merged the PR. Now if you specify num_channels: 1 and your images have more than 1 channel, they are converted to greyscale. Closing the issue, feel free to comment further if needed ;)

absint0o commented 5 years ago

@absint0o thank you! At the moment if you specify 1 channel and the image had 3 channels, Ludwig uses just the first channel. I just created a pull request that applies greyscaling instead of just using the first channel: #339

Thank you for your consideration.

i have another two question: it´s possible to improve a previous trained model without creating a new one? it's possible to re-enforce the model accuracy by "telling" which prediction was correct and incorrect?

i also would like to make a sugestion: it would be great if ludwig had a forum so people can debate and discuss more than just errors or issues.

thank you very much!

Regards

w4nderlust commented 5 years ago

@absint0o you can both resume the training of a model with --model_resume_path or load a model to use as initialization of a new model with --model_load_path. You can find the, admittedly not well advertised, forum on Gitq.

absint0o commented 5 years ago

@absint0o you can both resume the training of a model with --model_resume_path or load a model to use as initialization of a new model with --model_load_path. You can find the, admittedly not well advertised, forum on Gitq.

sorry, it's on the user guide and i've missed it out! i also have to define the path for the dataset as i normally do when do a new training right?

i got this error: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Anaconda3\envs\ludwig\data\pneumonia\results\experiment_run_3\model\model\training_progress.json'

i ran the command: ludwig train --data_csv dataset2.csv --model_definition_file model_definition.yaml --model_resume_path C:\Users\Anaconda3\envs\ludwig\data\pneumonia\results\experiment_run_3\model\

thank you and i'll check the ludwig forum!

w4nderlust commented 5 years ago

Remove \model at the end of the path ;)

absint0o commented 5 years ago

Nice! Thank you very much, I will try it out!