Firefly开源社区
标题: USB神经网络计算卡使用PLAI软体进行模型建构与训练 [打印本页]
作者: Firefly 时间: 2019-4-26 10:34
标题: USB神经网络计算卡使用PLAI软体进行模型建构与训练
並將GTI_PLAI_v1.0.tar.gz拷貝到家目錄。
- bash Anaconda3-2018.12-Linux-x86_64.sh
复制代码- Do you accept the license terms? [yes|no]
- [no] >>> yes
- Anaconda3 will now be installed into this location:
- /home/yilintung/anaconda3
- - Press ENTER to confirm the location
- - Press CTRL-C to abort the installation
- - Or specify a different location below
-
- [/home/yilintung/anaconda3] >>>
- Do you wish the installer to initialize Anaconda3
- in your /home/yilintung/.bashrc ? [yes|no]
- [no] >>> no
-
- Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
- >>> no
复制代码
完成後,回到家目錄並建立Anaconda3.sh,內容於下:
- export LANG='UTC-8'
- export LC_ALL='en_US.UTF-8'
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64
- export PATH=/home/yilintung/anaconda3/bin:$PATH
- . /home/yilintung/anaconda3/etc/profile.d/conda.sh
复制代码
接著安裝Cuda:
- cd /tmp
- sudo apt-get update && sudo apt-get install wget -y --no-install-recommends && \
- wget "https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" && \
- sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb && \
- sudo apt-get update && \
- sudo apt-get install -y cuda-8-0
- wget [url]https://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz[/url] && \
- sudo tar -xzf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local && \
- rm cudnn-8.0-linux-x64-v5.1.tgz && sudo ldconfig && \
- cd -
复制代码
完成後,進入Anaconda Python環境,並建立Python虛擬環境PLAI;完成後進入該虛擬環境:
- source Anaconda3.sh
- conda create --name PLAI python=3.7 anaconda
- conda activate PLAI
复制代码
進行相關套件安裝:
- pip install opencv-contrib-python
- pip install [url]https://download.pytorch.org/whl/cu80/torch-1.0.1.post2-cp37-cp37m-linux_x86_64.whl[/url]
- pip install torchvision
复制代码
進入Python(在終端機下輸入 python ),用以下程式確認套件是否安裝正確:
- >>> import cv2
- >>> import torch
- >>> import torchvision
- >>> torch.cuda.is_available()
- True
复制代码
完成環境設定後,解壓縮PLAI軟體,並進行額外的設定:
- tar zxvf GTI_PLAI_v1.0.tar.gz
- cd PLAI
- sudo cp lib/python/gtilib/libftd3xx.so.0.5.21 /usr/lib/
- sudo cp lib/python/gtilib/*.rules /etc/udev/rules.d/
复制代码
由於我們要用GNet1模型,所以對training.json做以下修改:
- "mask_bits": "3,3,1,1,1",
- "act_bits": "5,5,5,5,5",
复制代码
以及修改PLAI.py:
- gtiPLAI = PLAI(num_classes=2, data_dir=data_dir, checkpoint_dir=checkpoint_dir, model_type=2, module_type=1, device_type=1)
复制代码
如果使用GPU進行訓練,在最後模型轉換會出現錯誤:TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。請下載這個
程式碼覆蓋PLAI目錄下同名的檔案。之後,進行模型建構與訓練:
最後,使用
x86 SDK的liteSample來進行模型確認,命令如下:
- cd ~/SDK_x86/GTISDK/Bin/Linux/
- ./run-lite.sh -c ~/PLAI/coefDat_2801.dat -u ~/PLAI/nets/netConfig_2801_gnet1.txt -f ~/PLAI/coefBin_2801.bin -l ~/PLAI/data/pic_label.txt -i chenglong_15_vgg.img
复制代码
執行結果如下圖所示(照片是chenglong且模型推論也是chenglong):
原文链接:On-Device AI
———————————————
更多信息请关注Firefly公众微信号fireflytee:
———————————————
欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) |
Powered by Discuz! X3.1 |