Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Recognition

Recognition

辨識: 文字 影像 航照 車牌 人臉

語音辨識

數位影像可視為由數字代表區域間像素明亮度的二維陣列,聲音檔案是由時間和聲音強度所組合的一維陣列。

from sklearn.datasets import load_digits
digits = load_digits()
digits.images.shape

import matplotlib.pyplot as plt
fig, axes = plt.subplots(10, 10, figsiz=(8, 8), subplot_kw={'xticks':[], 'yticks':[]}, gridspec_kw=dict(hspace=0.1, wspace=0.1))
  for i, ax in enumerate(axes.flat):
    ax.imshow(digits.images[i], cmap='binary', interpolation='nearest'_
    ax.text(0.05, 0.05, str(digits.target[i]), transform=ax.transAxes, color='green')

Scikit-Learn 需要的格式是 [n_samples, n_features] 二維表示法,可以透過把每一在影像中的像素當做是一個特徵,藉由把像素陣列平面化,讓一個長度為 64 的像素值陣列可以表示每一個數字元,接著還需要一個目標陣列,用來放每一個數字元之前定義的標籤。這兩個值可以被建立到數字元資料集中,分別放在 data, target 屬性,下例是 1797 個樣本 64 個特徵:

X = digits.data
X.shape
y = digits.target
y.shape

想在 64 維的參數空間進行資料視覺化很困難,常見會使用非監督式學習把維度降低到 2,可應用 Manifold Learning Algorithm 的一種 Isomap 來轉換資料:

from sklearn.manifold import Isomap
iso = Isomap(n_components=2)
iso.fit(digits.data)
data_projected = iso.transform(digits.data)
data_projected.shape

把資料分成訓練組和測試組,再擬合 Gaussian naive Bayes 模型:

Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, random_state=0)
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
model.fit(Xtrain, ytrain)
y_model = model.predict(Xtest)

利用真實值與預測值進行比較來計算它的正確率:

from sklearn.metrics import accuracy_score
accuracy_score(ytest, y_model)

約有 83% 的分類正確率,但單就這數字並未得知是哪些地方發生錯誤,透過 Confusion Matrix 可以畫出陣列:

from sklearn.metrics import confusion_matrix
mat = confusion_matrix(ytest, y_model)
sns.heatmap(mat, square=True, annot=True, cbar=False)
plt.xlabel('predicted value')
plt.ylabel('true value')

Transfer Learning for Image Classification using Keras detecting-breast-cancer-in-histopathological-images-using-deep-learning fast-ai-deep-learnings-part-i-eye-in-the-sky

image-segmentation-using-pythons-scikit-image-moduleI

航照屋頂識別

OpenCV

圖檔常以 PGM 格式儲存,它的表頭依序載明 P2 或 P5 的格式類型,影像寬度高度,灰階最大值。

win_name = 'mypicture'
cv2.namedWindow(win_name, cv2.WINDOW_NORMAL)
img = cv2.imread('mypicture.jpg', 1) # 0 for grey, 1 for color
cv2.imshow(win_name, img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Haar cascade vs LBP cascade: 都是使用 Adaptive Boosting 演算法實現的

Enhance Image Restoration

Ubuntu Installation Object Detection with ImageAI

auto crop and rotate scanned images 自動裁切白邊修正傾斜角度

找圖裡的道路

Part of Speech Tagging with Hidden Markov Chain Models

Image Processing: openalpr

Doorbell with Facial Recognition Face Recognition cucumber-9 小黃瓜

ResNet

Implementation From Scratch implementing-resnet-with-mxnet-gluon-and-comet-ml-for-image-classification https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/ 個人覺得如果要快,有幾種方法: 1. 上 gpu,不過要考慮資料傳遞至 gpu memory 也是要花時間的,如果圖片量不大,那可能還更慢。而且 opencv 大部份的函式都無法 gpu 加速吧。 2. 事先將資料庫的圖片都先抽好 feature,然後利用 KD-Tree 或 VP-Tree 之類的資料結構來加速搜尋。 3. 如果只想快的,使用 PCA 也可以做 face recognition,這個速度相對快一些。 https://zh.wikipedia.org/wiki/%E7%89%B9%E5%BE%81%E8%84%B8 4. 如果想要上 deep learning,可以參考 facenet 即其之後的研究,效果都很好,當然,都很慢。 個人建議你先研究你的系統 bottleneck 是哪個部份,如果是 matching 就換 VP-Tree;如果是抽特徵,就換成 PCA;如果是 face detection 的部份那可能就沒救了,我想不到簡單的方法來加速 face detection。