前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >机器学习开发者应该收藏的 DIY 计算机视觉和深度学习项目

机器学习开发者应该收藏的 DIY 计算机视觉和深度学习项目

作者头像
AI研习社
发布2018-07-26 15:24:18
5960
发布2018-07-26 15:24:18
举报
文章被收录于专栏:AI研习社AI研习社

本文为雷锋字幕组编译的技术博客,原标题 DIY Deep Learning Projects,作者为 Favio Vázquez。 翻译 | 赵朋飞、林骁 整理 | 孔令双

受到 Akshay Bahadur 所做伟大工作的鼓舞,在这篇文章中你将看到一些应用计算机视觉和深度学习的项目,包括具体实现和细节,你可以在自己的电脑上复现这些项目。

LinkedIn 数据科学社区

Akshay Bahadur 是 LinkedIn 数据科学社区给出的最好的榜样。在其他诸如 Quora、StackOverflow、Youtube 等平台,有很多优秀的人,以及很多论坛和平台在科学、哲学、数学、语言学,以及数据科学等领域互相帮助。

Akshay Bahadur.

但我认为在过去的 ~3 年间,LinkedIn 社区在共享数据科学内容方面做的非常优秀,从分享经验,到关于如何在现实世界进行机器学习的文章。我经常建议想从事这一领域的人加入这个社区,而且 LinkedIn 是最好的,你可以在那里随时找到我 :)。

从深度学习和计算机视觉开始

https://github.com/facebookresearch/Detectron

在这十年里,在深度学习领域中对图像进行分类、检测和执行相应动作的研究是非常重要的,其结果令人惊讶,有些问题的解决在性能已经超越了人类水平。

在这篇文章中,我将展示 Akshay Bahadur在计算机视觉和深度学习领域所做的工作。如果你对这些概念还不熟悉,可以通过阅读下面这些内容学到更多:

  • 对深度学习的「怪异」介绍 这里有关于深度学习的精彩介绍、课程以及博客文章。但这是一种很独特的介绍。 https://towardsdatascience.com/a-weird-introduction-to-deep-learning-7828803693b0
  • 两个月探索深度学习和计算机视觉 我决定深入了解计算机视觉和机器学习。作为一个网页开发者,我发现了这个。 https://towardsdatascience.com/two-months-exploring-deep-learning-and-computer-vision-3dcc84b2457f
  • 从神经科学到计算机视觉 人类和计算机视觉的50年。 https://towardsdatascience.com/from-neuroscience-to-computer-vision-e86a4dea3574
  • 吴恩达计算机视觉 —— 11 个经验教训 我最近刚完成吴恩达在 Coursera 上的计算机视觉课程。吴恩达在解释这些问题方面做了杰出的工作。 https://towardsdatascience.com/computer-vision-by-andrew-ng-11-lessons-learned-7d05c18a6999

1. 使用 OpenCV 手动执行

akshaybahadur21/HandMovementTracking

https://github.com/akshaybahadur21/HandMovementTracking

Akshay:

为了执行视频追踪,算法需要分析视频帧序列并输出每帧之间的目标位移。有很多种算法,每种各有强项和弱点。选择使用哪种算法,重要的是要考虑应用目的。视频追踪系统有两个主要的组成部分:目标表示和定位,以及滤波和数据关联。 视频追踪是通过摄像头定位一个(或多个)移动目标的过程。拥有多种用途,比如,人机交互、安全监视、视频通讯与压缩、增强现实、交通控制、医学影像,以及视频编辑等。

下面是你在复现它时需要用到的代码:

代码语言:javascript
复制
import numpy as np
import cv2
import argparse
from collections import deque


cap=cv2.VideoCapture(0)

pts = deque(maxlen=64)

