×

Microsoft Releases Entity Framework Core 3.0 Preview 7 and Entity Framework 6.3 Preview 7

MMS Founder
MMS RSS

Article originally posted on InfoQ. Visit InfoQ

Last week Microsoft released Entity Framework Core 3.0 Preview 7 and Entity Framework 6.3 Preview 7.

Entity Framework 6 (EF6) was first released in 2008 and runs on the .NET Framework 4.x (available only on Windows). Entity Framework Core (EF Core) is a complete cross-platform rewrite of EF6 that can run on .NET Core or .NET Framework. A detailed feature comparison between EF Core and EF6 can be found here.

The new previews were made available on the same day of .NET Core 3.0 Preview 7 and ASP.NET Core 3.0 Preview 7. The release schedule for EF Core is in-sync with the .NET Core release schedule.

Supporting EF6 on .NET Core is one of the major features for the EF6.3 release. With the release of Preview 7, the majority of the work related to this feature has been completed.

One of the major roadmap goals of EF Core 3.0 involves making profound changes in the existing LINQ implementation. Related updates in Preview 7 include support to SQL translation of LINQ set operators like Union, Concat, Intersect, and Except. The release also includes a new API for intercepting database operations (similarly to the interception feature in EF6). Intercepting database operations allow simple logic (interceptors) to be invoked before or after database operations happen (such as committing a transaction or opening a connection).

Other changes include the postponing of two major features, originally planned for EF Core 3.0: support for property bag entities and the ability to ignore parts of the model for migrations. Also, a list of breaking changes (changes that have the potential to break applications developed for EF Core 2.2.x) is being kept up to date on every preview.

EF Core 3.0 and EF6 are both distributed as NuGet packages. Given the rapid pace of development in EF Core 3.0, Microsoft recommends switching to the nightly build of Preview 8 to try fixes that are not included in Preview 7.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


Microsoft Announces ML.NET 1.2

MMS Founder
MMS RSS

Article originally posted on InfoQ. Visit InfoQ

Earlier this month Microsoft announced ML.NET 1.2, along with updates on its Model Builder and CLI.

ML.NET is an open-source, cross-platform machine learning (ML) framework for the .NET ecosystem. Its main purpose is to allow the development of custom ML models using either C# or F#. It includes a UI tool for Visual Studio (called Model Builder, available only for Windows) and a Command-line interface (CLI).

The new version of ML.NET includes a TimeSeries package for forecasting and anomaly detection scenarios. It also includes the general availability of TensorFlow and ONNX model integration features, which allow the construction of machine learning and deep learning models involving image classification and object detection.

A new integration package called Microsoft.Extensions.ML was also released as a preview feature. The purpose of this package is to make it easier to integrate ML.NET models with ASP.NET apps, Azure Functions, and web services. An example of how to use it to integrate an ML.NET model with ASP.NET Core can be found here.

Another new feature is the addition of tree-based featurization. This is a popular data mining technique used in scenarios such as predicting clicks on online advertisements, for example.

Other updates include bug fixes in the ML.NET CLI and smaller additions to the Model Builder, such as support for .txt files (used for model training) and removal of size limit for training data (originally capped at 1GB). The release notes for ML.NET 1.2 can be found here.

ML.NET is available for Windows, Linux, and macOS. The Windows release requires Visual Studio 2017 15.9.12 or later since the model builder is available as a Visual Studio extension. There are no prerequisites for macOS and Linux, but in these platforms, the ML.NET models are built using a CLI. You can learn more about ML.NET here.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


R-CNN, Fast R-CNN, Faster R-CNN, YOLO — Object Detection Algorithms

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

This article was written by Rohith Gandhi.

Introduction

Computer vision is an interdisciplinary field that has been gaining huge amounts of traction in the recent years(since CNN) and self-driving cars have taken centre stage. Another integral part of computer vision is object detection. Object detection aids in pose estimation, vehicle detection, surveillance etc. The difference between object detection algorithms and classification algorithms is that in detection algorithms, we try to draw a bounding box around the object of interest to locate it within the image. Also, you might not necessarily draw just one bounding box in an object detection case, there could be many bounding boxes representing different objects of interest within the image and you would not know how many beforehand.

The major reason why you cannot proceed with this problem by building a standard convolutional network followed by a fully connected layer is that, the length of the output layer is variable — not constant, this is because the number of occurrences of the objects of interest is not fixed. A naive approach to solve this problem would be to take different regions of interest from the image, and use a CNN to classify the presence of the object within that region. The problem with this approach is that the objects of interest might have different spatial locations within the image and different aspect ratios. Hence, you would have to select a huge number of regions and this could computationally blow up. Therefore, algorithms like R-CNN, YOLO etc have been developed to find these occurrences and find them fast.

 

R-CNN

To bypass the problem of selecting a huge number of regions, Ross Girshick et al. proposed a method where we use selective search to extract just 2000 regions from the image and he called them region proposals. Therefore, now, instead of trying to classify a huge number of regions, you can just work with 2000 regions.

These 2000 candidate region proposals are warped into a square and fed into a convolutional neural network that produces a 4096-dimensional feature vector as output. The CNN acts as a feature extractor and the output dense layer consists of the features extracted from the image and the extracted features are fed into an SVM to classify the presence of the object within that candidate region proposal. In addition to predicting the presence of an object within the region proposals, the algorithm also predicts four values which are offset values to increase the precision of the bounding box. For example, given a region proposal, the algorithm would have predicted the presence of a person but the face of that person within that region proposal could’ve been cut in half. Therefore, the offset values help in adjusting the bounding box of the region proposal.

 

Problems with R-CNN

  • It still takes a huge amount of time to train the network as you would have to classify 2000 region proposals per image.
  • It cannot be implemented real time as it takes around 47 seconds for each test image.
  • The selective search algorithm is a fixed algorithm. Therefore, no learning is happening at that stage. This could lead to the generation of bad candidate region proposals.

 

Fast R-CNN

The same author of the previous paper(R-CNN) solved some of the drawbacks of R-CNN to build a faster object detection algorithm and it was called Fast R-CNN. The approach is similar to the R-CNN algorithm. But, instead of feeding the region proposals to the CNN, we feed the input image to the CNN to generate a convolutional feature map. From the convolutional feature map, we identify the region of proposals and warp them into squares and by using a RoI pooling layer we reshape them into a fixed size so that it can be fed into a fully connected layer. From the RoI feature vector, we use a softmax layer to predict the class of the proposed region and also the offset values for the bounding box.

The reason “Fast R-CNN” is faster than R-CNN is because you don’t have to feed 2000 region proposals to the convolutional neural network every time. Instead, the convolution operation is done only once per image and a feature map is generated from it.

 

To read the whole article, with illustrations, graphs and their explanations, click here.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


What is “The Art of Thinking Like a Data Scientist” Workbook and Why It Matters

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

For over 3 decades, my passion has been to assist organizations leverage the business potential of data and analytics and help them envision where and how data and analytics can generate new sources of customer, product and operational value. Maybe my fascination with data and analytics started in my youth with “Strat-o-Matic Baseball” but it certainly caught fire at Metaphor Computers in the 1980’s where I built some of the early Business Intelligence and data warehouse systems. In the 1990’s I joined Sequent Computers where I developed the “Business Benefit Analysis” methodology – a precursor to the “Thinking Like a Data Scientist” methodology.  Then at Business Objects, Yahoo, EMC, University of San Francisco, National University of Ireland – Galway and now at Hitachi Vantara, I’ve had the good fortune to work with customers and students to continuously test, tweak and refine the methodology. All of my learnings are captured in my new book “The Art of Thinking Like a Data Scientist.”

Thanks for your joining me on this journey.

 

To survive in today’s digital economy, it’s imperative for organizations to convert their key business stakeholders into “Citizens of Data Science.” Meaning, they should not only understandwhereand howto apply data science to power the business, but champion adata-first approach toward decision-making across the entire organization.

That’s the subject my new workbook, “The Art of Thinking Like A Data Scientist”, seeks to accomplish. It’s designed to be a pragmatic tool that can help your organization leverage data and analytics to power its business and operational models. The content is jammed with templates, worksheets, examples, and hands-on exercises — all composed to help reinforce and deploy the fundamental concepts of “Thinking Like A Data Scientist.”

The workbook is comprised of six chapters. Chapters 1, 2 and 3 set the business, data science and design thinking foundation. Chapter 4 covers the “Thinking Like a Data Scientist” methodology in detail, including an example. Chapters 5 (Hypothesis Development Canvas) and 6 (Prioritization Matrix) cover two critically-important components of the methodology. A more detailed delineation of the content in each chapter is listed below.

Chapter 1:  Big Data Business Model Maturity Index 

Chapter 1 sets the stage for the entire book and addresses the question “How effective is your organization at leveraging data and analytics to power your business models?” while providing a benchmark for an organization to measure itself. The chapter concludes with a series of exercises to help determine not only where your organization sits vis-à-vis this benchmark but provides a roadmap to become more effective at leveraging the business potential of data science.

Chapter 2:  Understanding the Basics of Data Science

To become more effective at leveraging data and analytics to power your organization’s business models, business stakeholders need a solid understanding of what data science can accomplish. This chapter explains the realm of what’s possible with data science, a layman’s definition of data science (identifying those variables and metrics that might be better predictors of performance), the data science development process, and how business stakeholders – “citizens of data science” – can contribute to an organization’s data science effectiveness.

Chapter 3:  Design Thinking Humanizes Data Science

Design Thinking and Data Science share many similarities in delivering meaningful, relevant and actionable outcomes within non-linear work environments. Design Thinking exploits the power of mightin fueling data science and business stakeholders’ (and subject matter experts) collaboration to identify variables and metrics that mightbe better predictors of performance. Design Thinking helps drive organizational alignment and adoption around the analytic results. Design Thinking truly does humanize data science.

Chapter 4: The “Thinking Like a Data Scientist” Methodology

Ah, the heart of the workbook, the actual methodology itself. This chapter details the 8-step “Thinking Like a Data Scientist” methodology, provides templates, and walks through a detailed example for the reader to readily apply this methodology to help their organizations identify where and how data science can be the source of differentiated customer, product and operational value.

Chapter 5:  Hypothesis Development Canvas

Chapter 5 focuses on the most critical output or deliverable from the “Thinking Like A Data Scientist” methodology – the Hypothesis Development Canvas. The Hypothesis Development Canvas codifies the collaboration between the data science team and the business stakeholders to ensure that the data science team has the necessary details to deliver meaningful business impact and relevance. This topic includes details about the targeted use case including use case business or operational objectives, the metrics and KPI’s against which progress and success will be measured, the key stakeholders who have a vested interest in the targeted use case, the entities around which analytics will need to be built, the supporting decisions and predictions, and finally, the costs associated with use case False Positives and False Negatives.

Chapter 6:  The Prioritization Matrix Process

The workbook concludes with the single most important tool that I’ve found in driving organizational alignment and adoption of the resulting analytics – the Prioritization Matrix. The Prioritization Matrix process leverages several Design Thinking techniques not only to align the key business stakeholders around which use case(s) the data science team should focus but seeks to tease out the passive-aggressive behaviors that doom so many well-intended data science projects. At the end of the day, you can build the world’s most effective predictions, but if no one puts them to use, nothing is gained.

I hope you enjoy the workbook. It’s one of my steps on the path in teaching business stakeholders to “Think Like a Data Scientist,” a culmination of lessons-learned working with clients for many years.

You can pick up your copy of “The Art of Thinking Like a Data Scientist” workbook here.

I look forward to hearing from you with your observations and learnings.

Thanks!

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


V8 JavaScript Engine 7.4, 7.5, and 7.6 Adds Numerous Performance Improvements

MMS Founder
MMS RSS

Article originally posted on InfoQ. Visit InfoQ

The recent 7.4, 7.5, and 7.6 versions of Google’s V8 JavaScript engine add several WebAssembly features and JavaScript performance improvements.

V8 version 7.4 also adds WebAssembly Threads/Atomics. Originally included as an experimental feature in V8 7.0, threads and atomics allow for the usage of multiple cores with WebAssembly, supporting computation-heavy processes for the web.

Chrome 75 adds implicit caching for WebAssembly, allowing already compiled WebAssembly modules to get pulled from the cache rather than recompiled upon each view. Non-Chromium users of V8 are encouraged to follow Chromium’s approach to implicit caching.

WebAssembly also gets support for the bulk memory proposal in V8 version 7.5, providing new instructions to update large regions of memory or tables.

V8 version 7.4 adds support for the ECMAScript private class fields syntax, making these fields inaccessible outside the class body.

Numeric separators, a proposed feature expected to arrive with ES2020, are now supported with V8 version 7.5, making it easier for humans to read very large number literals.

Version 7.4 of V8 also adds support for Intl.Locale, part of the ECMA-402 internationalization specification, providing more robust mechanisms for managing locales and efficiently extracting locale-specific preferences.

V8 7.6 improves Intl.DateTimeFormat by adding support for formatRange and formatRangeToParts methods, making it easier to format date ranges in a locale-specific manner, and also add the timeStyle and dateStyle options.

Promise.allSettled(promises) is a new JavaScript language feature added in V8 7.6. This feature signals when all input promises get settled (fulfilled or rejected).

BigInt support now works in a locale-aware manner with the toLocaleString method in V8 7.6, as well as via the Intl.NumberFormat API

V8’s recent releases have made several JavaScript performance improvements.

V8 version 7.6 introduces a substantial set of updates to JSON.parse, up to 2.7× faster parsing of data served. The main change is from a recursive parsing model to an iterative parser that manages its stack. Previously V8 could run out of stack for very deeply nested JSON data, but now V8 is only limited by available memory for JSON parsing. The new JSON parser improves memory efficiency by optimizing the approach to buffering properties.

In V8 7.4, improvements were made to provide faster calls with mismatching arguments. JavaScript allows calling functions with too few (under-application) or too many (over-application) parameters than formally declared. Under-application scenarios get formal parameters assigned as undefined, whereas over-application ignores its extra parameters. However, because JavaScript functions may access the actual parameters via the arguments object, rest parameters, etc., V8 provides access to the real arguments via arguments adaption. V8 now determines scenarios where this adaptation is not needed (e.g., callee is a strict mode function), reducing call overhead as much as 60%.

Also in V8 7.4, calling into native accessors directly via their get functions was much slower in Chrome than monomorphic or megamorphic property access by following a slower code path. V8 improves performance by calling into native accessors.

Large scripts in Chrome get streaming-parsed on worker threads while getting downloaded. In V8 7.4, a performance issue with custom UTF-8 decoding used by the source stream was fixed, resulting in an average 8% faster parse. Additionally, property names were getting deduplicated on parse. Fixing this issue improves streaming parser performance by an additional 10.5%, and also improves parse times for small non-streamed scripts and inline JavaScript.

With Chrome 75, V8 streams scripts directly from the network into its streaming parser, rather than waiting for the Chrome main thread. This change improves the performance of JavaScript parsing and reduces the number of concurrent streaming parse tasks, further reducing memory consumption.

V8 version 7.6 improves the performance of calls on frozen or sealed arrays on indexOf, includes, and various spread and apply calls. Fast, frozen, and sealed elements in V8 provides more detail around these improvements.

V8 now provides a JIT-less mode, supporting JavaScript execution without allocating executable memory at runtime. Typically V8 relies on the runtime allocation and modification of executable memory, making V8 fast. But some platforms such as iOS, smart TVs, and game consoles do not allow access to executable memory for non-privileged applications, perhaps to reduce the exploit surface area of an application. As of V* 7.4, the --jitless flag runs without runtime allocation of executable memory by switching V8 into an interpreter-only mode. WebAssembly does not currently get support with JIT-less mode.

V8 7.4 adds bytecode flushing, reducing V8’s memory overhead by flushing compiled bytecode from infrequently executed functions during garbage collection. This change reduces the V8’s heap memory by 5–15% without regressing performance or significantly increasing CPU time compiling JavaScript.

V8 7.4 also improves the handling of bytecode dead basic block elimination. As explained by the V8 team,

While we don’t expect this to have a large impact on user code, it is particularly useful for simplifying various desugarings, such as generators, for-of and try-catch, and in particular removes a class of bugs where basic blocks could “resurrect” complex statements part-way through their implementation.

Unicode string handling receives a significant improvement in V8 7.6 for calls like as String#localeCompare, String#normalize, and various internationalization APIs.

Google creates branch releases of its V8 JavaScript engine every six weeks to coincide with Google Chrome releases. Version 7.4 of V8 ships with Chrome 74, 7.5 with Chrome 75, and 7.6 with Chrome 76. V8 also powers the Node.js JavaScript runtime.

V8 is open source software with several applicable licenses to subsets of the codebase due to external dependencies. Contributions are welcome via the V8 Git project and should follow V8’s contribution guidelines and Google’s open source conduct guidelines.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


Microsoft Releases .NET Core 3.0 Preview 7

MMS Founder
MMS RSS

Article originally posted on InfoQ. Visit InfoQ

Last week Microsoft released .NET Core 3.0 Preview 7 for Windows, macOS, and Linux.

This release marks the beginning of the freezing period for .NET Core. From this point on, no more new features will be added and the development team will focus on polishing the existing code. According to the official announcement, a singular focus on quality is expected for the remaining preview releases.

The main improvement in this release is related to the size of the .NET Core SDK, which was reduced to 25%-30% of its original size (on-disk, depending on the operating system). The improvements come from a change on how the SDK is constructed: in previous versions, the SDK construction process involved using NuGet packages, which ended up in many unused artifacts. The new version of the SDK is constructed with what Microsoft calls “purpose-built packs”, exemplified by reference assemblies, frameworks, and templates.

The size improvements are smaller for Windows since WPF and Windows Forms 3.0 were added as part of .NET Core 3.0. Nevertheless, the .NET Core SDK Docker images were also affected: the x64 Debian and Alpine images were respectively reduced to 45% and 30% of their original size. More details on the SDK size reduction can be found here.

This preview of .NET Core 3.0 is supported by Microsoft and can be used in production: the Microsoft .NET Site has already been updated with the new release. Another update for Preview 8 is expected in a couple of weeks. Microsoft states that very few changes should be made for most APIs after Preview 7. However, WPF, Windows Forms, Blazor and Entity Framework are listed as “notable exceptions” in the same statement.

According to the .NET Core roadmap, the final 3.0 release is scheduled for September 2019. With Preview 7, Microsoft officially recommends the start of adoption planning for .NET Core 3.0, especially if docker containers are being used in production. The improvements for containers in the new release can be found here, and they are primarily related to docker resource limits and orchestration.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


Building Face Recognition using FaceNet

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

Face recognition is a combination of two major operations: face detection followed by Face classification. In this tutorial, we will look into a specific use case of object detection – face recognition.

The pipeline for the concerned project is as follows:

  1. Face detection: Look at an image and find all the possible faces in it
  2. Face extraction: Focus on each face image and understand it, for example, if it is turned sideways or badly lit
  3. Feature extraction: Extract unique features from the faces using convolutional neural networks (CNNs)
  4. Classifier training: Finally, compare the unique features of that face to all the people already known, to determine the person’s name

