# YOLOv8 install for docker YOLOv8的配置條件是Python>=3.8 以及神經網路框架PyTorch>=1.8. 本文參考YOLOv8官方 [https://github.com/ultralytics/ultralytics](https://) ## 安裝python 用`python3 --version`確認python版本。 沒有安裝過python的話用`sudo apt-get install python3`安裝 接著安裝pip這個工具`python get-pip.py` 確認已正確安裝了pip` pip --version` ## 安裝pytorch 到pytorch官網>Get Started [https://pytorch.org/](https://) 根據**你的配置選項**在Run this Commend 會教你使用不同的命令進行安裝。  ## 安裝YOLOv8 在終端輸入 ``` pip install ultralytics ``` **如果是Docker環境的安裝(this part is still under developemnt!)** ``` #將想要的映像檔名設為一個變數 t=ultralytics/ultralytics:映像檔名 ``` 官方對於docker映像檔提供了幾種對應不同需求的版本: latest:建議用於訓練的 GPU 映像。 latest-arm64:針對 ARM64 架構進行了最佳化,允許部署在 Raspberry Pi 和其他基於 ARM64 的平台等裝置上。 latest-cpu:基於 Ubuntu 的僅 CPU 版本,適用於推理和沒有 GPU 的環境。 latest-jetson:專為 NVIDIA Jetson 裝置量身定制,整合針對這些平台最佳化的 GPU 支援。 latest-python:僅包含 Python 和必要依賴項的最小映像,非常適合輕量級應用程式和開發。 ``` # Pull這個映像檔 sudo docker pull $t # 在容器內以GPU跑這個映像檔 sudo docker run -it --ipc=host --gpus all $t # 使用全部的GPU sudo docker run -it --ipc=host --gpus '"device=2,3"' $t # 使用特定的GPU ``` 上面的指令使用最新的映像初始化 Docker 容器ultralytics。該-it標誌分配一個偽 TTY 並保持標準輸入打開,使您能夠與容器互動。該--ipc=host標誌將 IPC(進程間通訊)命名空間設定為主機,這對於在進程之間共享記憶體至關重要。此--gpus all標誌允許存取容器內所有可用的 GPU,這對於需要 GPU 運算的任務很重要。 ``` # 將本機儲存庫掛載到容器 sudo docker run -it --ipc=host --gpus all -v /path/on/host:/path/in/container $t ``` ## 使用YOLOv8 YOLOv8可以直接在終端中呼叫使用,用predict指令以所選的model對source進行偵測 ``` yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg' ``` 也可以在python程式中使用 ``` from ultralytics import YOLO # Load a model model = YOLO("yolov8n.yaml") # build a new model from scratch model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training) # Use the model model.train(data="coco128.yaml", epochs=3) # train the model metrics = model.val() # evaluate model performance on the validation set results = model("https://ultralytics.com/images/bus.jpg") # predict on an image path = model.export(format="onnx") # export the model to ONNX format ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up