Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: could not broadcast input array from shape (32,29) into shape (32,32) #2

Open
parsibox opened this issue Jun 16, 2019 · 20 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@parsibox
Copy link

python3.6 main.py 
Using TensorFlow backend.

(32, 32)
[2.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 29)
Traceback (most recent call last):
  File "main.py", line 53, in <module>
    prediction = classifier.knn_classify(number)
  File "/home/mohsen/Desktop/python/farsi-car-number-plate-recognition/classifier.py", line 68, in knn_classify
    test_data[0] = img
ValueError: could not broadcast input array from shape (32,29) into shape (32,32)

@ammoradi
Copy link
Owner

@parsibox can I see a sample of your dataset?

@parsibox
Copy link
Author

i do not change any thing
i run your sample code

@ammoradi
Copy link
Owner

@parsibox Ok. I will check this case and update repo if I made a mistake.

@ammoradi ammoradi reopened this Jun 16, 2019
@ammoradi ammoradi self-assigned this Jun 16, 2019
@ammoradi ammoradi added bug Something isn't working good first issue Good for newcomers labels Jun 16, 2019
@ammoradi ammoradi pinned this issue Jun 16, 2019
@parsibox
Copy link
Author

1
thi is my image
image
image
image

@parsibox
Copy link
Author

did you try it?

@ammoradi
Copy link
Owner

ammoradi commented Jun 18, 2019

@parsibox i have not free time until next week.

  • PRs welcome

@parsibox
Copy link
Author

ok i wait for you

@ammoradi
Copy link
Owner

the bug is from the detector.
it should not detect the blue part of the flag but it does!
I will try to fix this.

@parsibox
Copy link
Author

thanks
i need this code

@parsibox
Copy link
Author

i am still waiting for you

@ammoradi
Copy link
Owner

ammoradi commented Jun 29, 2019

@parsibox could you please upload your testing image somewhere and give me a download link?

@parsibox
Copy link
Author

@parsibox
Copy link
Author

@parsibox
Copy link
Author

i am still waiting for you

@SabraHashemi
Copy link

i am still waiting for you

did you solve this problem? i had same problem

@parsibox
Copy link
Author

no

@SabraHashemi
Copy link

no

i think we can rewrite this resize function
tarfget is to resize any image to 32*32

@SabraHashemi
Copy link

def __resize_image(src_image, dst_image_height, dst_image_width):
src_image_height = src_image.shape[0]
src_image_width = src_image.shape[1]

if src_image_height > dst_image_height or src_image_width > dst_image_width:
    height_scale = dst_image_height / src_image_height
    width_scale = dst_image_width / src_image_width
    scale = min(height_scale, width_scale)
    img = cv2.resize(src=src_image, dsize=(0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
else:
    img = src_image

img_height = img.shape[0]
img_width = img.shape[1]

dst_image = np.zeros(shape=[dst_image_height, dst_image_width], dtype=np.uint8)

y_offset = (dst_image_height - img_height) // 2
x_offset = (dst_image_width - img_width) // 2

dst_image[y_offset:y_offset+img_height, x_offset:x_offset+img_width] = img

return dst_image

@ammoradi
Copy link
Owner

@parsibox @sabrabano0 I was far from this subject for years. let me read the principles used in this project and try to fix this bug.
maybe I should refactor or rebase this project. because it is not funny to deal with this problem with knn or a simple cnn it should be under sth like YOLO or SSD hand!

@SabraHashemi
Copy link

@parsibox @sabrabano0 I was far from this subject for years. let me read the principles used in this project and try to fix this bug.
maybe I should refactor or rebase this project. because it is not funny to deal with this problem with knn or a simple cnn it should be under sth like YOLO or SSD hand!

Not so complicated, as I mentioned above the problem is in the function resize. You have included resizing for bigger image than 32 x 32 but not for smaller like 24 x 32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants