GithubHelp home page GithubHelp logo

ahmedfgad / numpycnn Goto Github PK

View Code? Open in Web Editor NEW
559.0 26.0 188.0 2.61 MB

Building Convolutional Neural Networks From Scratch using NumPy

Home Page: https://pygad.readthedocs.io

Python 100.00%
numpy convolutional-neural-networks convnet cnn python computer-vision data-science relu relu-layer convolution

numpycnn's People

Contributors

ahmedfgad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numpycnn's Issues

Conv function error condition

Hi Ahmed,

    if len(img.shape) > 2 or len(conv_filter.shape) > 3: # Check if number of image channels matches the filter depth.
        if img.shape[-1] != conv_filter.shape[-1]:
            print("Error: Number of channels in both image and filter must match.")
            sys.exit()

The above snippet in the conv function checks for channel mismatch. But, if len(img.shape) is greater than 2 (eg - (224, 224, 3)), and the conv_filter's shape is (2,3,3), then the condition if img.shape[-1] != conv_filter.shape[-1] is False , even though the number of channels of the image, and the conv_filter, are not the same.
One possible solution is -

    if len(img.shape) != len(conv_filter.shape) - 1: # Check whether number of dimensions is the same
        print("Error: Number of dimensions in conv filter and image do not match.")  
        exit()
    if len(img.shape) > 2 or len(conv_filter.shape) > 3: # Check if number of image channels matches the filter depth.
        if img.shape[-1] != conv_filter.shape[-1]:
            print("Error: Number of channels in both image and filter must match.")
            sys.exit()

size of pool_out

The size of input image is (512,512), and the size of conv1_out is (510,510), the size of pool_out should be (255,255). However the size of pool_out is (254,254). So I suggest that the codes in pooling() function should be changed as following:
pool_out = np.zeros((np.uint16((feature_map.shape[0]-size)/stride+1),
np.uint16((feature_map.shape[1]-size)/stride+1),
feature_map.shape[-1]))

sigmoid(sop) function not numerically safe

The current implementation of the sigmoid() function can get a RuntimeWarning overflow in cnn.py at line 29 numpy.exp():
"return 1.0 / (1 + numpy.exp(-1 * sop))"
To avoid/correct the overflow, use:
"return numpy.exp(-numpy.logaddexp(0, -sop))"

小白学习CNN的问题

就是在第二层和第三层的卷积核为什么要用随机数赋值,不是很懂这些原理

how to create my own dataset?

your code is wonderful!
but I have one question: how to create my own dataset use code. And how to label or training it?
thank you !

A code error in relu function

The current relu function actually does no work for the feature_map.
The code relu_out[r, c, map_num] = numpy.max(feature_map[r, c, map_num], 0) should be written as
relu_out[r, c, map_num] = numpy.max([feature_map[r, c, map_num], 0])
And thanks for the code you shared!

some bugs to fix in pooling() and relu()

@ahmedfgad

in the pooling()
change the "feature_map.shape[0]-size+1)/stride" to "feature_map.shape[0]-size)/stride+1"

NumPyCNN/NumPyCNN.py

Lines 85 to 87 in aac7afd

pool_out = numpy.zeros((numpy.uint16((feature_map.shape[0]-size+1)/stride),
numpy.uint16((feature_map.shape[1]-size+1)/stride),
feature_map.shape[-1]))

pool_out = numpy.zeros((numpy.uint16((feature_map.shape[0]-size)/stride+1), 
                         numpy.uint16((feature_map.shape[1]-size+1)/stride+1), 
                         feature_map.shape[-1])) 

in the relu()
change the "feature_map.shape[1]-size-1" to "feature_map.shape[1]-size+1" to arrive at the end.

for r in numpy.arange(0,feature_map.shape[0]-size-1, stride):

 for r in numpy.arange(0,feature_map.shape[0]-size+1, stride): 

for c in numpy.arange(0, feature_map.shape[1]-size-1, stride):

 for c in numpy.arange(0, feature_map.shape[1]-size+1, stride): 

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.