Lower_green = np.array([110,50,50])
Upper_green = np.array([130,255,255])
while True:
 ret, img=cap.read()
 hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
 kernel=np.ones((5,5),np.uint8)
 mask=cv2.inRange(hsv,Lower_green,Upper_green)
 mask = cv2.erode(mask, kernel, iterations=2)
 mask=cv2.morphologyEx(mask,cv2.MORPH_OPEN,kernel)
 #mask=cv2.morphologyEx(mask,cv2.MORPH_CLOSE,kernel)
 mask = cv2.dilate(mask, kernel, iterations=1)
 res=cv2.bitwise_and(img,img,mask=mask)
 cnts,heir=cv2.findContours(mask.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[-2:]
 center = None

 if len(cnts) > 0:
   c = max(cnts, key=cv2.contourArea)
   ((x, y), radius) = cv2.minEnclosingCircle(c)
   M = cv2.moments(c)
   center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

   if radius > 5:
     cv2.circle(img, (int(x), int(y)), int(radius),(0, 255, 255), 2)
     cv2.circle(img, center, 5, (0, 0, 255), -1)
   
 pts.appendleft(center)
 for i in xrange (1,len(pts)):
   if pts[i-1]is None or pts[i] is None:
     continue
   thick = int(np.sqrt(len(pts) / float(i + 1)) * 2.5)
   cv2.line(img, pts[i-1],pts[i],(0,0,225),thick)
   
 
 cv2.imshow("Frame", img)
 cv2.imshow("mask",mask)
 cv2.imshow("res",res)
 
 
 k=cv2.waitKey(30) & 0xFF
 if k==32:
   break
# cleanup the camera and close any open windows
cap.release()
cv2.destroyAllWindows()

是的,54 行代码,相当简单?如果你的电脑检查结果如下面所示的话,你需要先安装 OpenCV:

在 MacOS 上安装 OpenCV 这篇文章中,我么将逐步介绍在 MacOS 和 OSX 上安装 OpenCV 3.3.0 (C++ and Python)。 https://www.learnopencv.com/install-opencv3-on-macos/

如果你使用 Ubuntu:

OpenCV:在 Ubuntu 上安装 OpenCV-Python 有了所有必须的依赖项,让我们安装 OpenCV。需要使用 CMake 配置安装选项项 https://docs.opencv.org/3.4.1/d2/de6/tutorial_py_setup_in_ubuntu.html

如果使用 Windows:

Windows 安装 OpenCV-Python- OpenCV 3.0.0-dev documentation 在这篇教程中我们将学习在 Windows 系统中如何设置O penCV-Python。下面的步骤在 Windows 7-64 中测试通过 https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html

2.基于 OpenCV 的疲劳检测

akshaybahadur21/Drowsiness_Detection

在 GitHub.github.com 创建账号有助于疲劳检测项目开发

https://github.com/akshaybahadur21/Drowsiness_Detection

驾驶员长时间驾驶有可能会导致事故发生。这段代码检测你的眼睛,瞌睡时会发出告警。

依赖项:

  • cv2
  • immutils
  • dlib
  • scipy

算法

每个眼睛使用 6个 (x, y)坐标表示,从眼睛的左角开始(正如你看见人时一样), 然后沿着眼睛周围顺时针计算。

条件

检查连续 20 帧图像,如果眼睛长宽比小于 0.25,就发出告警。

关系

3. 使用 SoftMax 回归进行数字识别

akshaybahadur21/Digit-Recognizer

在 Github.com 上的机器学习分类器-数字识别

https://github.com/akshaybahadur21/Digit-Recognizer

在程序中利用 SoftMax 回归代码能够帮助你区分不同的数字。你可以为 Python 安装 Conda,它可以为你提供所有与 Python 有关相关库的编译环境。

描述

Softmax 回归是逻辑回归的推广,我们可以用它来解决多分类问题,假设这些分类是互斥的(同义词:多项逻辑推理,最大熵分类器,或多类逻辑回归)。相反,我们在二分类问题中通常使用逻辑回归模型。

Python 实现

数据集使用 MNIST 数据集,同时图像大小为 28*28,利用逻辑回归、浅层神经网络和深层神经网络的方法将 0—9 进行分类。

三个模型当中最好的部分之一是使用 Numpy 函数库,包括优化,前向传播和后向传播。

逻辑回归:

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt

def softmax(z):
   z -= np.max(z)
   sm = (np.exp(z).T / np.sum(np.exp(z), axis=1))
   return sm


def initialize(dim1, dim2):
   """
   :param dim: size of vector w initilazied with zeros
   :return:
   """
   w = np.zeros(shape=(dim1, dim2))
   b = np.zeros(shape=(10, 1))
   return w, b


def propagate(w, b, X, Y):
   """
   :param w: weights for w
   :param b: bias
   :param X: size of data(no of features, no of examples)
   :param Y: true label
   :return:
   """
   m = X.shape[1]  # getting no of rows

   # Forward Prop
   A = softmax((np.dot(w.T, X) + b).T)
   cost = (-1 / m) * np.sum(Y * np.log(A))

   # backwar prop
   dw = (1 / m) * np.dot(X, (A - Y).T)
   db = (1 / m) * np.sum(A - Y)

   cost = np.squeeze(cost)
   grads = {"dw": dw,
            "db": db}
   return grads, cost


def optimize(w, b, X, Y, num_iters, alpha, print_cost=False):
   """
   :param w: weights for w
   :param b: bias
   :param X: size of data(no of features, no of examples)
   :param Y: true label
   :param num_iters: number of iterations for gradient
   :param alpha:
   :return:
   """

   costs = []
   for i in range(num_iters):
       grads, cost = propagate(w, b, X, Y)
       dw = grads["dw"]
       db = grads["db"]
       w = w - alpha * dw
       b = b - alpha * db

       # Record the costs
       if i % 50 == 0:
           costs.append(cost)

       # Print the cost every 100 training examples
       if print_cost and i % 50 == 0:
           print("Cost after iteration %i: %f" % (i, cost))

   params = {"w": w,
             "b": b}

   grads = {"dw": dw,
            "db": db}

   return params, grads, costs


def predict(w, b, X):
   """
   :param w:
   :param b:
   :param X:
   :return:
   """
   # m = X.shape[1]
   # y_pred = np.zeros(shape=(1, m))
   # w = w.reshape(X.shape[0], 1)

   y_pred = np.argmax(softmax((np.dot(w.T, X) + b).T), axis=0)
   return y_pred


def model(X_train, Y_train, Y,X_test,Y_test, num_iters, alpha, print_cost):
   """
   :param X_train:
   :param Y_train:
   :param X_test:
   :param Y_test:
   :param num_iterations:
   :param learning_rate:
   :param print_cost:
   :return:
   """

   w, b = initialize(X_train.shape[0], Y_train.shape[0])
   parameters, grads, costs = optimize(w, b, X_train, Y_train, num_iters, alpha, print_cost)

   w = parameters["w"]
   b = parameters["b"]


   y_prediction_train = predict(w, b, X_train)
   y_prediction_test = predict(w, b, X_test)
   print("Train accuracy: {} %", sum(y_prediction_train == Y) / (float(len(Y))) * 100)
   print("Test accuracy: {} %", sum(y_prediction_test == Y_test) / (float(len(Y_test))) * 100)

   d = {"costs": costs,
        "Y_prediction_test": y_prediction_test,
        "Y_prediction_train": y_prediction_train,
        "w": w,
        "b": b,
        "learning_rate": alpha,
        "num_iterations": num_iters}

   # Plot learning curve (with costs)
   #costs = np.squeeze(d['costs'])
   #plt.plot(costs)
   #plt.ylabel('cost')
   #plt.xlabel('iterations (per hundreds)')
   #plt.title("Learning rate =" + str(d["learning_rate"]))
   #plt.plot()
   #plt.show()
   #plt.close()

   #pri(X_test.T, y_prediction_test)
   return d


def pri(X_test, y_prediction_test):
   example = X_test[2, :]
   print("Prediction for the example is ", y_prediction_test[2])
   plt.imshow(np.reshape(example, [28, 28]))
   plt.plot()
   plt.show()

浅层神经网络

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt

def softmax(z):
   z -= np.max(z)
   sm = (np.exp(z).T / np.sum(np.exp(z),axis=1))
   return sm


def layers(X, Y):
   """
   :param X:
   :param Y:
   :return:
   """
   n_x = X.shape[0]
   n_y = Y.shape[0]
   return n_x, n_y


def initialize_nn(n_x, n_h, n_y):
   """
   :param n_x:
   :param n_h:
   :param n_y:
   :return:
   """
   np.random.seed(2)
   W1 = np.random.randn(n_h, n_x) * 0.01
   b1 = np.random.rand(n_h, 1)
   W2 = np.random.rand(n_y, n_h)
   b2 = np.random.rand(n_y, 1)
   parameters = {"W1": W1,
                 "b1": b1,
                 "W2": W2,
                 "b2": b2}

   return parameters


def forward_prop(X, parameters):
   W1 = parameters['W1']
   b1 = parameters['b1']
   W2 = parameters['W2']
   b2 = parameters['b2']

   Z1 = np.dot(W1, X) + b1
   A1 = np.tanh(Z1)
   Z2 = np.dot(W2, A1) + b2
   A2 = softmax(Z2.T)

   cache = {"Z1": Z1,
            "A1": A1,
            "Z2": Z2,
            "A2": A2}

   return A2, cache


def compute_cost(A2, Y, parameters):
   m = Y.shape[1]
   W1 = parameters['W1']
   W2 = parameters['W2']
   logprobs = np.multiply(np.log(A2), Y)
   cost = - np.sum(logprobs) / m
   cost = np.squeeze(cost)

   return cost


def back_prop(parameters, cache, X, Y):
   m = Y.shape[1]
   W1 = parameters['W1']
   W2 = parameters['W2']
   A1 = cache['A1']
   A2 = cache['A2']


   dZ2 = A2 - Y
   dW2 = (1 / m) * np.dot(dZ2, A1.T)
   db2 = (1 / m) * np.sum(dZ2, axis=1, keepdims=True)

   dZ1 = np.multiply(np.dot(W2.T, dZ2), 1 - np.square(A1))
   dW1 = (1 / m) * np.dot(dZ1, X.T)
   db1 = (1 / m) * np.sum(dZ1, axis=1, keepdims=True)

   grads = {"dW1": dW1,
            "db1": db1,
            "dW2": dW2,
            "db2": db2}

   return grads


def update_params(parameters, grads, alpha):
   W1 = parameters['W1']
   b1 = parameters['b1']
   W2 = parameters['W2']
   b2 = parameters['b2']

   dW1 = grads['dW1']
   db1 = grads['db1']
   dW2 = grads['dW2']
   db2 = grads['db2']

   W1 = W1 - alpha * dW1
   b1 = b1 - alpha * db1
   W2 = W2 - alpha * dW2
   b2 = b2 - alpha * db2

   parameters = {"W1": W1,
                 "b1": b1,
                 "W2": W2,
                 "b2": b2}
   return parameters


def model_nn(X, Y,Y_real,test_x,test_y, n_h, num_iters, alpha, print_cost):
   np.random.seed(3)
   n_x,n_y = layers(X, Y)
   parameters = initialize_nn(n_x, n_h, n_y)
   W1 = parameters['W1']
   b1 = parameters['b1']
   W2 = parameters['W2']
   b2 = parameters['b2']

   costs = []
   for i in range(0, num_iters):

       A2, cache = forward_prop(X, parameters)

       cost = compute_cost(A2, Y, parameters)
       grads = back_prop(parameters, cache, X, Y)
       if (i > 1500):
           alpha1 = 0.95*alpha
           parameters = update_params(parameters, grads, alpha1)
       else:
           parameters = update_params(parameters, grads, alpha)

       if i % 100 == 0:
           costs.append(cost)
       if print_cost and i % 100 == 0:
           print("Cost after iteration for %i: %f" % (i, cost))



   predictions = predict_nn(parameters, X)
   print("Train accuracy: {} %", sum(predictions == Y_real) / (float(len(Y_real))) * 100)
   predictions=predict_nn(parameters,test_x)
   print("Train accuracy: {} %", sum(predictions == test_y) / (float(len(test_y))) * 100)



   #plt.plot(costs)
   #plt.ylabel('cost')
   #plt.xlabel('iterations (per hundreds)')
   #plt.title("Learning rate =" + str(alpha))
   #plt.show()

   return parameters


def predict_nn(parameters, X):
   A2, cache = forward_prop(X, parameters)
   predictions = np.argmax(A2, axis=0)
   return predictions

以及最后的深层神经网络:

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt


def softmax(z):
   cache = z
   z -= np.max(z)
   sm = (np.exp(z).T / np.sum(np.exp(z), axis=1))
   return sm, cache


def relu(z):
   """
   :param z:
   :return:
   """
   s = np.maximum(0, z)
   cache = z
   return s, cache


def softmax_backward(dA, cache):
   """
   :param dA:
   :param activation_cache:
   :return:
   """
   z = cache
   z -= np.max(z)
   s = (np.exp(z).T / np.sum(np.exp(z), axis=1))
   dZ = dA * s * (1 - s)
   return dZ


def relu_backward(dA, cache):
   """
   :param dA:
   :param activation_cache:
   :return:
   """
   Z = cache
   dZ = np.array(dA, copy=True)  # just converting dz to a correct object.
   dZ[Z <= 0] = 0
   return dZ


def initialize_parameters_deep(dims):
   """
   :param dims:
   :return:
   """

   np.random.seed(3)
   params = {}
   L = len(dims)

   for l in range(1, L):
       params['W' + str(l)] = np.random.randn(dims[l], dims[l - 1]) * 0.01
       params['b' + str(l)] = np.zeros((dims[l], 1))
   return params


def linear_forward(A, W, b):
   """
   :param A:
   :param W:
   :param b:
   :return:
   """

   Z = np.dot(W, A) + b
   cache = (A, W, b)

   return Z, cache


def linear_activation_forward(A_prev, W, b, activation):
   """
   :param A_prev:
   :param W:
   :param b:
   :param activation:
   :return:
   """
   if activation == "softmax":
       Z, linear_cache = linear_forward(A_prev, W, b)
       A, activation_cache = softmax(Z.T)

   elif activation == "relu":
       Z, linear_cache = linear_forward(A_prev, W, b)
       A, activation_cache = relu(Z)

   cache = (linear_cache, activation_cache)

   return A, cache


def L_model_forward(X, params):
   """
   :param X:
   :param params:
   :return:
   """

   caches = []
   A = X
   L = len(params) // 2  # number of layers in the neural network

   # Implement [LINEAR -> RELU]*(L-1). Add "cache" to the "caches" list.
   for l in range(1, L):
       A_prev = A
       A, cache = linear_activation_forward(A_prev,
                                            params["W" + str(l)],
                                            params["b" + str(l)],
                                            activation='relu')
       caches.append(cache)

   A_last, cache = linear_activation_forward(A,
                                             params["W" + str(L)],
                                             params["b" + str(L)],
                                             activation='softmax')
   caches.append(cache)
   return A_last, caches


def compute_cost(A_last, Y):
   """
   :param A_last:
   :param Y:
   :return:
   """

   m = Y.shape[1]
   cost = (-1 / m) * np.sum(Y * np.log(A_last))
   cost = np.squeeze(cost)  # To make sure your cost's shape is what we expect (e.g. this turns [[17]] into 17).
   return cost


def linear_backward(dZ, cache):
   """
   :param dZ:
   :param cache:
   :return:
   """

   A_prev, W, b = cache
   m = A_prev.shape[1]

   dW = (1. / m) * np.dot(dZ, cache[0].T)
   db = (1. / m) * np.sum(dZ, axis=1, keepdims=True)
   dA_prev = np.dot(cache[1].T, dZ)

   return dA_prev, dW, db


def linear_activation_backward(dA, cache, activation):
   """
   :param dA:
   :param cache:
   :param activation:
   :return:
   """

   linear_cache, activation_cache = cache

   if activation == "relu":
       dZ = relu_backward(dA, activation_cache)
       dA_prev, dW, db = linear_backward(dZ, linear_cache)

   elif activation == "softmax":
       dZ = softmax_backward(dA, activation_cache)
       dA_prev, dW, db = linear_backward(dZ, linear_cache)

   return dA_prev, dW, db


def L_model_backward(A_last, Y, caches):
   """
   :param A_last:
   :param Y:
   :param caches:
   :return:
   """

   grads = {}
   L = len(caches)  # the number of layers
   m = A_last.shape[1]
   Y = Y.reshape(A_last.shape)  # after this line, Y is the same shape as A_last

   dA_last = - (np.divide(Y, A_last) - np.divide(1 - Y, 1 - A_last))
   current_cache = caches[-1]
   grads["dA" + str(L)], grads["dW" + str(L)], grads["db" + str(L)] = linear_activation_backward(dA_last,
                                                                                                 current_cache,
                                                                                                 activation="softmax")

   for l in reversed(range(L - 1)):
       current_cache = caches[l]

       dA_prev_temp, dW_temp, db_temp = linear_activation_backward(grads["dA" + str(l + 2)], current_cache,
                                                                   activation="relu")
       grads["dA" + str(l + 1)] = dA_prev_temp
       grads["dW" + str(l + 1)] = dW_temp
       grads["db" + str(l + 1)] = db_temp

   return grads


def update_params(params, grads, alpha):
   """
   :param params:
   :param grads:
   :param alpha:
   :return:
   """

   L = len(params) // 2  # number of layers in the neural network

   for l in range(L):
       params["W" + str(l + 1)] = params["W" + str(l + 1)] - alpha * grads["dW" + str(l + 1)]
       params["b" + str(l + 1)] = params["b" + str(l + 1)] - alpha * grads["db" + str(l + 1)]

   return params


def model_DL( X, Y, Y_real, test_x, test_y, layers_dims, alpha, num_iterations, print_cost):  # lr was 0.009
   """
   Implements a L-layer neural network: [LINEAR->RELU]*(L-1)->LINEAR->SIGMOID.
   Arguments:
   X -- data, numpy array of shape (number of examples, num_px * num_px * 3)
   Y -- true "label" vector (containing 0 if cat, 1 if non-cat), of shape (1, number of examples)
   layers_dims -- list containing the input size and each layer size, of length (number of layers + 1).
   alpha -- learning rate of the gradient descent update rule
   num_iterations -- number of iterations of the optimization loop
   print_cost -- if True, it prints the cost every 100 steps
   Returns:
   params -- params learnt by the model. They can then be used to predict.
   """

   np.random.seed(1)
   costs = []  # keep track of cost

   params = initialize_parameters_deep(layers_dims)

   for i in range(0, num_iterations):

       A_last, caches = L_model_forward(X, params)
       cost = compute_cost(A_last, Y)
       grads = L_model_backward(A_last, Y, caches)

       if (i > 800 and i<1700):
           alpha1 = 0.80 * alpha
           params = update_params(params, grads, alpha1)
       elif(i>=1700):
           alpha1 = 0.50 * alpha
           params = update_params(params, grads, alpha1)
       else:
           params = update_params(params, grads, alpha)

       if print_cost and i % 100 == 0:
           print("Cost after iteration %i: %f" % (i, cost))
       if print_cost and i % 100 == 0:
           costs.append(cost)
   predictions = predict(params, X)
   print("Train accuracy: {} %", sum(predictions == Y_real) / (float(len(Y_real))) * 100)
   predictions = predict(params, test_x)
   print("Test accuracy: {} %", sum(predictions == test_y) / (float(len(test_y))) * 100)

   #plt.plot(np.squeeze(costs))
   #plt.ylabel('cost')
   #plt.xlabel('iterations (per tens)')
   #plt.title("Learning rate =" + str(alpha))
   #plt.show()

   return params


def predict(parameters, X):
   A_last, cache = L_model_forward(X, parameters)
   predictions = np.argmax(A_last, axis=0)
   return predictions

通过摄像头写入

运行程序 python Dig-Rec.py

代码语言:javascript
复制
python Dig-Rec.py

通过摄像头展现传入的代码

运行程序 python Digit-Recognizer.py

代码语言:javascript
复制
python Digit-Recognizer.py

Devanagiri Recognizer

akshaybahadur21/Devanagiri-Recognizer

Devanagiri-Recognizer - 使用 convnetgithub.com 的印地语字母表分类器

这段代码可以帮助你使用 Convnets 来分类不同的印地文字母(Devanagiri)。

https://github.com/akshaybahadur21/Devanagiri-Recognizer

你可以为 Python 安装 Conda,它可以为你提供所有与 Python 有关相关库的编译环境。

使用的技术

我使用了卷积神经网络,Tensorflow 框架以及 Keras API 来提供高级的抽象。

结构

卷积层 → 池化层 → 卷积层 → 池化层 → 全连接层 →Softmax 回归层 → 分类

其他需要注意的事项

  1. 你还可以增加卷积层。
  2. 增加正则化防止过拟合。
  3. 增加图片的数量来提高准确率。

Python 实现

DHCD (Devnagari Character Dataset)数据集的所有图片尺寸都是 32 * 32 并且都用于卷积神经网络。

运行程序 python Dev-Rec.py

代码语言:javascript
复制
python Dev-Rec.py

4. 使用 FaceNet 做面部识别

akshaybahadur21/ Facial-Recognition-using-FaceNet

https://github.com/akshaybahadur21/Facial-Recognition-using-Facenet

这段程序利用 facenet 网络帮助你做面部识别(https://arxiv.org/pdf/1503.03832.pdf). Facenets 的概念最初是在一篇研究论文中提出的。主要概念讨论了三重损失函数来比较不同人的图像。这个概念使用的是 Inception 网络,来自于 DeepingLearning.ai社区的 frutils.py 文件。在我的网络当中我增加了一些函数来提高稳定性和更好的检测。

必备的代码库

你可以为 Python 安装 Conda,它可以为你提供所有与 Python 有关相关库的编译环境,以下是你可能需要的库:

  • numpy
  • matplotlib
  • cv2
  • keras
  • dlib
  • h5py
  • scipy

描述

面部识别系统是能够从数字图像或者视频中识别或验证人面部的技术。构建面部识别系统这里有很多种方法,但是通常,他们是通过比较图片中选择的面部特征和数据集中的特征来进行判断。

添加的功能

  1. 只有当你的眼睛睁开是才能侦测到面部。
  2. 使用 dlib 库的面部对齐功能在实时流媒体上进行有效的预测。

Python 实现

  1. 使用 Inception Network 来搭建网络
  2. 源论文来自于Google-Facenet

程序

  1. 如果你想训练网络,请运行 Train-inception.py, 若你不想训练网络,因为我早已经训练好了一个网络,那么你可以下载该文件到本地运行 face-rec_Google.h5 。
  2. 现在你已经有了一个数据集,里面包含了很多图片。 点击文件 /images来折叠这些照片。您可以将图片粘贴到此处,也可以使用网络摄像头进行点击。你可以运行该文件 create-face.py 来做到这一点,图片都存储在文件夹 /incept 中。你必须手动粘贴到文件夹中 /images folder。
  3. 运行程序 rec-feat.py 来实现所有的功能。

5. Emojinator

akshaybahadur21/ Emojinator

Emojinator - Github 上一个简单的表情分类器。

https://github.com/akshaybahadur21/Emojinator

这些代码能够帮助你区分不同的表情。到目前为止,我们只支持手的表情。

必备的代码库

你可以为 Python 安装 Conda,它可以为你提供所有与 Python 有关相关库的编译环境,以下是你可能需要的库:

  • numpy
  • matplotlib
  • cv2
  • keras
  • dlib
  • h5py
  • scipy

描述

表情符号是电子信息和网页中使用的表意符号和微笑符号。表情符号存在于不同的类型中,包括面部表情、常见物体、地点和天气类型以及动物。它们很像表情符号,但表情符号是真实的图片,而不是印刷图。

功能

  1. 利用过滤器来检测手。
  2. 利用 CNN 来训练模型。

Python 实现

使用卷积神经网络

过程

  1. 首先,你需要一个手势图片的数据库,你可以运行该文件来获得 CreateGest.py。输入手势名称,你可以看到两个框架。按「C」进行拍摄。看看轮廓框架并调整你的手,以确保你捕捉到你的手的特征。一个手势可以拍 1200 张照片。试着在框架内移动你的手,以确保你的模型在训练过程当中不会过拟合。
  2. 重复以上操作,保证你可以获得所有你想要的特征。
  3. 运行程序 CreateCSV.py 来将图片转换成 CSV 文件。
  4. 如果你想训练模型,则运行程序 『TrainEmojinator.py』
  5. 最后,运行程序 Emojinator.py ,通过摄像头来测试你的模型

作者

Akshay Bahadur 和 Raghav Patnecha.

结语

我只能说我对这些项目感到难以置信,所有人都可以在计算机上运行它们,或者在 Deep Cognition 的平台上运行它们,如果你不想安装任何东西,它可以在线运行。

我想感谢 Akshay 和他的朋友们为开放源代码贡献力量以及所有其他将来的贡献。尝试一下,运行它们,并获得灵感。这只是 DL 和 CV 可以做的令人惊叹的事情的一个小例子,取决于你如何将它变成可以帮助世界变得更好的地方。

永不放弃,我们需要每个人都对许多不同的事情感兴趣。我认为我们可以改善世界,改善我们的生活,我们的工作方式,思考和解决问题,如果我们引导现在的所有资源,使这些知识领域共同努力,实现更大的利益,我们可以在世界和我们的生活中产生巨大的积极影响。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-06-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AI研习社 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • LinkedIn 数据科学社区
  • 从深度学习和计算机视觉开始
  • 1. 使用 OpenCV 手动执行
  • 2.基于 OpenCV 的疲劳检测
相关产品与服务
腾讯云小微
腾讯云小微,是一套腾讯云的智能服务系统,也是一个智能服务开放平台,接入小微的硬件可以快速具备听觉和视觉感知能力,帮助智能硬件厂商实现语音人机互动和音视频服务能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档