GithubHelp home page GithubHelp logo

Comments (10)

lomenie avatar lomenie commented on May 26, 2024 1

I ve got the same....

from numpycnn.

lomenie avatar lomenie commented on May 26, 2024 1

Thanks but still an issue
Working with conv layer 1*
('Filter ', 1)
Traceback (most recent call last):
File "example.py", line 44, in
l1_feature_map = numpycnn.conv(img, l1_filter)
File "/Users/lomenie/Documents/GitHub/NumPyCNN/numpycnn.py", line 78, in conv
conv_map = conv_(img, curr_filter)
File "/Users/lomenie/Documents/GitHub/NumPyCNN/numpycnn.py", line 38, in conv_
curr_result = curr_region * conv_filter
ValueError: operands could not be broadcast together with shapes (2,2) (3,3)

from numpycnn.

lomenie avatar lomenie commented on May 26, 2024

no answer from the developer ?

from numpycnn.

ahmedfgad avatar ahmedfgad commented on May 26, 2024

Thanks for your note.
The shared code is running fine with me and some other people. This is why I got confused of it.
But after investigating the code well, I figured out the source the error and I am planning to work on the code and solve it in the next few days.
Thanks again.

from numpycnn.

ahmedfgad avatar ahmedfgad commented on May 26, 2024

The issue is fixed. The issue was due to incompatibility of shape between the filter and the image region being worked on. It is solved based on such lines:

curr_region = img[r-numpy.uint16(numpy.floor(filter_size/2)):r+numpy.uint16(numpy.ceil(filter_size/2)), 
                              c-numpy.uint16(numpy.floor(filter_size/2)):c+numpy.uint16(numpy.ceil(filter_size/2))]

from numpycnn.

lomenie avatar lomenie commented on May 26, 2024

from numpycnn.

ahmedfgad avatar ahmedfgad commented on May 26, 2024

Yes this is the reason.
The code is running in my PC without error. The same code gives an error on another without changing any part.
At all, the version of Python and NumPy I used are as follows:
The project is tested using Python 3.5.2 installed inside Anaconda 4.2.0 (64-bit)
NumPy version used is 1.14.0

from numpycnn.

lomenie avatar lomenie commented on May 26, 2024

With the first code here is the pb (so I do not think it is a uint type issue)
Working with conv layer 1
('Filter ', 1)
Filter Size
3
('Filter ', 2)
Filter Size
3

ReLU

Pooling
End of conv layer 1

Working with conv layer 2
('Filter ', 1)
Filter Size
5
Filter Size
5
('Filter ', 2)
Filter Size
5
Filter Size
5
('Filter ', 3)
Filter Size
5
Filter Size
5

ReLU

Pooling
End of conv layer 2

Working with conv layer 3
('Filter ', 1)
Filter Size
7
Traceback (most recent call last):
File "NumPyCNN.py", line 129, in
l3_feature_map = conv(l2_feature_map_relu_pool, l3_filter)
File "NumPyCNN.py", line 58, in conv
conv_map = conv_(img[:, :, 0], curr_filter[:, :, 0]) # Array holding the sum of all feature maps.
File "NumPyCNN.py", line 23, in conv_
curr_result = curr_region * conv_filter
ValueError: operands could not be broadcast together with shapes (7,6) (7,7)

from numpycnn.

ahmedfgad avatar ahmedfgad commented on May 26, 2024

I am very thankful for your notes.
You are right. The bug still exist.
I figured a fault that may causing such error after running such code on another device with another version of NumPy.
I figured out that the numpy.ceil was not working correctly. When I run this line,

numpy.uint16(numpy.ceil(3/2))

The expected output is 2 but it returns 1. Due to dividing two integers (3 and 2), the result will also be an integer (1). The ceil of that integer is 1.
Based on that, the region size is calculated based on the following code will be always smaller than the filter size:

            curr_region = img[r-numpy.uint16(numpy.floor(filter_size/2)):r+numpy.uint16(numpy.ceil(filter_size/2)), 
                              c-numpy.uint16(numpy.floor(filter_size/2)):c+numpy.uint16(numpy.ceil(filter_size/2))]

This bug is fixed by making one of the two numbers float. For example, numpy.ceil(filter_size/2.0). The previous code will be as follows:

curr_region = img[r-numpy.uint16(numpy.floor(filter_size/2.0)):r+numpy.uint16(numpy.ceil(filter_size/2.0)), c-numpy.uint16(numpy.floor(filter_size/2.0)):c+numpy.uint16(numpy.ceil(filter_size/2.0))]

from numpycnn.

ahmedfgad avatar ahmedfgad commented on May 26, 2024

The issue is closed for being solved.

from numpycnn.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.