object_detector.create operands could not be broadcast together #114
Comments
Thanks for trying out the object detector! I really appreciate the detailed report of this bug, since it made it very easy for me to understand the issue. The problem is that we are not handling images with 4 channels (RGB + opacity channel) correctly. I will work on a fix and in the meantime let's discuss work-arounds to get your model working. If you want to train the model to leverage the opacity channel, then the current version will unfortunately not support that. However, if you get rid of the opacity channel then this error message will disappear. You can either manually convert your images before loading them, or you can do it through Turi Create: def drop_alpha(image):
return tc.Image(_image_data=image.pixel_data[..., :3].tobytes(),
_width=image.width,
_height=image.height,
_channels=3,
_format_enum=2,
_image_data_size=image.width * image.height * 3)
sf['image_rgb'] = sf['image'].apply(drop_alpha) Removing the opacity channel of an image can be done in several ways. The question is, do we replace the transparent background with white or black, or something else? The above method is blunt and simply drops the opacity channel. This will work if most of your images do not actually use the extra channel. However, if they do use it, it may lead to visual artifacts so I encourage you to check the new images manually with |
Hi, Thanks for the feedback. I can look into manually fixing the images as a workaround. I've tried the fix above but am also getting the below error: #!/usr/bin/env python
import turicreate as tc
def drop_alpha(image):
return tc.Image(_image_data=image.pixel_data[..., :3].tobytes(),
_width=image.width,
_height=image.height,
_channels=3,
_format_enum=2,
_image_data_size=image.width * image.height * 3)
images = tc.SFrame('clash.sframe')
images['rgb'] = images['image'].apply(drop_alpha) $ ./convert.py
Traceback (most recent call last):
File "./convert.py", line 16, in <module>
images['rgb'] = images['image'].apply(drop_alpha)
File "/Users/hovland/.pyenv/versions/turicreate/lib/python2.7/site-packages/turicreate/data_structures/sarray.py", line 1881, in apply
return SArray(_proxy=self.__proxy__.transform(fn, dtype, skip_na, seed))
File "/Users/hovland/.pyenv/versions/turicreate/lib/python2.7/site-packages/turicreate/cython/context.py", line 49, in __exit__
raise exc_type(exc_value)
RuntimeError: Runtime Exception. Exception in python callback function evaluation:
UnpicklingError('NEWOBJ class argument has NULL tp_new',):
Traceback (most recent call last):
File "turicreate/cython/cy_pylambda_workers.pyx", line 398, in turicreate.cython.cy_pylambda_workers._init_lambda
File "turicreate/cython/cy_pylambda_workers.pyx", line 138, in turicreate.cython.cy_pylambda_workers.lambda_evaluator.__init__
UnpicklingError: NEWOBJ class argument has NULL tp_new |
That looks like another bug unfortunately (thanks for finding these!). I can't seem to reproduce it though. There is probably something different between your images and my test images. Perhaps it will give us a more informative error message (or none at all) if you run this as a slower for loop: rgbs = []
for row in images:
rgb = drop_alpha(row['image'])
rgbs.append(rgb)
images['rgb'] = rgbs Sorry again for this and thanks for your patience! Any additional information that can help us track this down is greatly appreciated. |
Interestingly the code above seems to work fine. I'm able to run it and then modify my model create statement to point to the Here is just a print of the ['Height: 100 Width: 100', 'Height: 104 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 104 Width: 100', 'Height: 100 Width: 100', 'Height: 104 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100', 'Height: 100 Width: 100']``` |
Great! Does that mean the detector is training now? I would love to investigate the second bug some more. If you have time, it would be great if you could check if If you find an SFrame with a single image that breaks it, I would love to get more info on that particular image (or ideally the file itself, but I understand completely if you do not want to share it). Thanks again for finding these things, @res0nat0r! |
Yep, I was able to get a model to generate now. :) Actually here is the entire SFrame if you'd like to download it and look. It is just a handful Feel free to download below, let me know if you need anything else. Thanks for the help. |
That is super helpful, thank you so much @res0nat0r. I am now able to reproduce the error. I have filed a separate issue #124 so as not to confuse it with the original issue of not being able to use the detector on RGBA images. |
Awesome thanks! |
Hi res0nat0r, I am trying to generate model for object detection. While generating model i am also getting same error as you got. i tried to add the code you and gustavla discussed above but i am still getting the error. Following is my convert.py code. Can you help me how to solve this issue. import sys if len(sys.argv) < 2: fileIn = sys.argv[1] objectLabel = 'Object' csv = pd.read_csv(fileIn, names = ["image", "id", "label", "xMin", "xMax", "yMin", "yMax", "annotations"], for i, item in csv.iterrows():
csv.to_csv('annotations.csv') Thank you. |
This relies on the `resize` function to do make these conversions. This function is really fast when there is no resizing or channel change, although a bit slower than the previous decoding method in speed tests. Fixes #114
Hi all,
I'm trying to follow the object detection tutorial on some image data I have, I have
an SFrame with my images labeled with annotations.
explore()
shows the boundingboxes properly setup, but I'm getting the error below when trying to create a model.
Any suggestions would be great, or if this is a bug I'd be happy to help debug further.
Model failure:
...
The text was updated successfully, but these errors were encountered: