Giter Club home page Giter Club logo

skalskip / ilearndeeplearning.py Goto Github PK

View Code? Open in Web Editor NEW
1.3K 59.0 466.0 273.65 MB

This repository contains small projects related to Neural Networks and Deep Learning in general. Subjects are closely linekd with articles I publish on Medium. I encourage you both to read as well as to check how the code works in the action.

Home Page: https://medium.com/@skalskip

License: MIT License

Jupyter Notebook 99.75% Python 0.23% Shell 0.01% Dockerfile 0.01% Cython 0.01%
neural-network deep-learning visualizations numpy deep-learning-tutorial computer-vision

ilearndeeplearning.py's Introduction

ILearnDeepLearning.py

NumPy NN animation

Description

People say that nothing develops and teaches you like getting your hands dirty. This repository contains small projects mostly related to Deep Learning but also Data Science in general. Subjects are closely linekd with articles I publish on Medium and are intended to complement those blog posts. For me it is a way to document my learning process, but also to help others understand neural network related issues. I hope that the content of the repository will turn out to be interesting and, above all, useful. I encourage you both to read my posts as well as to check how the code works in the action.

Hit the ground running

# clone repository
git clone https://github.com/SkalskiP/ILearnDeepLearning.py.git

# navigate to main directory
cd ILearnDeepLearning.py

# set up and activate python environment
apt-get install python3-venv
python3 -m venv .env
source .env/bin/activate

# install all required packages
pip install -r requirements.txt

Deep Dive into Math Behind Deep Networks

Medium articule - Source code

This project is mainly focused on visualizing quite complex issues related to gradient descent, activation functions and visualization of classification boundaries while teaching the model. It is a code that complements the issues described in more detail in the article. Here are some of the visualizations that have been created.

Keras model frames Keras class boundries

Figure 1. A classification boundaries graph created in every iteration of the Keras model.
Finally, the frames were combined to create an animation.

Gradient descent

Figure 2. Visualization of the gradient descent.

Let’s code a Neural Network in plain NumPy

Medium articule - Source code

After a theoretical introduction, the time has come for practical implementation of the neural network using NumPy. In this notebook you will find full source code and a comparison of the performance of the basic implementation with the model created with Keras. You can find a wider commentary to understand the order and meaning of performed functions in a related article.

NumPy NN animation

Figure 3. Visualisation of the classification boundaries achieved with simple NumPy model

Preventing Deep Neural Network from Overfitting

Medium articule - Source code

This time I focused on the analysis of the reasons for overfitting and ways to prevent it. I made simulations of neural network regulation for different lambda coefficients, analyzing the change of values in the weight matrix. Take a look at the visualizations that were created in the process.

Change of accuracy

Figure 4. Classification boundaries created by: top right corner - linear regression;
bottom left corner - neural network; bottom right corner - neural network with regularisation

Change of accuracy

Figure 5. Change of accuracy values in subsequent epochs during neural network learning.

How to train Neural Network faster with optimizers?

Medium articule - Source code

As I worked on the last article, I had the opportunity to create my own neural network using only Numpy. It was a very challenging task, but at the same time it significantly broadened my understanding of the processes that take place inside the NN. Among others, this experience made me truly realize how many factors influence neural net's performance. Selected architecture,proper hyperparameter values or even correct initiation of parameters, are just some of those things... This time however, we will focus on the decision that has a huge impact on learning process speed, as well as the accuracy of obtained predictions - the choice of the optimization strategy.

Change of accuracy

Figure 6. Examples of points which are a problem for optimization algorithms.

Change of accuracy

Figure 7. Optimizers comparison.

Simple Method of Creating Animated Graphs

Medium articule - Source code

Both in my articles and projects I try to create interesting visualizations, which very often allow me to communicate my ideas much more effectively. I decided to create a short tutorial to show you how to easily create animated visualizations using Matplotlib. I also encourage you to read my post where I described, among other things, how to create a visualization of neural network learning process.

Change of accuracy

Figure 8. Lorenz Attractor created using the Matplotlib animation API.

Gentle Dive into Math Behind Convolutional Neural Networks

Medium articule - Source code

In this post on Medium I focused on the theoretical issues related to CNNs. It is a preparation for the upcoming mini project, which aims to create my own, simple implementation of this type of the Neural Network. As a result, this section of the repository is quite narrow and includes mainly simple visualizations of the effects of a convolution with a selected filter.

Convolution

Figure 9. Convolutionary effect with selected filters.

Chess, rolls or basketball? Let's create a custom object detection model

Medium articule - Source code

My posts on the Medium are usually very theoretical - I tend to analyse and describe the algorithms that define how Neural Networks work. This time, however, I decided to break this trend and show my readers how easy it is to train your own YOLO model, capable of detecting any objects we choose. In order to achieve this goal, we will need help from a very useful and easy-to-use implementation of YOLO. In short, not much coding, but a huge effect.

Convolution

Figure 10. Detection of players moving around the basketball court,
based on YouTube-8M dataset.

Knowing What and Why? - Explaining Image Classifier Predictions

Medium articule - Source code

As we implement highly responsible Computer Vision systems, it is becoming progressively clear that we must provide not only predictions but also explanations, as to what influenced its decision. In this post, I compared and benchmarked the most commonly used libraries for explaining the model predictions in the field of Image Classification - Eli5, LIME, and SHAP. I investigated the algorithms that they leverage, as well as compared the efficiency and quality of the provided explanations.

Explaining predictions

Figure 11. Comparison of explanations provided by ELI5, LIME and SHAP

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Interesting materials and ideas

This is a place where I collect links to interesting articles and papers, which I hope will become the basis for my next projects in the future.

  1. Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddings
  2. Sequence to Sequence Learning with Neural Networks
  3. Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation
  4. BLEU: a Method for Automatic Evaluation of Machine Translation
  5. Neural Machine Translation by Jointly Learning to Align and Translate
  6. A (Long) Peek into Reinforcement Learning
  7. Why Momentum Really Works
  8. Improving the way neural networks learn
  9. Classification and Loss Evaluation - Softmax and Cross Entropy Loss

ilearndeeplearning.py's People

Contributors

anitoanto avatar dependabot[bot] avatar skalskip avatar varad2305 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  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

ilearndeeplearning.py's Issues

there is no "weights" folder

In the "setup_yolo_framework.sh" script, there is this line:
sh weights/download_yolov3_weights.sh

But there is no folder called "weights" in the yolo3 directory structure.. so this fails.

cannot reshape array size.

File "Neural_network.py", line 103, in complete_backward_propagation
y = y.reshape(y_hat.shape)
ValueError: cannot reshape array of size 900 into shape (25,900)
issue

Contour Levels Issue

There seems to be some issue with the contour levels with the code stating "no contour levels were found within the data range"

Numpy deep neural network

Thank you for this wonderful example, which helped me understanding the gradient descent implementation.
I just noticed a minor mistake:

  • dW_curr = np.dot(dZ_curr, A_prev.T) / m
  • db_curr = np.sum(dZ_curr, axis=1, keepdims=True) / m

should be:

  • dW_curr = np.dot(dZ_curr, A_prev.T)
  • db_curr = np.sum(dZ_curr, axis=1, keepdims=True)

In addition:

  • params_values["W" + str(layer_idx)] -= learning_rate * grads_values["dW" + str(layer_idx)]
  • params_values["b" + str(layer_idx)] -= learning_rate * grads_values["db" + str(layer_idx)]

should also be:

  • params_values["W" + str(layer_idx)] -= learning_rate / m * grads_values["dW" + str(layer_idx)]
  • params_values["b" + str(layer_idx)] -= learning_rate / m * grads_values["db" + str(layer_idx)]

Otherwise, the code will not work, for instance if one wants to extend it to implement a regression use-case instead of a classification use-case (i.e. "none" instead of "softmax" in the final layer + court-circuiting the final activation function in the code).

basketball detection

Hi, do you have the training code and data set for basketball detection? Thanks!

"pkg-resources==0.0.0" error

Trying to follow your "hit the ground running"

install all required packages

pip install -r requirements.txt

produces the error

Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r requirements.txt (line 54)) (from versions: )
No matching distribution found for pkg-resources==0.0.0 (from -r requirements.txt (line 54))

taking a look at requirements.txt, line 54 in fact indicates a 0.0.0 version for pkg-resources.

Ask a little question

Thanks for your code
when I run the code in Advanced Visualisation of Lorenz Attractor
I save the code in python file and change the code
anim.save('lorenz_attractor.gif', dpi=80, writer='imagemagick')
to
plt.show()

When I run the code by CMD
It gives me a blank plot
I don't know why...

Prediction TypeError in Let’s code a Neural Network in plain NumPy

I could use

params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)

but there is an error when I implement next step

Y_test_hat, _ = full_forward_propagation(np.transpose(X_test), params_values, NN_ARCHITECTURE)

Here is it

TypeError Traceback (most recent call last)
1 # Prediction
----> 2 Y_test_hat, _ = full_forward_propagation(np.transpose(X_test), params_values, NN_ARCHITECTURE)

in full_forward_propagation(X, params_values, nn_architecture)
8
9 activ_function_curr = layer["activation"]
---> 10 W_curr = params_values["W" + str(layer_idx)]
11 b_curr = params_values["b" + str(layer_idx)]
12

TypeError: tuple indices must be integers or slices, not str

But I think params_values is a dictionary, Why is it? I have copied all the necessary code.
btw, I use Juypter 6.7.0 in Anaconda3 & python 3.6.7

Keyerror : 0

I got an error while running the NumPy neural network code using my dataset,
"'DataFrame' object has no attribute 'reshape'".
Also then I ran using your dataset make_moons, and again I got an error
"Keyerror: 0".

ln [19]:
#Training
params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)[0]

KeyError Traceback (most recent call last)
in ()
1 # Training
----> 2 params_values = train(np.transpose(X_train), np.transpose(y_train.reshape((y_train.shape[0], 1))), NN_ARCHITECTURE, 10000, 0.01)[0]

KeyError: 0

Would you please help me with what to do?
Is it necessary to take the transpose and reshaping the X and y??

numpy implemented model can not work

i copy all the necessary code from your provided Numpy deep neural network.ipynb ,
when i run the code
,Test set accuracy: 0.48 always keep 0.48.
obviously this is not right

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.