fabiochiu/medium-articles huggingface dataset:
Summer
Tags: Heartbreak, Love, Narrative

Summer

The warmth of summer numbs my aching winter heartbreak as I lay in this field. With my eyes closed, I imagine the tenderness the sun gives me as something else, perhaps the arms of another.

Of another. A sweet embrace of no other but mine, to calm and rejuvenate me like the sweetest wines, to whisper holy praises of my very soul into my ear while I doze. The rays of sun enrich me, leaving me like a fat lamb with a stomach full of milk. Perhaps this pretend lover of mine might take my hand in theirs, grazing the top of my rigid hand with their thumb. I may not be dainty, but the sun cures me of the heaviness I have carried my whole life, ridding me of all my worldly problems and remoulding me as perfection.

It is addictive to bask out here, to have my chills cured and my worldly desires cared for by comforting, figments of love. I could rise from my dozy state and reach for the source of this ethereal comfort, and by getting closer I could reach for the only thing I call home. My cheeks flush red from the heat that comforts my face, painting it to be a beautiful yet malnourished, porcelain Lolita.

My malnourished body, starved of affection, begins to show itself. My dress begins to get bigger, as my plumpness fades and leaves me. What is happening? My ribs are showing, my chest tightening with each breath.

The sun is leaving. The clouds cover the skies, decorative harlots to the warmth I crave so terribly. As the sky darkens, I shrink into the ground, wasting away as the sun leaves my presence. Those clouds, those dirty things, stealing my adored, this is a highway robbery! My face wears gaunt, my features diminished by this painful solitude. I am starving for love, for warmth, can they not see? Of course not, they are not true, just figments of my rather colourful imagination like usual.

My skin tears with the cuts of my broken bones; my black blood, devoid of life, soaking into the ground in a heavy stream. The clouds fall upon me, the fresh rain mingling with the remnants of my sliver tears. My looks disintegrate, my skin is paper, and my heart is a cold lump of coal. Nothing is to be left to solitude, as any remnants of past warmth carve into the ground below me.

Fear not for me, Summer, my mind remains fixated on you for all eternity. Your warmth soothes another soul, but as my heart sinks further into the ground, I beg that you might take me back for just one moment.
Broken
By: Lily Storey
Tags: Lost, Love, Heartbreak

I can’t even call my bed my own with your smell of cologne. The bathroom we once shared is now the place i cry and mourn for your return. The living room doesn’t even own up to its name because i feel so much as dead standing in it. The places we used to go now have no place on this earth in my mind. You are long gone but also so close to my heart and it’s close to it’s last pump.
All that is left — Poetry
By: Elise Nin
Tags: Poem, Heartbreak, Poetry On Medium, Poetry, Love

Left out of the sunlight for far too long

we couldn’t bloom, so we slowly withered away

forgotten now, with nowhere to belong

left hanging with broken stems, in an old bouquet
How to solve Multi-Class Classification Problems in Deep Learning with Tensorflow & Keras?
By: Murat Karakaya
Tags: Accuracy, Loss Function, Keras, Multiclass Classification, Activation Functions

This is the third part of the “How to solve Classification Problems in Keras?” series.

If you have not gone over Part A and Part B, please review them before continuing with this tutorial.

The link to all parts is provided below.

In this tutorial, we will focus on how to solve Multi-Class Classification Problems in Deep Learning with Tensorflow & Keras.

First, we will download the MNIST dataset.

In multi-class classification problems, we have two options to encode the true labels by using either:

integer numbers, or

one-hot vector

We will experiment with both encodings to observe the effect of the combinations of various last layer activation functions and loss functions on a Keras CNN model’s performance.

In both experiments, we will discuss the relationship between Activation & Loss functions, label encodings, and accuracy metrics in detail.

We will understand why sometimes we could get surprising results when using different parameter settings other than the generally recommended ones.

As a result, we will gain insight into activation and loss functions and their interactions.

In the end, we will summarize the experiment results in a cheat table.

If you would like to learn more about Deep Learning with practical coding examples, please subscribe to my YouTube Channel or follow my blog on Medium. Do not forget to turn on Notifications so that you will be notified when new parts are uploaded.

You can access this Colab Notebook using the link given in the video description below.

If you are ready, let’s get started!
Adding Start and End Time in a Deep Learning code
By: Rakesh Ts
Tags: Artificial Intelligence, Keras, Machine Learning, Python, Deep Learning

Adding Start and End Time in a Deep Learning code Rakesh TS ·Dec 26, 2020

It is important to calculate the over all time taken for the system to run a DL pipeline.

Objective : To add start and end time to a Deep Learning code.
Introduction to Keras, Part Two: Data Preprocessing
By: Samhita Alla
Tags: Keras, Data, Deep Learning

In the first part of this series, you’ve implemented various data loading techniques. You’ve seen how to load images, text, CSV files, and NumPy arrays into your Keras workspace.

Now to enable the model to make a rightful usage of your data, you’d have to convert it into an understandable format which could then be interpreted by a deep learning algorithm. To do this, you’d have to preprocess your data.

Importing Keras

First import the keras library into your workspace.

from tensorflow import keras

Now you’ll how to preprocess various kinds of data. So here’s the challenge. Every section has the task and its concerned solution. Before you jump to the solution, try solving the given task; that way, you’d be able to understand the preprocessing techniques involved.

Preprocessing Text Data
How to solve Binary Classification Problems in Deep Learning with Tensorflow & Keras?
By: Murat Karakaya
Tags: Accuracy, Loss Function, Keras, Muratkarakayaakademi, Activation Functions

In this tutorial, we will focus on how to select Accuracy Metrics, Activation & Loss functions in Binary Classification Problems.

First, we will review the types of Classification Problems, Activation & Loss functions, label encodings, and accuracy metrics.

Furthermore, we will also discuss how the target encoding can affect the selection of Activation & Loss functions.

Moreover, we will talk about how to select the accuracy metric correctly.

Then, for each type of classification problem, we will apply several Activation & Loss functions and observe their effects on performance.

We will experiment with all the concepts by designing and evaluating a deep learning model by using Transfer Learning on horses and humans dataset.

In the end, we will summarize the experiment results.

I split the tutorial into three parts. In this first part, we will focus on Binary Classification. Next part, we will focus on multi-label classification and multi-label classification.

If you would like to learn more about Deep Learning with practical coding examples, please subscribe to my YouTube Channel or follow my blog on Medium. Do not forget to turn on notifications so that you will be notified when new parts are uploaded.

You can access this Colab Notebook using the link given in the video description below.

Furthermore, you can watch this notebook on Youtube as well!

If you are ready, let’s get started!
Addressing the difference between Keras’ validation_split and sklearn’s train_test_split()
Tags: Neural Networks, Artificial Intelligence, Keras, Overfitting, Data Science

The other alternative: validation_split

An alternative to using train_test_split() is to specify a validation_split percentage. This allows Keras to handle the train/test splitting of the data entirely on its own.

This has numerous advantageous when deploying a model, simply because only library required for using the model will be Keras.

This is done when fitting the model, for example:

It’s worth noting that unlike train_test_split(), Keras splits the data by order of the index, taking the first 80% of the datapoints (in this case) as training data, and the last 20% as test data. A nice visual is shown below:

The advantage of doing this is shown by implementing it:

Since there is now validation data while the model is being trained, it is possible to plot training and test accuracy graphs during training.

Plot of the train and test accuracies while the model is training

The plot above gives us more insight into how the model is training.

We see that at epochs ~170, the model starts to lose test accuracy, meaning that we are overfitting. We also notice another thing: the test accuracy is very noisy. This indicates that the batch_size used is too small, or that the optimiser is not well optimised for this problem. This may impact the decisions we make in trying to improve the model.

However, what is our test accuracy? It would be convenient to get a value, the same way we did when using train_test_split(), using the .evaluate() method.

This is where a lot of people err. Many do something like this:

The intention is to both plot the test plots, and to see the final accuracy of the model using the .evaluate method. However, this will naturally lead to overfit, as exhibited by the output accuracy of 0.803, compared to that of the plot, which seems to be closer to 0.78.

This is because, validation_split and train_test_split() don’t split the data in the same way, and therefore some of the data from X_test is actually being used within .fit, hence the overfit.
Using AI to Draw in the Air!
By: Ashay Parikh
Tags: Neural Networks, AI, Keras, Opencv, Image Processing

Introduction

Last year, I created a Python program that allowed a user to draw letters in the air with an orange highlighter. Along with being intriguing, this project is a great way to introduce Convolutional Neural Networks, Image Segmentation, and other fundamental concepts in the field of Deep Learning and Computer Vision to a beginner.

Today, I have decided to revisit this project and highlight the key steps I took in developing Air Notability.

Solution

All of my code can be found in this GitHub repository.

Step 1: Train a CNN to classify letters

To solve this problem, I started by training a CNN with the EMNIST dataset.

My CNN was pretty basic, with a few convolutional, pooling, and dropout layers before the fully-connected neural network. The model’s accuracy was over 90%, which was sufficient for this project’s purposes.

Step 2: Track the Orange Highlighter

After starting a real-time video capture, the program gets a mask that removes all of the non-orange pixels on the screen. Next, it creates a contour, or a curve that joins all of the orange pixels, and draws a bounding box around groups of orange pixels. This gives us a point, the center of the orange highlighter, which we can add to an array of points if we are drawing or remove from an array if we are erasing. In the end, the array of points is used to draw circles on top of the real-time video capture and form the highlighter’s path.

Step 3: Use the Highlighter’s Path to get a Letter

Finally, we can plot the array of points on a blank image to obtain an actual handwritten letter. After some more processing, the image can be passed into our CNN from Step 1, which outputs the letter that was drawn. This letter is then returned and added to the real-time video capture.

Moving Forward

In my brief explanation, I broke the entire problem of drawing letters in the air with a colored marker into three smaller problems. In addition to learning more about the code that allows you to train neural networks and transform images, I hope that you learned the value of breaking down complex problems.

Please feel free to build off of my code. Here are some suggestions :
SEQUENCE TO SEQUENCE LEARNING
By: Murat Karakaya
Tags: Seq2seq, Encoder Decoder, Attention, Keras, Murat Karakaya Akademi

Hello Everyone!

Due to the importance of Seq2Seq learning, I prepared a series of posts and videos.

You can access all my SEQ2SEQ Learning videos on Murat Karakaya Akademi Youtube channel in ENGLISH or in TURKISH

You can access all tutorial on my Medium blog.

Encoder-Decoder Model with Global Attention

Here is the list of the tutorials:

Part A: AN INTRODUCTION TO SEQ2SEQ LEARNING AND A SAMPLE SOLUTION WITH MLP NETWORK

Part B: SEQ2SEQ LEARNING WITH RECURRENT NEURAL NETWORKS (LSTM)

Part C: SEQ2SEQ LEARNING WITH A BASIC ENCODER DECODER MODEL

Part D: SEQ2SEQ LEARNING WITH AN ENCODER DECODER MODEL WITH TEACHER FORCING

Part E: SEQ2SEQ LEARNING WITH AN ENCODER DECODER MODEL WITH TEACHER FORCING FOR VARIABLE INPUT AND OUTPUT SIZE: MASKING & PADDING

Part F: SEQ2SEQ LEARNING WITH AN ENCODER DECODER MODEL + BAHDANAU & LUONG ATTENTION

Part G: To be continued! :)
Implementation of LeNet From Scratch using Keras.
By: Anjani Suman
Tags: TensorFlow, Keras, Machine Learning, Computer Vision, Deep Learning

Here in this blog, I’m going to discuss the code implementation of LeNet using Keras. In this, I used this research for http://yann.lecun.com/exdb/publis/pdf/lecun-98.pdf for implementation.

LeNet-5 Total seven-layer does not comprise an input, each containing trainable parameters; each layer has a plurality of the Map the Feature, a characteristic of each of the input FeatureMap extracted by means of a convolution filter, and then each FeatureMap There is multiple neurons.

fig1. LeNet Research paper Arch

Library Import

Here this is basic import.

Defining Architecture

First, we define sequential layer here the layer is stack in the form Conv2D and MaxPool2D in repeated form. At last, I use the Dense layer before the dense layer Conv2D and MaxPool2D layer used for feature extraction, and this dense layer used for classification.

Here I did some changes in the activation function and input shape in the original paper they used tanh activation function and the input shape is 32*32. You can see the complete arch in fig1.

To get complete notebook use this link https://github.com/anjanimsp/LeNet_From_Scratch
AI Engineer asks what’s the difference between TensorFlow 1.0 and Tensorflow 2.0
Tags: Artificial Intelligence, TensorFlow, Keras, Ai Engineer, Deep Learning

Since the day Google had released TensorFlow 1.0 in 2017, it gained immediate popularity with machine learning engineers as one of the open-source machine learning libraries. However, two years later, when Google launched its updated version — TensorFlow 2.0 on 30th September 2019 — the entire AI community went into a frenzy.

With AI Engineers around the world debating about the differences between TensorFlow 1.0 and TensorFlow 2.0, it became important to understand the differences between the two.

But before we delve into the differences between the two let’s have a look at some of the TensorFlow facts –

With TensorFlow, almost all the genres of industries were transformed including banking, healthcare, agriculture, pharma to name a few

TensorFlow had played a pivotal role in enabling organizations to leverage AI and thus make their services or products better than before

Talk about being an apple of somebody’s eyes, well TensorFlow quickly became one for almost all the industry biggies including LinkedIn, Twitter, PayPal to name a few

Tensor Flow’s use cases — sentiment analysis, object, and video detection, including image and speech recognition

These were the reasons why TensorFlow 1.0 became such a hit with deep learning enthusiasts. However, there were some loopholes in this renowned open-source ML library, which usually made AI Engineers turn toward other high-level options like PyTorch and Keras.

So again what is the difference between the two?

According to the TensorFlow team, there is no battle between the two versions as TensorFlow 2.0 is an updated version of TensorFlow 2.0.

The makers of TensorFlow have worked diligently on all the drawbacks of TensorFlow 1.0. They had liaised with AI engineers and deep learning enthusiasts to understand the problem areas and then went to work on them. Result: TensorFlow 2.0 — a smarter, a better, and definitely an easier version of TensorFlow 1.0.

https://recentlyheard.com/2020/12/10/ai-engineer-asks-whats-the-difference-between-tensorflow-1-0-and-tensorflow-2-0/
Choosing a hyperparameter tuning library — ray[tune] or aisaratuners?
Tags: TensorFlow, Keras, Machine Learning, Data Science, Python

Aisaratuners

Aisaratuners library is a hyperparameter tuning library for Machine learning models that aims to give you the best optimized model for your dataset. It uses AiSara propreitary state of the art algorithm. Aisaratuners uses Latin Hypercube Sampling to do the initial sampling of hyperparameters and then uses its HyperParameter tuning API which utlilizes SOTA pattern recognition so that the sampling space can be reduced in order to pick the best parameters for your model. It can be better explained by the following image from Aisara medium post.

Image from Aisara Medium Post

Now let’s get hands-on with aisaratuners. We will start by installing and importing it.

!pip install aisaratuners

from aisaratuners.aisara_keras_tuner import Hp, HpOptimization

We will start by first defining the hyperparameters and their space. I will set the same space as I did for ray[tune] for better comparison.

These hyperparameters are used in a function that tries values from this space to figure out the best possible values.

Finally, we have to run the optimizer.

So, Aisaratuners was able to achieve an accuracy of 97.37% in half as many trials (4 vs 8) as ray[tune].

This just shows that aisaratuners converges much faster due to its proprietary state-of-the-art algorithm for finding the best hyperparameters and also results in much better accuracy

The best thing I liked about aisaratuners is its simplicity as we had to do minimum changes which made sense intuitively as well and also that it gives the capability to visualize the process as well. Below are some visualizations about the optimization procedure

Lastly, I wanted to figure out if ray[tune] was able to achieve a higher accuracy if we tested with more trials. I doubled the number of trials from 8 to 16. This resulted in more time taken to find the best hyper parameters but it was able to achieve an accuracy of 97.37% in that case.

Conclusion

We can conclude the following from the experiments:

aisaratuners library was able to outperform ray[tune], both with respect to number of trials (4 versus 8) and test accuracy (97% versus 92%). ray[tune] was able to achieve equal accuracy as compared to aisaratuners but with four times as many trials (4 versus 16). There were less changes in code in aisaratuners as there were incase of ray[tune] i.e, it was much more easy to setup aisaratuners. aisaratuners gives access to an API to plot the optimization process to give a better understanding to the user. I personally did face some issues with ray[tune] when using it with Convolutional Layers.

Feel free to reach out if you have any questions regarding the article. You can check the full code on my Google Colab here
Image classification (persons, animals, other) on raspberry pi from pi-camera (with cycle while) using custom tflite model (output to terminal), TensorFlow Lite
By: Alex G.
Tags: Image Classification, Raspberry Pi, TensorFlow, Keras, Tensorflow Lite

Note before you start:

So, Let’s start :)

Hardware preparation:

Software preparation:

1 Create a neural network model to predict 3 classes persons, animals, others.

I have already done it in the article below. So in this article, you do NOT NEED to DO IT.

2 Convert h5 model to tflite model

I have already done it in the article below. So in this article, you do NOT NEED to DO IT.

3 So, let’s implement our model to image classification (persons, animals, other) on raspberry pi from pi-camera (with cycle while) used custom tflite model (output to terminal)

For that, you need to run the next code:



git clone #clone my repogit clone https://github.com/oleksandr-g-rock/image_classify_tflite_camera_pi_while.git #go to folder

cd image_classify_tflite_camera_pi_while

wget #download tflite modelwget https://github.com/oleksandr-g-rock/how_to_convert_h5_model_to_tflite/raw/main/animall_person_other_v2_fine_tuned.tflite #run script

python3 classify_picamera_with_while_used_tflite.py

4 You should see something like that.

Image classification (persons, animals, other) on raspberry pi from pi-camera (with cycle while) used custom tflite model (output to terminal) (Photo,GIF by Author) https://github.com/oleksandr-g-rock/image_classify_tflite_camera_pi_while/blob/main/demo_while.gif

Result:

In this article, we created image classification (persons, animals, other) on raspberry pi from pi-camera (with cycle while) using custom tflite model (output to terminal). All code located here.
Simple image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal), using TensorFlow Lite
By: Alex G.
Tags: Raspberry Pi, TensorFlow, Keras, Tensorflow Lite, Python

Note before you start:

So, let’s start :)

Hardware preparation:

Software preparation:

1. Create a neural network model to predict 3 classes persons, animals, others.

I have already done it in the article below. So in this article, you do not need to do this.

2 Convert h5 model to tflite model

I have already done it in the article below. So in this article, you do not need to do this.

3 So, let’s implement our model to Simple image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal)

For that, you need to run the next code:



git clone #clone my repogit clone https://github.com/oleksandr-g-rock/image_lassify_tflite_simple.git #go to folder

cd image_lassify_tflite_simple

wget #download tflite modelwget https://github.com/oleksandr-g-rock/how_to_convert_h5_model_to_tflite/raw/main/animall_person_other_v2_fine_tuned.tflite #run script

python3 classify_image_used_tflite.py

4 You should see something like that.

Simple image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal) (Photo,GIF by Author) https://github.com/oleksandr-g-rock/image_lassify_tflite_simple/blob/main/demo_cat.gif

Result:

In this article, we created a solution for simple image classification (persons, animals, others) on raspberry pi using custom model tflite (output to terminal).

I using a custom model tflite which I converted from h5.

And all results will be shown in the terminal. Code for this article is available here.
Using custom metrics for callbacks in Keras model training
By: Anuj Arora
Tags: Custom Metrics, TensorFlow, Keras, Machine Learning, Callback

Keras provides several in-built metrics which can be directly used for evaluating the model performance. However, it is not uncommon to include custom callbacks, to extend beyond keras' capabilities, as I myself had to do recently. In this post, I discuss how to use custom calculated values (metrics, losses) with in-built callbacks.

Before proceeding, we will need to define our own custom callback to carry out calculations that we want for tracking the training progress or evaluate the model performance. Below is a dummy code for defining a custom callback.

CustomCallback(keras.callbacks.Callback):

def on_epoch_end(self, epoch, logs={}):

:

do_somthing_here

:

logs["metric_name"] = metric_value

Once custom callback is defined, the related custom metric can be included in the other callbacks

ckpt_callback = ModelCheckpoint(

path_to_file,

monitor="metric_name",

mode="Specify depending on desired behavior of the metric",

save_freq="as above",

)

This behavior is not limited to exchanging data from custom callbacks to the in-built callbacks, but can be extended across all callbacks, since the 'log' object is passed automatically to all of them through model.fit(). Similar workflow will work with other default callbacks like EarlyStopping, etc. where the functionality is dependent on a custom defined value/metric.
How to convert h5 model to tflite (TensorFlow Lite) model
By: Alex G.
Tags: Tflite, Colab, TensorFlow, Keras, Python

So, Let’s start :)

We need to convert the model from h5 format to tflite format.

At first, we need to create a neural network model with h5 format.

I have already done it in the article below. So in this article, you do NOT NEED to DO IT.

Convert h5 model to tflite model

For that, we can use my notebook. And you can see a small gif guide below :)