We will learn the main ideas behind each step, and how to raise our own facial recognition system in Python using the following deep-learning technologies:

  • dlib(http://dlib.net/): Provides a library that can be used for facial detection and alignment.
  • OpenFace(https://cmusatyalab.github.io/openface/): A deep-learning facial recognition model, developed by Brandon Amos et al (http://bamos.github.io/). It is able to run on real-time mobile devices as well.
  • FaceNet(https://arxiv.org/abs/1503.03832): A CNN architecture that is used for feature extraction. For a loss function, FaceNet uses triplet loss. Triplet loss relies on minimizing the distance from positive examples while maximizing the distance from negative examples.

Setting up Environment

Since setup can get very complicated and takes a long time, we will be building a Docker image that contains all the dependencies, including dlib, OpenFace, and FaceNet.

Getting the code

Fetch the code that we will use to build face recognition from the repository:

git clone https://github.com/PacktPublishing/Python-Deep-Learning-Projects cd Chapter10/

Building the Docker Image

Docker is a container platform that simplifies deployment. It solves the problem of installing software dependencies onto different server environments. If you are new to Docker, you can read more at https://www.docker.com/.

To install Docker on Linux machines, run the following command:

curl https://get.docker.com | sh

For other systems such as macOS and Windows, visit https://docs.docker.com/install/.You can skip this step if you already have Docker installed. 

Once Docker is installed, you should be able to use the docker command in the Terminal, as follows:

Now, we will create a docker file that will install all the dependencies, including OpenCV, dlib, and TensorFlow.

#Dockerfile for our env setup

FROM tensorflow/tensorflow:latest 

RUN apt-get update -y --fix-missing

RUN apt-get install -y ffmpeg

RUN apt-get install -y build-essential cmake pkg-config                     libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev                     libavcodec-dev libavformat-dev libswscale-dev libv4l-dev                     libxvidcore-dev libx264-dev                     libgtk-3-dev                     libatlas-base-dev gfortran                     libboost-all-dev                     python3 python3-dev python3-numpy 

RUN apt-get install -y wget vim python3-tk python3-pip 

WORKDIR /RUN wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip     && unzip opencv.zip     && wget -O opencv_contrib.zip

https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip     && unzip opencv_contrib.zip 

# install opencv3.2

RUN cd /opencv-3.2.0/   

&& mkdir build   

&& cd build   

&& cmake -D CMAKE_BUILD_TYPE=RELEASE          

           -D INSTALL_C_EXAMPLES=OFF  

           -D INSTALL_PYTHON_EXAMPLES=ON  

           -D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib-3.2.0/modules

           -D BUILD_EXAMPLES=OFF

           -D BUILD_opencv_python2=OFF  

           -D BUILD_NEW_PYTHON_SUPPORT=ON

           -D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)")

           -D PYTHON_EXECUTABLE=$(which python3)

           -D WITH_FFMPEG=1

           -D WITH_CUDA=0             ..

    && make -j8

    && make install

    && ldconfig

    && rm /opencv.zip

    && rm /opencv_contrib.zip  # Install dlib 19.4RUN wget -O dlib-19.4.tar.bz2 http://dlib.net/files/dlib-19.4.tar.bz2

    && tar -vxjf dlib-19.4.tar.bz2 RUN cd dlib-19.4

    && cd examples

    && mkdir build

    && cd build

    && cmake ..

    && cmake --build . --config Release

    && cd /dlib-19.4

    && pip3 install setuptools

    && python3 setup.py install

    && cd $WORKDIR

    && rm /dlib-19.4.tar.bz2   ADD $PWD/requirements.txt /requirements.txtRUN pip3 install -r /requirements.txt  CMD ["/bin/bash"]

Now execute the following command to build the image:

docker build -t hellorahulk/facerecognition -f Dockerfile

It will take approximately 20-30 minutes to install all the dependencies and build the Docker Image:

Downloading Pre-Trained Models

We will download a few more artifacts, which we will use and discuss in detail later in this tutorial. Download Dlib’s face landmark predictor, using the following commands:

curl -O http://dlib.net/

files/shape_predictor_68_face_landmarks.dat.bz2

bzip2 -d shape_predictor_68_face_landmarks.dat.bz2

cp shape_predictor_68_face_landmarks.dat facenet/

Download the pre-trained inception model:

curl -L -O https://www.dropbox.com/s/hb75vuur8olyrtw/Resnet-185253.pbcp Resnet-185253.pb pre-model/

Once we have all the components ready, the folder structure should look roughly as follows:

Folder Structure of the Code

Make sure that you keep the images of the person you want to train the model within the /data folder, and name the folder as /data/<class_name>/<class_name>_000<count>.jpg.

The /output folder will contain the trained SVM classifier and all pre-processed images inside a subfolder /intermediate, using the same folder nomenclature as in the /data folder.

For better performance in terms of accuracy, keeping more than five samples of images for each class is suggested. This helps the model to converge faster and generalize better.

Building the Pipeline

Facial recognition is a biometric solution that measures the unique characteristics of faces. To perform facial recognition, you’ll need a way to uniquely represent a face. The main idea behind any face recognition system is to break the face down into unique features, and then use those features to represent identity.

Building a robust pipeline for feature extraction is very important, as it will directly affect the performance and accuracy of our system.

To build the face recognition pipeline, we will devise the following flow (represented by orange blocks in the diagram):

  • Pre-processing: Finding all the faces, fixing the orientation of the faces
  • Feature extraction: Extracting unique features from the processed faces
  • Classifier training: Training the SVM classifier with 128-dimensional features

This image illustrates the end to end flow for face recognition pipeline. We will look into each of the steps, and build our world-class face recognition system.

Pre-processing of Images

The first step in our pipeline is face detection. We will then align the faces, extract features, and then finalize our pre-processing on Docker.

Face detection

Obviously, it’s very important to first locate the faces in the given photograph so that they can be fed into the later part of the pipeline. There are many ways to detect faces, such as detecting skin textures, oval/round shape detection, and other statistical methods. We’re going to use a method called HOG.

HOG is a feature descriptor that represents the distribution (histograms) of directions of gradients (oriented gradients), which are used as features. Gradients (x and y derivatives) of an image are useful because the magnitude of gradients is large around edges and corners (regions of abrupt intensity changes), which are excellent features in a given image.

To find faces in an image, we’ll convert the image into greyscale. Then we’ll look at every single pixel in our image, one at a time, and try to extract the orientation of the pixels using the HOG detector. We’ll be using dlib.get_frontal_face_detector() to create our face detector.

The following small snippet demonstrates the HOG-based face detector being used in the implementation:

import sysimport dlibfrom skimage import io  

# Create a HOG face detector using the built-in dlib classface_detector = dlib.get_frontal_face_detector() 

# Load the image into an arrayfile_name = 'sample_face_image.jpeg'image = io.imread(file_name) 

# Run the HOG face detector on the image data.

# The result will be the bounding boxes of the faces in our image.detected_faces = face_detector(image, 1) print("Found {} faces.".format(len(detected_faces))) 

# Loop through each face we found in the imagefor i, face_rect in enumerate(detected_faces): 

# Detected faces are returned as an object with the coordinates

# of the top, left, right and bottom edges  print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i+1, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom()))

The output is as follows:

Found 1 faces.

-Face #1 found at Left: 365 Top: 365 Right: 588 Bottom: 588

Aligning Faces

Once we know the region in which the face is located, we can perform various kinds of isolation techniques to extract the face from the overall image.

One challenge to deal with is that faces in images may be turned in different directions, making them look different to the machine.

To solve this issue, we will warp each image so that the eyes and lips are always in the sample place in the provided images. This will make it a lot easier for us to compare faces in the next steps. To do so, we are going to use an algorithm called face landmark estimation.

The basic idea is to come up with 68 specific points (called landmarks) that exist on every face—the top of the chin, the outside edge of each eye, the inner edge of each eyebrow, and so on. Then we will train a machine-learning algorithm to be able to find these 68 specific points on any face.

The 68 landmarks we will locate on every face are shown in the following diagram:

This image was created by Brandon Amos (http://bamos.github.io/), who works on OpenFace (https://github.com/cmusatyalab/openface).

Here is a small snippet demonstrating how to use face landmarks, which we downloaded in the Setup environment section:

import sys

import dlib

import cv2

import openface 

predictor_model = "shape_predictor_68_face_landmarks.dat" 

# Create a HOG face detector , Shape Predictor and Aligner

face_detector = dlib.get_frontal_face_detector()

face_pose_predictor = dlib.shape_predictor(predictor_model)

face_aligner = openface.AlignDlib(predictor_model) 

# Take the image file name from the command line

file_name = 'sample_face_image.jpeg' 

# Load the image

image = cv2.imread(file_name) 

# Run the HOG face detector on the image data

detected_faces = face_detector(image, 1) print("Found {} faces.".format(len(detected_faces)) 

# Loop through each face we found in the image

for i, face_rect in enumerate(detected_faces):  

# Detected faces are returned as an object with the coordinates   

# of the top, left, right and bottom edges 

print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom()))  

# Get the the face's pose 

pose_landmarks = face_pose_predictor(image, face_rect)  

# Use openface to calculate and perform the face alignment 

alignedFace = face_aligner.align(534, image, face_rect, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)  

# Save the aligned image to a file

cv2.imwrite("aligned_face_{}.jpg".format(i), alignedFace)

Using this, we can perform various basic image transformations such as rotation and scaling while preserving parallel lines. These are also known as affine transformations (https://en.wikipedia.org/wiki/Affine_transformation).

The output is as follows:

With segmentation, we solved finding the largest face in an image, and with alignment, we standardized the input image to be in the centre based on the location of eyes and bottom lip.

Here is a sample from our dataset, showing the raw image and processed image:

Feature Extraction

Now that we’ve segmented and aligned the data, we’ll generate vector embeddings of each identity. These embeddings can then be used as input to classification, regression, or clustering task. 

This process of training CNN to output face embeddings requires a lot of data and computer power. However, once the network has been trained, it can generate measurements for any face, even ones it has never seen before! So this step only needs to be done once.

For convenience, we have provided a model that has been pre-trained on Inception-Resnet-v1, which you can run over any face image to get the 128 dimension feature vectors. We downloaded this file in the Setup environment section, and it’s located in the /pre-model/Resnet-185253.pb directory.

If you want to try this step yourself, OpenFace provides a Lua script (https://github.com/cmusatyalab/openface/blob/master/batch-represent/batch-represent.lua) that will generate embeddings for all images in a folder and write them to a CSV file.

 The code to create the embeddings for the input images can be found further after the paragraph.

In the process, we are loading trained components from the Resnet model such as embedding_layer, images_placeholder, and phase_train_placeholder, along with the images and the labels:

def _create_embeddings(embedding_layer, images, labels, images_placeholder, phase_train_placeholder, sess):    """    Uses model to generate embeddings from :param images.    :param embedding_layer:     :param images:     :param labels:     :param images_placeholder:     :param phase_train_placeholder:     :param sess:     :return: (tuple): image embeddings and labels    """    emb_array = None    label_array = None    try:        i = 0        while True:            batch_images, batch_labels = sess.run([images, labels])            logger.info('Processing iteration {} batch of size: {}'.format(i, len(batch_labels)))            emb = sess.run(embedding_layer,                           feed_dict={images_placeholder: batch_images, phase_train_placeholder: False})             emb_array = np.concatenate([emb_array, emb]) if emb_array is not None else emb            label_array = np.concatenate([label_array, batch_labels]) if label_array is not None else batch_labels            i += 1     except tf.errors.OutOfRangeError:        pass     return emb_array, label_array

Here is a quick view of the embedding creating process. We fed the image and the label data along with few components from the pre-trained model:

The output of the process will be a vector of 128 dimensions, representing the facial image.

Execution on Docker

We will implement pre-processing on our Docker image. We’ll mount the project directory as a volume inside the Docker container (using a -v flag), and run the pre-processing script on the input data. The results will be written to a directory specified with command-line arguments.

The align_dlib.py file is sourced from CMU. It provides methods for detecting a face in an image, finding facial landmarks, and aligning these landmarks:

docker run -v $PWD:/facerecognition

-e PYTHONPATH=$PYTHONPATH:/facerecognition

-it hellorahulk/facerecognition python3 /facerecognition/facenet/preprocess.py

--input-dir /facerecognition/data

--output-dir /facerecognition/output/intermediate

--crop-dim 180

In the preceding command, we are setting the input data path using a –input-dir flag. This directory should contain the images that we want to process. We are also setting the output path using a –output-dir flag, which will store the segmented aligned images. We will be using these output images as input for training.

The –crop-dim flag is to define the output dimensions of the image. In this case, all images will be stored at 180 × 180. The outcome of this process will be a /intermediate folder being created inside the /output folder, containing all the pre-processed images.

Training the Classifier

First, we’ll load the segmented and aligned images from the input directory –input-dir flag. While training, we’ll apply to pre-process the image. This pre-processing will add random transformations to the image, creating more images to train on.

These images will be fed in a batch size of 128 into the pre-trained model. This model will return a 128-dimensional embedding for each image, returning a 128 x 128 matrix for each batch. After these embeddings are created, we’ll use them as feature inputs into a scikit-learn SVM classifier to train on each identity.

The following command will start the process, and train the classifier. The classifier will be dumped as a pickle file in the path defined in the –classifier-path argument:

docker run -v $PWD:/facerecognition

-e PYTHONPATH=$PYTHONPATH:/facerecognition

-it hellorahulk/facerecognition python3 /facerecognition/facenet/train_classifier.py

--input-dir /facerecognition/output/intermediate

--model-path /facerecognition/pre-model/Resnet-185253.pb

--classifier-path /facerecognition/output/classifier.pkl

--num-threads 16

--num-epochs 25

--min-num-images-per-class 10

--is-train

  • –num-threads: Modify according to the CPU/GPU config
  • –num-epochs: Change according to your dataset
  • –min-num-images-per-class: Change according to your dataset
  • –is-train: Set the True flag for training

This process will take a while, depending on the number of images we are training on. Once the process is completed, we will find a classifier.pkl file inside the /output folder.

Now you can use the classifier.pkl file to make predictions, and deploy it on production.

Evaluation

We will evaluate the performance of the trained model by executing the following command:

docker run -v $PWD:/facerecognition

-e PYTHONPATH=$PYTHONPATH:/facerecognition

-it hellorahulk/facerecognition python3 /facerecognition/facenet/train_classifier.py

--input-dir /facerecognition/output/intermediate

--model-path /facerecognition/pre-model/Resnet-185253.pb

--classifier-path /facerecognition/output/classifier.pkl

--num-threads 16

--num-epochs 2

--min-num-images-per-class 10

Once the execution is completed, we will see predictions with a confidence score, as shown in the following screenshot:

We can see that the model is able to predict with 99.5% accuracy. It is also relatively fast.

We have successfully completed a world-class facial recognition POC for our hypothetical high-performance data centre, utilizing deep learning technologies of OpenFace, Dlib, and FaceNet.  This project is a great example of the power of deep learning to produce solutions that make a meaningful impact on the business operations of our clients.

If this tutorial kept you engaged and you wish to explore more, ‘Python: Beginner’s Guide to Artificial Intelligence’ could be the one you might find useful. This book will introduce to various machine learning and deep learning algorithms from scratch. Along with that, you’ll also be exposed to implementing them practically. Apart from that, you will learn to build accurate predictive models with TensorFlow, combined with other open-source Python libraries.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


Discover how machine learning can solve finance industry challenges by Jannes Klaas

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

Aided by the availability of vast amounts of data computing resources, machine learning (ML) has made big strides. The financial industry, which at its heart is an information processing enterprise, holds an enormous amount of opportunity for the deployment of these new technologies.

Machine Learning for Finance is a practical guide to modern ML applied in the financial industry. This book is not only about investing or trading in the finance sector; it’s much more as a direct result of the love story between computers and finance. Investment firms have customers, often insurance firms or pension funds, and these firms are financial services companies themselves and, in turn, also have customers, everyday people that have a pension or are insured.

Let’s see what Jannes has to say about finance industry challenges and how machine learning can help solve them:

  1. Tell us a little bit about your book, Machine Learning for Finance? What were your goals and intentions when writing it? What makes this book necessary? What gap does it fill?

    Jannes Klaas: The book is by no means a complete guide to everything you might want to possibly know, but it is a practice-driven introduction that will leave the reader with some ready-to-use skills. After reading only a few chapters, readers will be able to use their new skills in their professional work. This approach differentiates the book from much of the very theory-driven literature that traditionally dominates quant finance. When I started writing this book, I felt that there was a disconnect between what many people who were doing ML knew and what many people who were doing finance knew. I saw many ML experts creating “financial models” that were worse than useless from a finance perspective. At the same time, many financial practitioners had no idea of what was happening to their field. They were worried that the days of excel spreadsheets were over and that their skills would be outdated. And they were right about that. But they did not have a straightforward way to get an overview of the brave new world they found themselves in and acquire some essential skills. There was and still is a gap of understanding, and both sides need to upskill to make the most out of the opportunity that lies in front of us. I am hoping to address the gap and contribute a little bit to the furthering of the financial profession.

  2. What are the different ML approaches in finance? Which approach do you prefer for mapping and resolving a problem and why?

    JK: Depending on the task, there are a lot of different methods. So, no single approach clearly dominates. The first question to ask here is whether you want to do supervised, unsupervised, or reinforcement learning. If you have labels, that is, you know what the true prediction should have been for your training data, then a supervised approach is usually the best. Supervised learning is where most of the commercial value lies and is usually the go-to approach for anything that concerns predictions. Unsupervised learning allows you to gather insight from your data if you don’t have labels. For instance, you might be interested in finding common factors that drive stock prices. You don’t know which factors are there or even how many, so you can use an unsupervised approach to get some insight. Reinforcement learning does not require labels, but it requires some reward signal. Say, you are interested in an optimal hedging strategy. Once again, you have no idea what the optimal strategy would have been, but you do know if you made or lost money. So you can use this knowledge as a reward signal and train the algorithm to maximize it.

    From an academic perspective, I find reinforcement learning very interesting. But as a practitioner, I tend to work with supervised approaches most of the time. In general, the simpler the model, the better.

  3. Why do financial models amplify biases in data? How can you combat this bias and make ML models fair and accountable?

    JK: Machine learning models are made to pick up on features that discriminate between classes in the dataset (e.g. fraudulent or genuine transactions). They can even combine features to form new features that help them with discrimination. The problem is that they can also discriminate based on protected attributes, such as age, gender, or race. This can even happen if the protected attributes themselves are hidden from the model. Say, you wanted to avoid discriminating against young people. So you will not use age as a feature, but you use the occupational status. However, the model will infer the age from the occupational status (e.g. student), and might end up discriminating on age anyhow. A second common issue is that many ML systems do not work equally well for everyone. Many computer vision systems, for instance, struggle to recognize the faces of people of color. This is very problematic if you use computer vision for verifying IDs, for instance. Combatting this requires you to first be aware of and open about the problem. The next step is to have a team that is diverse and can potentially spot the subtle patterns that lead to bias. Your data also needs to be representative of the diverse group of people you might be serving. Then there are a few technical approaches. One approach is to add discrimination to the loss function of the model. So the model needs to not only minimize its prediction error but also its bias on the protected attributes. These technical solutions can definitely be part of the response, but if you do not acknowledge and constantly monitor the problem, these solutions will not save you.

About the Book

Machine Learning for Finance explores new advances in machine learning and shows how they can be applied across the financial sector, including in insurance, transactions, and lending. It explains the concepts and algorithms behind the main machine learning techniques and provides example Python code for implementing the models yourself.

About the Author

Jannes Klaas is a quantitative researcher with a background in economics and finance. He taught machine learning for finance as lead developer for machine learning at the Turing Society, Rotterdam. He has led machine learning bootcamps and worked with financial companies on data-driven applications and trading strategies.

Jannes is currently a graduate student at Oxford University with active research interests including systemic risk and large-scale automated knowledge discovery.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


How Do I Prove The Value Of Self-Serve Augmented Data Discovery?

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

How does one measure the effectiveness of a new Augmented Data Discovery solution? Once the business has chosen data democratization and implemented a self-serve analytics solution, it must measure ROI & TCO and establish metrics that will compare business results achieved before and after the implementation.

Without measurable results, it will be difficult to garner and sustain support for business transformation and for creating an environment where Citizen Data Scientists can thrive. Senior managers, corporate stakeholders and naysayers may resort to gut feelings and business users may perceive that there is little to be gained from embracing self-serve advanced analytics tools if the management team does not value these new tools.

When an organization establishes metrics, it must consider its goals and objectives and analyze the results of actions taken and decisions made with the support of data analytics versus those made ‘the old way’. For example, if one were to set new pricing, decide on a new business location or create a new promotion based on Assisted Predictive Modeling, the business would measure the success and results versus the results achieved when decisions were made without data analytics.

Many organizations depend on the vision of one individual or a small team of executives who have market or industry experience. This approach can be difficult to defeat without clearly defined metrics and results to support the case for data-driven decisions. At its inception, these tools may be used to ‘test’ a theory or compare a direction or decision to another option. But, that is OK. By offering recommendations and options, the team will begin to consider other possibilities and, as the data foundation is created, the argument for ‘going with your gut’ will fade.

As the enterprise shifts its focus, and team members adopt and depend on Augmented Analytics for presentations, data sharing and reporting, the culture will shift and the business will gain a new appreciation for clear, precise data and the results it can produce in the planning process, in day-to-day decisions and in solving problems and identifying market potential.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.


Regression Analysis in One Picture

MMS Founder
MMS RSS

Article originally posted on Data Science Central. Visit Data Science Central

The basic idea behind regression analysis is to take a set of data and use that data to make predictions. A useful first step is to make a scatter plot to see the rough shape of your data. Then, choose a regression method to find the line of best fit. Which method you choose depends upon the shape the scatter plot reveals (is it a line, a curve, or a parabola?) and what special situations, if any, your data has. The following image shows an overview of regression; See below for links to more detail.

Further Reading

Linear Regression

Logistic Regression

Ridge Regression

Lasso Regression

Stepwise Regression

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.