底下簡介個人讀RCNN 系列 目標檢測的個人心得筆記:
Ashing's Blog
機器學習及深度學習心得筆記,及使用3D印表機及Arduino製作機器人,機械手臂,自走車...
2020年12月14日 星期一
2020年5月23日 星期六
Jest Xavier NX 簡易安裝跑起YOLOV4
1. 先安裝Nvidia 提供的NX image.
https://developer.nvidia.com/embedded/learn/get-started-jetson-xavier-nx-devkit#write
2.安裝Jtop 可檢視CPU ,GPU ,Memory,溫度...等等 使用狀況
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip python3-dev build-essential
sudo -H pip3 install jetson-stats
sudo jtop
3.直接下載Darknet 編譯及安裝
git clone https://github.com/AlexeyAB/darknet.git
cd darknet
sudo gedit Makefile
修改Makefile內容:
##--------------------------------------------------------
GPU=1
CUDNN=1
CUDNN_HALF=1
OPENCV=1
AVX=0
OPENMP=0
LIBSO=1
ZED_CAMERA=0 # ZED SDK 3.0 and above
ZED_CAMERA_v2_8=0 # ZED SDK 2.X
##---------------------------------------------------------
sudo gedit ~/.bashrc
增加以下內容到 .bashrc 最後:
##--------------------------------------------------------
export DARKNET_HOME=/home/_name_/darknet/
export CUDA_HOME=/usr/local/
export PATH=${DARKNET_HOME}:${CUDA_HOME}bin:${PATH}
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
##--------------------------------------------------------
Note:_name_ 要改成你的系統名子
然後使其生效:
source ~/.bashrc
然後編譯:
make
編譯成功後 ,使用./darknet 測試,應出現如下結果
下載yolov4.weight 以及任一個測試video檔如 tested50.mp4(請自己準備或從youtube下載)
yolov4.weight下載聯結:
https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
接著執行以下指令及可以跑起Yolov4 ,FPS 約4~4.5
./darknet detector demo ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights test50.mp4 -i 0 -thresh 0.25
如果要跑Yolov3的話改成以下指令:
./darknet detector demo ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights test50.mp4 -i 0 -thresh 0.25
需要有相對應的weight 檔
需要有相對應的weight 檔
如果要開啟USB camera 將darknet_video.py 82,83列改成以下,即可跑起USB camera
執行
python3 darknet_video.py
cap = cv2.VideoCapture(0)
#cap = cv2.VideoCapture("test.mp4")
另外這裡有一個我已經編譯好的簡易版vscode 可以從這裡下載:
https://drive.google.com/file/d/1GH9bC3uLwJwZTbOloYafpZU7O5CtGend/view?usp=sharing
然後安裝:
sudo dpkg -i code-oss_1.35.0-1558361432_arm64.deb
使用 code-oss
可以使用在Jetson Nano or NX 都可以
以上就是快速簡易的安裝讓YoloV4 或Yolov3 跑起來,之後如果要安裝tensorflow 或是pytorch
等等框架可以直接參考以下聯結Jeston Zoo:
https://elinux.org/Jetson_Zoo
適用於各Jetson 系列
另外在本文的設定裡,並沒有安裝使用python 虛擬環境,原因是個人覺得其實不需要
其實裝的東西沒那麼複雜,再來則是省去了需要做link的動作,例如如果做了python 虛擬環境
則需要將opencv tensorrt 這些module link到你的虛擬環境裡。所以,尤其對初學者而言其實不去做python 虛擬環境會比較方便。如果真的想做,之後再做其實也可以。
最後來個 Yolov4 辨識ok手勢的Demo on Jestson Xavier NX
416x416 FPS: 7~8
https://youtu.be/LQ0niAgDdis
2018年10月10日 星期三
深度學習(8)--使用Tensorflow Object Detection API 實現物件自動辨識
2017年6月,Google公司開放了Tensorflow Object Detection API。這個專案使用TensorFlow 實現了大多數深度學習目標檢測架構,其中就包含Faster R-CNN。在本文章中將會介紹如何安裝Tensorflow Object Detection API,再介紹如何使用已訓練好的模型進行物體檢測,本文介紹的環境將會是架構在Windows 10 上面,使用Python 3.5.2,TensorFlow V1.9,最後並利用OPENCV 的WebCam攝影功能,利用攝影機即時辨別物體。
底下就先來觀看利用攝影機即時辨別物體的DEMO影片吧。
<Demo 影片>
2018年8月10日 星期五
Python(3)--Python小遊戲_黑白棋
這是一個經典的小遊戲黑白棋,在8x8 格子上玩家與電腦輪流下子,本示例程式用O,X來替代黑子與白子。遊戲玩法為黑子玩家與白子玩家輪流下自己顏色的棋子,在新下的棋子與同顏色的另一個棋子之間,如果有任何對手的棋子,都將其反轉,遊戲的目標是讓玩家自己的棋子盡可能的多。最後留下的棋子數最多者為贏家。
本程式由Python3.5.2 +Pyqt5 製作而成,範例代碼可由下面連結取得
https://github.com/Ashing00/Othello/tree/master
程式執行畫面如下圖所示:
本程式由Python3.5.2 +Pyqt5 製作而成,範例代碼可由下面連結取得
https://github.com/Ashing00/Othello/tree/master
程式執行畫面如下圖所示:
2018年8月3日 星期五
Python(2)--Python小遊戲_井字棋
這是一個經典的小遊戲井字棋,在九宮格上玩家與電腦輪流畫OXO,當每列或每行或是兩個對角成一線時便是獲勝。
本程式由Python3.5.2 +Pyqt5 製作而成,範例代碼可由下面連結取得
https://github.com/Ashing00/tictactoe/tree/master
程式執行畫面如下圖所示:
程式提供了兩種人工智慧選擇,一個是強人工智慧另一個是弱人工智慧,選擇強人工智慧,如果電腦先下,玩家可以說是沒有贏的可能,因此特地弄出一個弱人工智慧選項,一來增加遊戲的趣味,一來可以比較這兩者在程式設計上的差異。選擇弱人工智慧,玩家通常可以簡單的獲勝。
遊戲一開始還須得選擇O或X,然後會隨機選擇玩家先下或是電腦先下。
2018年3月25日 星期日
深度學習(7)--使用Tensorflow實現類VGG model 訓練Cifar10數據集
繼上一篇我們使用Alexnet 模型來訓練Cifar10數據集,這次我們改用VGG16 模型來做訓練及預測。Cifar10的數據集可以從以下網址下載:
https://www.cs.toronto.edu/~kriz/cifar.html
從本質上來看,VGGNet 是在更細的粒度上實現的AlexNet,他廣泛的使用非常小的卷積核架構去實現更深層次的卷積網路神經網路。在一定的程度上證實了,增加卷積神經網路的深度,增加更多的隱藏層和權重可以實現對識別的明顯改進。
從VGGNet的結構上來說,與AlexNet並沒有太大的區別,只不過增加了更多隱藏層,VGG的參數較多調整範圍大,而最終生成的模型參數是AlexNet的3倍左右,VGGNet的模型圖如下圖所示:
<picture 1> VGGNet的模型圖 , citation: htpps://arxiv.org/pdf/1409.1556.pdf
2018年1月26日 星期五
機器學習(10)--訊息量、資訊熵(Information Entropy)
訊息量
在資訊理論中,訊息量是有確定解釋並可以量化計算的,這裡提到的訊息量是一種資訊數量化,度量的規則。用科學公式性的方法去量化一段文字有多少資訊的想法,最早是由哈萊特(RVL Hartley)在1928年首先提出。他將消息數的對數(log)定義為訊息量。若信源有m種消息,且每個消息是以相等的可能性產生的,該信源的訊息量可表示如下:
上述公式是一個以m為引數的對數函數,舉個具體的例子:
假設中國桌球隊與巴西桌球隊的男子單打比賽,注意它不存在平局的狀況,也就是說要麼中國桌球隊獲勝不然就是巴西桌球隊獲勝,這兩個就是已經所有可能發生的情形。只有兩種情形,在上述公式中即m=2,信源有兩種,即"中國隊獲勝巴西隊失敗"或是"巴西隊獲勝中國隊失敗"。將m=2帶入上述公式:
訊息量為1,單位是bit。
2017年11月30日 星期四
Python(1)--下載Youtube影片成MP3
本章節提供一Python 範例程式,使用youtube_dl套件可將Youtube影片聲音下載成MP3。
注意此程式只供學習Python使用,未涉及侵犯各youtube影片或音樂聲音的版權。
請使用者在使用此程式時,自行注意相關版權的使用條款。
底下是完整的Python +Qt5的source code 下載。
Python sample code 下載:
https://github.com/Ashing00/ytpmp3/blob/master/ytbmp3.py
底下是build好的執行檔,可以直接執行,不須python 環境。
https://drive.google.com/file/d/1RVPSHXBhVMLAgUXAuiFvbV9ZBmAD_DO4/view?usp=sharing
下圖是python程式執行時畫面(也可直接執行ytbmp3.exe),
首先到youtube上找到欲下載的網址,複製到位址列,再按下<下載>
即可將該youtube的聲音下載並轉成MP3.
注意,該程式需要配合FFmpeg 使用,可從底下網址下載
https://ffmpeg.zeranoe.com/builds/
解壓縮之後將/bin 裡的ffmpeg.exe/ffplay.exe/ffprobe.exe 放在跟執行程式的同一目錄下
才能轉成MP3喔。
當出現<Finish!> 表示轉換及下載已完成。
<程式執行畫面>
2017年8月25日 星期五
深度學習(6)--使用Tensorflow實現類AlexNet model 訓練Cifar10數據集
繼上一篇我們使用Alexnet 模型來訓練MNIST 數據集,這次我們改用Cifar10數據集來做訓練及預測。Cifar10的數據集可以從以下網址下載:
https://www.cs.toronto.edu/~kriz/cifar.html
它總共包含60000張32x32 RGB彩色的圖案,前五個檔案各有10000張圖檔為訓練數據集,最後10000張為測試用數據集。該數據集分成10個類別,以數字編號0-9分別是
airplane










automobile










bird










cat










deer










dog










frog










horse










ship










truck










首先,照慣例我會先練習如何讀進Cifar10數據集從原始的二位元檔案至Numpy的矩陣格式,以便後續處理,這樣也可以用matplotlib套件秀出原圖,這樣做的意義是,就像之前所做的手寫數字辨識練習,可以加入自行創建或收集的圖片再進行預測或訓練,就不會只限於原始的數據集。也就是說如果懂得如何將圖片轉成Numpy的矩陣格式,那麼我就可以使用這個圖片做訓練或預測。例如常見的OpenCV套件不僅可以做到將圖片轉成Numpy矩陣格式,並且可以做很多的效果預處理,如裁減、灰化、調整對比或大小等等。
在Cifar10的數據集裡每一Row 包含的第一個byte為類別標籤,接下來的1024,1024,1024共3072(32x32x3)byte分別代表該圖R,G,B的數據。
底下一範例程式,便是可以將原始的Cifar10二進位檔讀出,轉成Numpy矩陣資料格式後,
再用Matplotlib套件,便可還原出原始圖檔:
https://github.com/Ashing00/Cifar10/blob/master/read_cifar.py
效果如下圖所示,上面的數字為其對應的類別標籤。
訂閱:
文章 (Atom)