How to convert h5 model to tflite model (Photo,GIF by Author) https://github.com/oleksandr-g-rock/how_to_convert_h5_model_to_tflite/blob/main/0_TAILXgr4HU9CIDAm.gif

I saved these converted tflite model here.
Create image classification for recognizing persons, animals, others. Using TensorFlow
By: Alex G.
Tags: TensorFlow, Keras, Matplotlib, Python, Computer Vision

So, Let’s start :)

At first, we need a dataset with the next classes:

- Person

- Animals

- Other

Let me describe what each class I mean:

In a first-class “person”, we should have any images of peoples but WITHOUT ANIMALS.

In the next class “animals”, we should have images with animals WITHOUT HUMAN.

In this class, including images with the next classes:

dog (different breeds), squirrel (different breeds), horse, chicken, cats, raccoon, deer.

In this class, including images with the next classes: dog (different breeds), squirrel (different breeds), horse, chicken, cats, raccoon, deer. In the last class “other”, we should have any images WITHOUT HUMAN AND ANIMAL.

I created a dataset with 113k. images with 3 classes which I described above.

This dataset was created from a lot of datasets Kaggle platform:

Person:

Animals:

Other:

I already created a notebook that already does this. But, if you want run this notebook in colab you need to create datasets manually.

You can just open a notebook in Colab and watch how model training :)

I created a model that has a result for NEW data: 0.008% for loss and 100.00% accuracy. I guess it’s a perfect result.

confusion matrix (Photo,GIF by Author) https://github.com/oleksandr-g-rock/How_to_create-image-classification-for-recognizing-persons-animals-others/blob/main/0_w1p1XToA7zVEMsAk.png

So link for the notebook here.

Also, I saved the best model file (with format h5) with the best result here.

Result:

- I created a model that has a result for NEW data: 0.008% for loss and 100.00% accuracy. I guess it’s a perfect result.

- link for the notebook here.

- Code for this article available here.

- I saved the best model file (with format h5) with the best result here.
Dealing with memory leak issue in Keras model training
By: Anuj Arora
Tags: Callback, TensorFlow, Keras, Validation, Memory Leak

Recently, I was trying to train my keras (v2.4.3) model with tensorflow-gpu (v2.2.0) backend on NVIDIA’s Tesla V100-DGXS-32GB. When trained for large number of epochs, it was observed that there was memory build-up / leakage. What this meant was, as the training progressed, it was consuming more and more disk space until none was left, crashing the job or system.

One look over the internet and it was clear that, this problem has been around for sometime now. Some users, linked the issue to model.predict(), which I had included in my callbacks.

In the same discussion, a suggested solution was:

Instead of passing a np.array to the model.predict(), pass a tensor by using tf.convert_to_tensor(). The associated explanation mentions that,

for loop with a numpy input creates a new graph every iteration because the numpy array is created with a different signature. Converting the numpy array to a tensor maintains the same signature and avoids creating new graphs.

Going by the explanation from the solution above, another proposed solution I could find was replacing model.predict() with model.predict_on_batch().

I also tried cloning the trained model using keras.models.clone(model), and use the cloned model, as in, cloned_model.predict(). After the predict step, I’d delete the cloned model, hoping it will deal with the issue mentioned above.

Unfortunately, all the above strategies failed to solve the problem for me, even though it seems like it the first couple had worked for others. The solution that ultimately worked,

Include gc.collect() and keras.backend.clear_session() after the model.predict().

With this, I could finally train the model with a constant disk usage.
Super easy Python stock price forecast (using keras / lstm) Deep learning
Tags: Keras, Lstm, Python, Stock Price Forecast, Deep Learning

Super easy Python stock price forecast (using keras / lstm) Deep learning

Super easy deep learning (using lstm) to predict the ups and downs of the next day’s stock price using keras in Python 10mohi6 ·Nov 27, 2020

1. tool installation

$ pip install scikit-learn keras pandas_datareader

2. file creation

3. execution

$ python pred.py

That’s super easy!

4. result

As a result of calculation with the same data and features, DNN, LogisticRegression, BernoulliNB are the best among XGBoost, DNN, LSTM, GRU, RNN, LogisticRegression, k-nearest neighbor, RandomForest, BernoulliNB, SVM.

XGBoost 0.5119047619047619

DNN 0.5496031746031746

LSTM 0.5178571428571429

GRU 0.5138888888888888

RNN 0.5376984126984127

LogisticRegression 0.5496031746031746

k-nearest neighbor 0.5198412698412699

RandomForest 0.49603174603174605

BernoulliNB 0.5496031746031746

SVM 0.5396825396825397

5. reference
Super easy Python stock price forecast (using keras / dnn) Deep learning
Tags: Dnn, Keras, Python, Stock Price Forecast, Deep Learning

Super easy Python stock price forecast (using keras / dnn) Deep learning

Super easy deep learning (using dnn) to predict up and down stock prices the next day using keras in Python 10mohi6 ·Nov 26, 2020

1. tool installation

$ pip install scikit-learn keras pandas_datareader

2. file creation

3. execution

$ python pred.py

That’s super easy!

4. result

As a result of calculation with the same data and features, DNN, LogisticRegression, BernoulliNB are the best among XGBoost, DNN, LSTM, GRU, RNN, LogisticRegression, k-nearest neighbor, RandomForest, BernoulliNB, SVM.

XGBoost 0.5119047619047619

DNN 0.5496031746031746

LSTM 0.5178571428571429

GRU 0.5138888888888888

RNN 0.5376984126984127

LogisticRegression 0.5496031746031746

k-nearest neighbor 0.5198412698412699

RandomForest 0.49603174603174605

BernoulliNB 0.5496031746031746

SVM 0.5396825396825397

5. reference
⌚Configure TensorFlow 2.0 Environment in Windows in 10 minutes 😁
By: Rahul Kushwaha
Tags: Recognition, TensorFlow, Opencv, Machine Learning, Keras

✅Step 1: Download and install/update the latest Version of Python from the official website (Don’t forget to check the ‘Add Python to PATH’)

https://www.anaconda.com/products/individual

Do check this

✅Step 2: Download and install Anaconda Installer from official website for Windows.😀

https://www.python.org/downloads/

✅Step 3: Open Edit Environmental Variables in Windows, and three new paths as given below:👍

1. C:\Users\yourusername\anaconda3\Scripts 2. C:\Users\yourusername\anaconda3 3. C:\Users\yourusername\anaconda3\Library\bin

In my System,

Paths

✅Step 4: Now,😊 Run the Command Prompt as Administrator and type the commands as given below:

1) conda create -n tf1 tensorflow ( Here tf1 is the name for our new environment , created especially to run TensorFlow ) 2) conda activate tf1

✅Step 5: Now You are ready to import tensorflow in this new environment.💪

Commands for importing Keras

1). from tensorflow.keras.preprocessing.image import img_to_array

2). from tensorflow.keras.models import load_model

✅Step 6: Now you are ready to work on your Machine Learning Project. Just run your programs by activating this new environment tf1.

THE END , thanks for reading….

⌚Commands for installing important libraries

pip install opencv-python

pip install pillow — upgrade

pip install opencv-contrib-python — upgrade — user

pip install imutils

Original Article written at:
LSTM: Understanding the Number of Parameters
By: Murat Karakaya
Tags: Parameters, Lstm, Keras, Learnable Parameters, Python

In this tutorial, we will focus on internal structure of Keras LSTM layer in order to understand how many learnable parameters an LTSM layer has.

Why do we need to care of calculating number of parameters in LSTM layer since we can easily get this number in the model summary report?

Well there are several reasons:

First of all, to calculate the number of learnable parameters correctly, we need to understand how LSTM is structured and how LSTM operates in depth . Thus, we will delve into LSTM gates and gate functions. We will gain precious insight about how LSTM handles time dependent or sequence input data.

and how . Thus, we will delve into LSTM gates and gate functions. We will gain precious insight about how LSTM handles or input data. Secondly, in ANN models, number of parameter is a really important metric for understanding the model capacity and complexity. We need to keep an eye on the number of parameters of each layer in the model to handle overfitting or underfitting situations. One way to prevent these situations is to adjust the number of parameters of each layer. We need to know how number of parameters actullay affects the performance of each layer.

If you want to enhance your understanding of LSTM layer and learn how many learnable parameters it has please continue this tutorial.

By the way, I would like to mention that in my Youtube channel I have a dedicated playlist in English (All About LSTM) and in Turkish (LSTM Hakkında Herşey). You can check these playlist to learn more about LSTM.

Lastly, if you want to be notified for upcoming tutorials about LSTM and Deep Learning please subscribe to my Youtube channel and activate notifications.

Thank you!

Now, let’s get started!
Fine-Tuning Pre-trained Model VGG-16
By: Muriel Kosaka
Tags: Transfer Learning, Keras, Python, Emotion Recognition, Deep Learning

After importing the necessary libraries, our train/test set, and preprocessing the data (described here), we dive into modeling:

First, import VGG16 and pass the necessary arguments:

from keras.applications import VGG16 vgg_model = VGG16(weights='imagenet', include_top=False, input_shape=(224, 224, 3))

2. Next, we set some layers frozen, I decided to unfreeze the last block so that their weights get updated in each epoch

# Freeze four convolution blocks

for layer in vgg_model.layers[:15]:

layer.trainable = False # Make sure you have frozen the correct layers

for i, layer in enumerate(vgg_model.layers):

print(i, layer.name, layer.trainable)

Image by Author

Perfect, so we will be training our dataset on the last four layers of the pre-trained VGG-16 model.

3) I used the same model architecture from my previous VGG-16 model as a feature extractor:

x = vgg_model.output

x = Flatten()(x) # Flatten dimensions to for use in FC layers

x = Dense(512, activation='relu')(x)

x = Dropout(0.5)(x) # Dropout layer to reduce overfitting

x = Dense(256, activation='relu')(x)

x = Dense(8, activation='softmax')(x) # Softmax for multiclass

transfer_model = Model(inputs=vgg_model.input, outputs=x)

4) Let’s set some callbacks, such as ReduceLROnPlateau and ModelCheckpoint. ReduceLROnPlateau is helpful especially in fine-tuning our model because as described by Pedro Marcelino, high learning rates increase the risk of losing previous knowledge so it is best to set a low learning rate, and with ReduceLROnPlateau, this can help us out with that! ModelCheckpoint is always helpful since it allows us to define where to checkpoint our model weights.

from keras.callbacks import ReduceLROnPlateau lr_reduce = ReduceLROnPlateau(monitor='val_accuracy', factor=0.6, patience=8, verbose=1, mode='max', min_lr=5e-5) checkpoint = ModelCheckpoint('vgg16_finetune.h15', monitor= 'val_accuracy', mode= 'max', save_best_only = True, verbose= 1)

4) Next, we compile and fit our model

from tensorflow.keras import layers, models, Model, optimizers learning_rate= 5e-5 transfer_model.compile(loss="categorical_crossentropy", optimizer=optimizers.Adam(lr=learning_rate), metrics=["accuracy"]) history = transfer_model.fit(X_train, y_train, batch_size = 1, epochs=50, validation_data=(X_test,y_test), callbacks=[lr_reduce,checkpoint])
Simple image classification on raspberry pi using the pre-trained model VGG16 and TensorFlow
By: Alex G.
Tags: Image Classification, AI, Raspberry Pi, Keras, Machine Learning

Note before you start:

So, Let’s start :)

Hardware preparation:

Software preparation:

1 Create file image_classify.py with next code:

In this example, I will use the pre-train model VGG16, but you can try to use any pre-train model.

#import modules

from keras.applications.vgg16 import VGG16

from keras.preprocessing import image

from keras.applications.vgg16 import preprocess_input, decode_predictions

import numpy as np #load imgenet vgg16 model

model = VGG16(weights='imagenet') #load image and change size to 224*224

img_path = 'demo.jpg'

img = image.load_img(img_path, target_size=(224, 224)) #convert image to array

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = preprocess_input(x) #predict class for image

preds = model.predict(x)

print('Result:', decode_predictions(preds, top=1)[0])

2 run script for recognizing the image

python3 image_classify.py

3 You should see something like that

Simple image classification on raspberry pi using the pre-trained model VGG16 (Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_classification_pi_vgg16_pretrain_model/blob/main/1_P6WMPQdlMVmaFpLap3ResA.png

And this result absolutely right :)

Result:

In this article, we created simple image classification on raspberry pi using the pre-trained model VGG16. All code is located here.
Simple image classification on raspberry pi from pi-camera using the pre-trained model VGG16 and TensorFlow
By: Alex G.
Tags: AI, Raspberry Pi, Keras, Machine Learning, Python

Note before you start:

So, Let’s start :)

Hardware preparation:

Software preparation:

1 So, for that, you need to create a new file image_classify.py with the next code:

#import modules

from keras.applications.vgg16 import VGG16

from keras.preprocessing import image

from keras.applications.vgg16 import preprocess_input, decode_predictions

import numpy as np

from picamera import PiCamera #load imgenet vgg16 model

model = VGG16(weights='imagenet') #create photo from pi camera

camera = PiCamera() #save photo with name image.jpeg in this folder

camera.capture('image.jpeg') #load image and change size to 224*224

img_path = 'image.jpeg'

img = image.load_img(img_path, target_size=(224, 224)) #convert image to array

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = preprocess_input(x) #predict class for image

preds = model.predict(x)

print('Result:', decode_predictions(preds, top=3)[0])

Let me explain what this code will do:

At first, these two lines made a photo and save it to an image.jpeg file

camera = PiCamera()

camera.capture('image.jpeg')

After that, this code will classify (predict top 3 classes) what is in the photo

img_path = 'image.jpeg'

img = image.load_img(img_path, target_size=(224, 224))

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = preprocess_input(x)

preds = model.predict(x)

print('Result:', decode_predictions(preds, top=3)[0])

2 run script for recognizing the image.

python3 image_classify.py

3 you should see some predicts in terminal like that

Simple image classification on raspberry pi from pi-camera using the pre-trained model VGG16 (Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_classification_pi_vgg16_pretrain_model_from_pi_camera/blob/main/1_ERh8oKFSssQrAIiA_Yma_Q.png

Result:

In this article, we created simple image classification on raspberry pi from pi-camera using the pre-trained model VGG16.

In this example, I using the pre-train model VGG16, but you can try to use any pre-train model. All code is located here.
遷移式學習 (Transfer Learning)
Tags: Transfer Learning, Pre Trained Model, TensorFlow, Keras, Pytorch

ImageNet

ImageNet is an image database organized according to the WordNet hierarchy (currently only the nouns), in which each…
Fundamentos de Deep Learning na prática (parte 3)
By: Matheus De Andrade Silva
Tags: Keras, Data Science, Redes Neurais, Deep Learning

Information Technology / Computer Science student at Federal University of Rio Grande do Norte (UFRN), Natal, Brazil.
Book : Deep Learning Models explored with help of Python Programming
By: Ijsmi Books
Tags: TensorFlow, Keras, Python, Model, Deep Learning

Book : Deep Learning Models explored with help of Python Programming ijsmi books ·Nov 7, 2020

This is the second book in Deep Learning models series by the author. Deep learning models are widely used in different fields due to its capability to handle large and complex datasets and produce the desired results with more accuracy at a greater speed. In Deep learning models, features are selected automatically through the iterative process wherein the model learns the features by going deep into the dataset and selects the features to be modeled. In the traditional models the features of the dataset needs to be specified in advance. The Deep Learning algorithms are derived from Artificial Neural Network concepts and it is a part of broader Machine Learning Models.

The book starts with the Introduction part which is adopted from Author’s Deep Learning Models and its application: An overview with the help of R software book and move on to the Python’s important data processing packages such Numpy, and Pandas.

Book then explores the Deep Leaning models with the help of packages such as Pytorch, Tensor Flow and Keras and their applications in image processing, stock market prediction, recommender systems and natural language processing.

Editor

International Journal of Statistics and Medical Informatics

www.ijsmi.com/book.php

ISBN: 9798558877953

E-Books: https://www.amazon.com/dp/B08MQTM1ZP

Paperbacks: https://www.amazon.com/dp/B08MSQ3R8R
Generating cats with Tensorflow
By: Erik Hric
Tags: AI, TensorFlow, Keras, Machine Learning, Docker

Necessary steps

Swap the dataset,

Reshape the data,

Increase image resolution,

Serve model from docker.

New Dataset

For this demo we’ll use dataset of cat faces from kaggle. It contains images of 15K cats at resolution of 64x64.

Sample cat faces from dataset (https://www.kaggle.com/spandan2/cats-faces-64x64-for-generative-models)

Google uses this line to initialise train_images and train_labels variables.

(train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()

We’ll take the lazy approach and replace its contents with our cats. To do so create data directory with the following structure. Our data/catdata folder contains one subfolder catface with images. If your dataset contains more classes place their images in a folder on the same level as catface. Folder names and class_names must match.

You can read more about directory structure parameters here and here.

cat_dataset = tf.keras.preprocessing.image_dataset_from_directory(

"./data/catdata",

labels="inferred",

label_mode="int",

class_names=['catface'],

color_mode="grayscale",

batch_size=32,

image_size=(img_size, img_size), #img_size should be 28 for now

shuffle=True,

seed=None,

validation_split=None,

subset=None,

interpolation="bilinear",

follow_links=False,

)

Data reshaping

Next step is to iterate over the cat_dataset structure and transform it into the same structure as MNIST had.

cat_train_labels = []

cat_train_images = [] for images, labels in cat_dataset:

for i in range(len(images)):

cat_train_images.append(images[i])

cat_train_labels.append(labels[i]) c_images = np.array(cat_train_images)

c_images = c_images.reshape(c_images.shape[0],img_size,img_size,) c_labels = np.array(cat_train_labels)

c_labels = c_labels.reshape(c_labels.shape[0],)

Ensure that our data shape matches the original data shape (except for the count of items).

print(c_images.shape)

print(train_images.shape) print(c_labels.shape)

print(train_labels.shape) train_labels = c_labels

train_images = c_images

Without any further modifications, your training process should be able to start with the original resolution of 28x28.

Training progress of 250 epochs with resolution of 56x56 (faulty run with only ~4K samples)

Before proceeding you may want to store your reshaped numpy arrays to files: (Source)

from numpy import save

save('./data/images.npy', c_images)

save('./data/labels.npy', c_labels)

Increasing the resolution

28x28 may be enough for handwritten digits, but for pictures of cats it is not that much. To get a higher resolution predictions we need to change size of the discriminator and generator model layers.

The golden rule: Output size of the generator should match the input size of the discriminator. I messed around with the numbers, but I ended up with the following:
Quick PlaidML MacOS Installation Guide
By: Kenny Lim
Tags: Installation, Gpu, Keras, Machine Learning, Data Science

Here you can see that we have reduced the wall time to only 1/3 of the time taken by the cpu, from 9 mins to 3 mins.

Tips:

For anyone unsure if it is working for you. Check GPU acitvity using activity monitor. Launch activity monitor -> Go to window -> gpu history

you can the see gpu fired up in the “AMD Radeon Pro 450” window

Conclusion:

Well, as promised a quick and fuss free guide to installing and using to utilising the GPU on your macbook in jupyter notebook. Feel free to leave a comment if anything doesn’t work out. Oh yes, the codes used in this story can be found on my github: https://github.com/kennylimyx/plaidml
Convert Darknet model to Keras model
By: Nanyoung Kim
Tags: Darknet, Keras, Macos

keras-yolo3 클론

https://github.com/qqwweee/keras-yolo3

2. yolo3-tiny.weights 다운로드

https://pjreddie.com/media/files/yolov3-tiny.weights

위 링크를 클릭하면 다운이 된다. 다운받은 파일을 위에 클론한 레포지토리에 넣는다.

3. weights를 .h 로 변환

잘 돌아가는지 테스트해보자.

python convert.py yolov3-tiny.cfg yolov3-tiny.weights model_data/yolo_tiny.h5

위의 코드를 실행시키자 아래와 같은 오류가 발생했다.

File "/Users/kimnan-young/opt/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 703, in is_tensor return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x) AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

4. Tensorlike module 오류 해결

/Users/kimnan-young/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py

파일의 212line 을 보자.

def is_dense_tensor_like(t): return isinstance(t, core_tf_types.Tensor)

리턴 값의 두번째 파라미터 값(core_tf_types.Tensor)을 복사한다.

/Users/kimnan-young/opt/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py

파일에서 문제가 발생한 703line을 아래와 같이 수정한다.

def is_tensor(x): # return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x) return isinstance(x, tf_ops.core_tf_types.Tensor) or tf_ops.is_dense_tensor_like(x)

주석처리 한 부분이 고치기 전이고 두번째 리턴이 고친 후이다.

5. .h 파일 생성

yolo_tiny.h5 파일이 생성되었다.

에서 dodg.jpg 파일을 다운 받고 아래 코드를 실행시켰다.

from IPython.display import display

from PIL import Image

from yolo import YOLO



def objectDetection(file, model_path, class_path):

yolo = YOLO(model_path=model_path, classes_path=class_path, anchors_path="model_data/tiny_yolo_anchors.txt")

image = Image.open(file)

result_image = yolo.detect_image(image)

display(result_image)



objectDetection('dog.jpg', 'model_data/yolo_tiny.h5', 'model_data/coco_classes.txt')

잘 돌아간다.