Receiving this error trying to run a simple image classification example
File "/Users/colinpetit/.pyenv/versions/3.6.5/lib/python3.6/site-packages/ludwig/features/image_feature.py", line 101, in add_feature_data
data[feature['name']][i, :, :, :] = img
ValueError: could not broadcast input array from shape (743,620,3) into shape (383,442,4)
model_definition_file:
input_features:
-
name: img
type: image
encoder: stacked_cnn
output_features:
-
name: type
type: category
training:
epochs: 10
I have to specify this better in the docs: Either your images are all of the same size, or you have to resize them to the same size by specifying the resize_method, width and height parameters as explained here. Let me know if this solves your issue.
I've set a resize as follows
input_features:
-
name: image_path
type: image
encoder: stacked_cnn
resize_method: crop_or_pad
height: 500
width: 500
output_features:
-
name: class
type: category
However I still get an error.
ValueError: could not broadcast input array from shape (500,500,4) into shape (500,500,3)
Interesting, that 4 as the last dimension of your image, may mean images with an alpha channel, something I may have not considered. Can you send me an image form you dataset that has a fourth channel so that I can reproduce the issue?
@ydudin3 could you please try to take a look at this too?
Another remark: I would suggest not exceeding 224x224 as a image size, as othersize model training would require a lot of memory and it will be really slow. @ydudin3 maybe we can add something about it in the documentation, plus moving all parameters from the feature itself to preprocessing as it happens for other features and impose a defaul maximum size, so that if the dimension of images is above that size images are resized users get a warning printed on the console.
It is the Stanford dog breeds data set, I couldn't find the one or two with an alpha channel but I think that was the issue.
I just removed the alpha channel with this.
And yes, size was far too big! 112x112 was getting quick results.
Thanks @mattarderne for confirming it, will work on a patch that solves this issue, it will be pretty straightforward.
Hello, @w4nderlust
Can I update the docs image-preprocessing with your suggestion
Ludwig supports grayscale and color images, image type is automatically inferred. During preprocessing raw image files are transformed into numpy ndarrays and saved in the hdf5 format. Images should have the same size (keep the image size under 224x224 pixels). If they have different sizes they should be converted to the same size by specifing the
resize_method,width, andheightparameters of image feature preprocessing.
Thanks for collecting this. Wait a bit as we are going to change a few things, including the support for images with alpha channels.
So all parameters have been moved to preprocessing, #141 . Now there is a PR for dealing with the 4th channel and image sizes too. Stay tuned.
I added a temporary workaround for images with a 4th channel. We will improve over this solution (which basically just ignores the alpha channel), but at the moment should fix this issue. @mattarderne and @ctpmp can you please confirm that with the code on master this issue is solved?