2025/6/28

apksigner 在
./out/host/linux-x86/bin/apksigner 
platform.pk8 在
./build/make/target/product/security/platform.pk8
./build/make/target/product/security/platform.x509.pem
AOSP 中 OTA 相關的 generate key 說明:Sign build for release

2025/6/22

原來有一些遣在的 rule.
packages/app/app-name 這個 app-name 要跟 Android.bp 的

2025/6/19

Cuttlefish Android Emulator

ref: 原來在 aosp 中的 emulator (goldfish) 在run aosp android14 的時候, qemu x86 kernel 一邊沒 lz4,一邊 ramfs 好像不一樣。
然後 aosp source project site 說明 竟然都寫 cuttlefish 了。

cuttlefish 已經是獨立的 project,clone 下來後,build 成 deb,需要 libtinfo5,所以ubuntu24.04 用 libtinfo6 會 build fail。
只好download libtinfo5 的 deb 下來 install,才能 build 成功。
tools/buildutils/build_packages.sh

build 完會有這麼多 deb..
  • cuttlefish-orchestration_1.13.0_amd64.deb : 在 google 的 雲端server 用的(?)
  • cuttlefish-base_1.13.0_amd64.deb : 這個就是 emulator 的 deb
  • cuttlefish-integration_1.13.0_amd64.deb : 跟google 雲端上的 emulator溝通用的一些tool
  • base/ cuttlefish-common-build-deps_1.13.0_amd64.deb :
  • cuttlefish-user_1.13.0_amd64.deb : web server 版的 emulator,會run 成一個 web server,用 browser 來操作
  • /frontend/cuttlefish-frontend-build-deps_1.13.0_all.deb :
  • cuttlefish-common_1.13.0_amd64.deb : [DEPRECATED]
所以把 base 和 user 安裝(用 apt),之後,會產生 幾個 group,要把自己加進去:
sudo usermod -aG kvm,cvdnetwork,render $USER
然後因為會產生 /dev/ 下的node,所以要 reboot.

準備 system image,從 aosp build, target 是 aosp_cf_x86_64_phone-trunk-userdebug
build 完aosp source code,就會有 launch_avd 這個 command.
follow google 說明直接 launch 的話,會有 Error:
launch_avd
....
ailed to connect:No such device
[2025-06-19T10:09:00.523729147+00:00 ERROR crosvm] exiting with error 1: the architecture failed to build the vm

Caused by:
    failed to create a PCI root hub: failed to create proxy device: Failed to configure tube: failed to receive packet: Connection reset by peer (os error 104)
Detected unexpected exit of monitored subprocess /home/charles-chang/aosp/out/host/linux-x86/bin/process_restarter
Subprocess /home/charles-chang/aosp/out/host/linux-x86/bin/process_restarter (16314) has exited with exit code 1
Failed to connect:No such device
Client closed the connection
Client closed the connection
Client closed the connection
[2025-06-19T10:09:01.549915546+00:00 ERROR crosvm] exiting with error 1: the architecture failed to build the vm

Caused by:
    failed to create a PCI root hub: failed to create proxy device: Failed to configure tube: failed to receive packet: Connection reset by peer (os error 104)
....
不知道是什麼原因,但是加上 gpumode 之後就可以開起來..
launch_cvd --gpu_mode=gfxstream
...
VIRTUAL_DEVICE_BOOT_STARTED
VIRTUAL_DEVICE_NETWORK_MOBILE_CONNECTED
VIRTUAL_DEVICE_BOOT_COMPLETED
Virtual device booted successfully
依照 google cuttlefish 的說明,這樣啟動的 emulator 是沒有螢幕的,所以用 adb 可以連線。
開啟 webserver 的話,加上 --daemon
launch_cvd --gpu_mode=gfxstream --daemon
...
Virtual device booted successfully
VIRTUAL_DEVICE_BOOT_COMPLETED
這樣會跑在background,用 browser 開啟 http://localhost:8443 就會看到 cvd-1
按下 "connect" 就會出現android 手機畫面..
google 建議用 webrtc,效果會更好。
launch_cvd --gpu_mode=gfxstream -start_webrtc --daemon
停止要用 cvd reset 或 stop_cvd

cuttlefish 使用 virtual network,所以沒版法直接 listen public IP。
如果其他機器要連線,要用 ssh-tunnel:
  • 在 remote mynb 啟動 cuttlefish -start_webrtc
  • 在 local pc 設定 ssl tunnel : ssh -L 50000:localhost:8443 myname@mynb
  • local pc 的 browser 開啟 localhost:50000


cuttlefish 啟動過就會在 $HOME 之下create 一個 cuttlefish 目錄,其中
  • assembly : 設定檔
  • environment : 會有folder env-1,裡面是上次run 的環境變數
  • instance : 會有 folder cvd-1 (emulator id),上次的instance 紀錄
然後在 $HOME 下,會有cuttlefish_XXX link 到 cuttlefish 下的folder/file。
所以一旦emulator 出問題,關掉下次再開也是出問題,用 cvd reset 也無效,就要手動刪掉那些 cvd-1 目錄。

所以在 ~/cuttlefish/instance/cvd-1/ 裡:
  • kernel.log : 就是 kernel message
  • console : 就是 emulator 的 console,會是 link 到 /dev/pty/X,可以用 screen 來開



emulator 是否run 的起來,竟然和host和 android image 有關,使用 Adnroid-14 AOSP build 出來的 aosp_cf image,在有些pc 上可以 run,有些不行,有些要加 --gpu_mode,有些不能加。
而且 run 起來後,app 啟動計次顯示就會發生問題,系統反應也變慢。
但是使用 -b android-latest-release 的image則幾乎所有機器都沒問題,而且只需要加 --start_webrtc 就可以,不用管 --gpu_mode,cuttlefish 會自己偵測。

2025/6/15

Build image from AOSP and run on emulator

ref:
想要build aosp 在 emulator 跑,測試 user build 和 userdebug build 的差異。
然後..
先 clone source..
mkdir aosp && cd aosp
repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r75 --depth=1
repo sync -c --no-tags --no-clone-bundle -j3
超過 3 就會有 resource limiit error,其實最後還是用1。
中途出現一些 checkout error,把整個source code 刪除,留下 .repo 目錄,再 sync 一次就 OK

然後做 lunch,這個有點問題
source buile/envsetup.sh
lunch
出現一堆,但是都沒有類似說明的 x86_64,ref:how do I build android emulator from source 的說明。
有些 lunch target 本來就不會show,所以試試看
lunch sdk_phone64_x86_64-trunk_staging-user
竟然 OK 了。-- 嘗試 userdebug, eng 也都 OK
把 printconfig列出來確認:
============================================
PLATFORM_VERSION_CODENAME=VanillaIceCream
PLATFORM_VERSION=VanillaIceCream
PRODUCT_INCLUDE_TAGS=com.android.mainline mainline_module_prebuilt_nightly
TARGET_PRODUCT=sdk_phone64_x86_64
TARGET_BUILD_VARIANT=user
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-6.8.0-60-generic-x86_64-Ubuntu-24.04.2-LTS
HOST_CROSS_OS=windows
BUILD_ID=AP2A.240805.005.S4
OUT_DIR=out
============================================
如果依照 ref 的說明
lunch aosp_cf_x86_64_only_phone-aosp_current-userdebug
...
build/make/core/release_config.mk:145: error: No release config found for TARGET_RELEASE: aosp_current. Available releases are: ap2a next staging trunk trunk_food trunk_staging.
依照error 說明把 aosp_current 改掉
lunch aosp_cf_x86_64_only_phone-trunk-user
就可以了 (順便測試 user build 也 OK)
============================================
PLATFORM_VERSION_CODENAME=VanillaIceCream
PLATFORM_VERSION=VanillaIceCream
PRODUCT_INCLUDE_TAGS=com.android.mainline mainline_module_prebuilt_nightly
TARGET_PRODUCT=aosp_cf_x86_64_only_phone
TARGET_BUILD_VARIANT=user
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=silvermont
HOST_OS=linux
HOST_OS_EXTRA=Linux-6.8.0-60-generic-x86_64-Ubuntu-24.04.2-LTS
HOST_CROSS_OS=windows
BUILD_ID=AP2A.240805.005.S4
OUT_DIR=out
============================================
cf 就是給 cuttlefish (android emulator name) 用的。



有時候 build 到最後會有Error,說 /dev/loop2 沒有,這是因為沒有 disk 權縣,加入 disk group 就可以了。



google 說以後都要用 AOSP-release 了。
加上用 android 14 的tag, cuttlefish ru 一下就 hang 住,拿 prebuild 的又OK。
查 prebuild 是Android-16,所以 follow aosp 說明...
repo init --partial-clone --no-use-superproject -b android-latest-release -u https://android.googlesource.com/platform/manifest
repo sync -c -j3
依照googlesource 說明
lunch aosp_cf_x86_64_only_phone-aosp_current-userdebug
因為現在 lunch 都不會出現target 讓你選了。

然後就可以用 m 來 build.
ubuntu 24.04 會出現 mount error, ref: permission denied in mount (/):
sudo sysctl -w kernel.apparmor_restrict_unprivileged_unconfined=0
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
或是增加這個檔案到系統,免得每次開機都要重新設:
$ cat /etc/sysctl.d/99-apparmor-unconfined.conf
kernel.apparmor_restrict_unprivileged_unconfined=0
kernel.apparmor_restrict_unprivileged_userns=0

$sudo sysctl --system

2025/6/5

google 為了 GKI 的 kernel , mantain 了一個 manifest.xml,裡面包含 kernel source 和 build kernel image 需要的 tool。
所以用repo把對應的manifest.xml 的所有project都拉回來就可以 build 了,不用再額外安裝tool

build kernel image 使用 bazel
tools/bazel run //common:kernel_aarch64_dist -- --dist_out=out

2025/5/23

install pythton2.7 to ubuntu 24.04

因為 ubuntu 24.04 把 python2 整個移除了,所以 apt 沒有 python2 了。
一般說明都是download python2 source 來 build.
但是從 Python2.7.13 開始,在 ubuntu 24.04 上 build 就會有 ssl function error。
所以若是要用 2.7.13 以上的版本,只好用 AppImage,ref: 下載需要版本的 appimage 後,chmod +x,之後建 link 到 /usr/bin/python2 就可以用了。
--- 雖然不知道會不會有危險,但是它也有提供source:python-appimage,只是env packages 是從docker image 拿的。

2025/5/19

networkmanager, netplan

ubuntu 24.04 用 NetworkManager 來設定 網路相關功能。
所以都用 nmcli 做,不用像以前要設定 iptable, dnsmasq..
所以都會出現在 /etc/netplan/***.yaml

每個 network 設定都會再 /etc/netplan/ 下留下一個紀錄。
曾經發生過 設定 ipv4 share 的 NIC,device 無法正確 forward 出去。
network setting 在usb-network多出一個Setting,

之後把/etc/netplan/ 下沒用到的,不正確的 yaml 刪除重新開機後,好像就正常了。

2025/5/14

DMAR error, intel_iommu

apt update 後,到 UI 的 Software Updater 去更新,其實只有選把nouse 的 remove,結果更新後,第二螢幕變白。
重開機後卡在開機 splash,因為以前有出現過,所以把第二螢幕移除,重開機後 OK,在接上外接螢幕,外接螢幕白色。
看 dmesg 有一堆:
DMAR: [DMA Read NO_PASID] Request device [04:00.0] fault addr 0xff62e000 [fault reason 0x06] PTE Read access is not set
[19704.235699] DMAR: DRHD: handling fault status reg 3
...
所以google 一下,都說是這樣: 就是修改 /etc/default/grub..
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=off"
然後更新
update-grub
之後重開機就正常了。

據說那個error 是 write access right 沒有set。

2025/5/10

Upgrade Node to 20.X --- for copilot in vim


ubuntu 24.04 的 nodee 版本是 18。copilot for vim 要 20.X,
所以要手動 upgrade. ref: 大概就是先 remove nodejs…然後 run
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
然後再 apt install nodejs

裝完是 20.19

進入 vi 後
:Copilot help
會 show copilot command,就是 copilot.txt
要先 authenticate..
:Copilot setup
果然不知道怎麽用...

告訴它
:set filetype=c
看狀態
:Copilot status

2025/5/8

DeepWiki Open

所以步驟大概是這樣。
如果不是要 run 在 local,在 Server 上
git clone https://github.com/AsyncFuncAI/deepwiki-open.git
參考上一篇,修改 NEXT_PUBLIC_SERVER_BASE_URL 到 server 的 public ip address.
啟動 backend
pip install -r api/requirements.txt
python -m api.main
啟動 front-end
npm install
npm run dev -- -H 0.0.0.0
然後就可以開啟 http://server-ip:3000

因為支援 local folder,所以可以去 server clone repo,然後在 project 位置填絕對 path.
勾 Local Ollama Model (Experimental)
就可以開始 Generate Wiki

他使用的 ollama model 寫在 api/config.py,可以自己修改。

2025/5/3

亂記一些

這邊是有關 deepwiki-open:

從Dockerfil 看到 python 是 3.11
python 啟動的是 backend server,用 npm run 啟動的是 fron-end.
fron end 原來 listen on localhost,用 npm run 的 command:
npm run dev -- -H 0.0.0.0
就可以改到 public ip
使用 docker compose up 的話,使用 ollam 時,要修改:
diff --git a/docker-compose.yml b/docker-compose.yml
index a7d42c3..b1d85d3 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,6 +3,7 @@ version: '3.8'
 services:
   deepwiki:
     build: .
+    network_mode: host
     ports:
       - "${PORT:-8001}:${PORT:-8001}"  # API port
       - "3000:3000"  # Next.js port
把 contrainer 的 localhost:11434 使用 host 的,才能跟 ollama 連接。

原來他的 front-end, ts code,連到 localhost,所以是連到 browser 所在主機的 localhost,不是 server ...
所以要 修改 client side 的 SERVER_BASE_URL,用 server 的 ip:
diff --git a/docker-compose.yml b/docker-compose.yml
index a7d42c3..210e476 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,6 +3,7 @@ version: '3.8'
 services:
   deepwiki:
     build: .
     ports:
       - "${PORT:-8001}:${PORT:-8001}"  # API port
       - "3000:3000"  # Next.js port
@@ -11,6 +12,6 @@ services:
     environment:
       - PORT=${PORT:-8001}
       - NODE_ENV=production
-      - NEXT_PUBLIC_SERVER_BASE_URL=http://localhost:${PORT:-8001}
+      - NEXT_PUBLIC_SERVER_BASE_URL=http://192.168.145.77:${PORT:-8001}
     volumes:
       - ~/.adalflow:/root/.adalflow  # Persist repository and embedding data
發現沒辦法support gitlab 的 subgroup,因為會和產生的 page 的 path 混在一起,而 source code 的result http server 頁面是依照source path 安排的。
更新後發現支援 local path,所以就 clone 到 local disk 後再給 path 就可以。
這邊的 local 又變成 server 的 local,不是 browser 的 local。
所以都要在 run 的那台 server 上clone source 之後,給 full path.


  • DeepWiki opensource implement
  • huggingface agent : smolagents, E2B Desktop, Qwen2-VL-72B-Instruct
  • LTX-Video : ComfyUI
  • uv




還有今天apt update/upgrade 後,lcd backlight 又失效了。
然後進入additional driver 設定想換 driver 出現 Error。
要反悔又不行。
一直出現 要 apt --fix-broken install
但是又會出現 overwrite error /var/.../*.deb,
所以只好 follow stackoverflow 說明,用 apt -i --force-overwrite /var/..../*.deb 來強制 install
sudo dpkg --force-overwrite /var/cache/apt/archives/libnvidia-common-570-server_570.133.20-0ubuntu0.24.04.1_all.deb
最後還是 fail 因為unpack 某個 deb 出現 /usr/share/nvidia/files.d/sandboxutils-filelist.json 無法overwrite,
去看這個是 folder ,所以無法 overwrite,rename 後就可以了,然後那個 deb 就 create 了一個同名 file。
繼續 apt fix,出現 error,照次說 sandboxutils-filelist.json 無法 rmdif,--- 因為他是 file 呀!
所以就去把 file 刪掉,把剛剛rename 的 folder rename 回來。
才完成 fix
查 sandboxutils-filelist.json 目錄下有一個同名檔案,他的內容跟 file 的內容是一致的。
髓以我猜某一個 deb 稿錯了。

然後剛剛又 apt update, apt list --upgradable 看到 cuda-driver 有更新 575....
所以是更新成 575 造成 ? 還是要更新 575 才會 fix ?



要用 transformer run phi4-multimodal 要 install flash-attention:
pip install flash-attn --no-build-isolation
然後會用 cicc build 很久...

另外還要:
soundfile peft backoff 
結果phi4-multimodal 太大... 超過 24G..



enable conda in powershell,要 run
PS C:\Users\charles.chang> conda init powershell
no change     D:\miniconda\Scripts\conda.exe
no change     D:\miniconda\Scripts\conda-env.exe
no change     D:\miniconda\Scripts\conda-script.py
no change     D:\miniconda\Scripts\conda-env-script.py
no change     D:\miniconda\condabin\conda.bat
no change     D:\miniconda\Library\bin\conda.bat
no change     D:\miniconda\condabin\_conda_activate.bat
no change     D:\miniconda\condabin\rename_tmp.bat
no change     D:\miniconda\condabin\conda_auto_activate.bat
no change     D:\miniconda\condabin\conda_hook.bat
no change     D:\miniconda\Scripts\activate.bat
no change     D:\miniconda\condabin\activate.bat
no change     D:\miniconda\condabin\deactivate.bat
modified      D:\miniconda\Scripts\activate
modified      D:\miniconda\Scripts\deactivate
modified      D:\miniconda\etc\profile.d\conda.sh
modified      D:\miniconda\etc\fish\conf.d\conda.fish
no change     D:\miniconda\shell\condabin\Conda.psm1
modified      D:\miniconda\shell\condabin\conda-hook.ps1
no change     D:\miniconda\Lib\site-packages\xontrib\conda.xsh
modified      D:\miniconda\etc\profile.d\conda.csh
modified      D:\OneDrive\OneDrive - Royaltek\文件\WindowsPowerShell\profile.ps1

==> For changes to take effect, close and re-open your current shell. <==

2025/4/15

RK3588 MP520

black 在 pchome 買的 rk3588 板子。
打開蓋子有 maskrom button,所以一樣可以 boot to maskrom
然後 rkdevtool 看得到。

但是官方沒有提供 image file,所以不敢亂燒。
看論壇說 kernel source 是用 apt-get source 的方式提供的,但是我只有找到 dtb 和 header. 沒有source (GPL...疑慮)
只好用預燒的 image 開機,是 debian.
UI 還好算流暢,不會像 pi 用 gui 那樣很頓。
可以用 chromium 看 youtub, hd OK, 4k 會卡,然後 cpu 超熱 (沒有使用 hardware codec ?)
用 top 看有一個 pipewire process 一直吃掉一個核...

因為不能動image,也沒有 uboot, kernel source,所以只好試試看 npu。
follow : ArmSoM Wiki: rknn-sdk
one@MB127:~$ dmesg | grep -i rknpu
...
[    4.532693] [drm] Initialized rknpu 0.9.6 20240322 for fdab0000.npu on minor 1
所以 kernel 有 enable rknpu
照著做,啟動 rknn_server 之後,把 *.rknn 轉好 scp 過去。
然後run:
(toolkit2) one@MB127:~/projects/rknn_model_zoo/examples/yolov5/python$ python yolov5.py --model_path ~/yolov5s_relu.onnx --img_show
use anchors from '../model/anchors_yolov5.txt', which is [[[10.0, 13.0], [16.0, 30.0], [33.0, 23.0]], [[30.0, 61.0], [62.0, 45.0], 
[59.0, 119.0]], [[116.0, 90.0], [156.0, 198.0], [373.0, 326.0]]]
/home/one/projects/rknn_model_zoo/py_utils/onnx_executor.py:12: FutureWarning: In the future `np.bool` will be defined as the 
corresponding NumPy scalar.
  if getattr(np, 'bool', False):
Model-/home/one/yolov5s_relu.onnx is onnx model, starting val
infer 1/1

IMG: bus.jpg
person @ (208 242 286 508) 0.881
person @ (478 238 560 525) 0.859
person @ (109 237 232 534) 0.842
person @ (79 355 121 515) 0.318
bus  @ (91 129 555 465) 0.702

發生 ssh 連線中斷問題,好像進入 suspend 了...
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: Link is Down
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: FPE workqueue stop
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: Register MEM_TYPE_PAGE_POOL RxQ-0
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: PHY [stmmac-1:01] driver [YT8531 Gigabit Ethernet] (irq=POLL)
[  4? 15 16:59:14 2025] dwmac4: Master AXI performs any burst length
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: No Safety Features support found
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: IEEE 1588-2008 Advanced Timestamp supported
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: registered PTP clock
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: FPE workqueue start
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: configuring for phy/rgmii-rxid link mode
[  4? 15 16:59:14 2025] rk_gmac-dwmac fe1c0000.ethernet end1: FPE workqueue stop
[  4? 15 16:59:15 2025] PM: suspend entry (deep)
[  4? 15 16:59:15 2025] Filesystems sync: 0.015 seconds
大概是no activity suspend,雖然有去 settings 確認關掉,但是還是沒用。
所以只好把所有 systemd 的 suspend service 關掉。
--- 關掉一堆,所以不知道真正有效是哪個。所以沒記。
about source code
ref: MP-520更新發生錯誤
關於MP520 Linux kernel版本的說明:
目前MP520採用的Linux kernel為SoC RK3588S原廠提供的版本加以修改成適合MP520主機板。RK3588S原廠推出新版的速度很慢。
我們會將原廠版本經過修改,並在每一滾動發行版中徹底測試再發佈出來。
另外開源界主流的Mainline linux kernel已有RK3588S版本,但是還只限於終端機文字模式,還很陽春,無法支援圖形視窗介面。
等到Mainline linux kernel的RK3588S版本可以支援圖形視窗時,MP520的Kernel,計劃從Mainline Kernel版本修改而成。
這樣就可以隨時保持最新版本了。不過估計至少還需要一、兩年以上的時間。

about system image
ref: MP520-20 請問有官方 image 的下載點嗎?
沒有,但是提供刷機服務
沒有 sourcecode,也沒有 image,所以只能買一個 nvme ssd 來換了,以免郵寄麻煩..
或是把 nvme ssd 接到 pc 來 DD 備份。
...不曉得有甚麼難處,不然找個 googledrive, mega 之類的放也可以,買的人沒很多,要 download 的人也不會很多吧。
可能 image 不是他們自己 build,他們沒有軟體工程師...

2025/4/12

隨便的 memo ...

沒 train 完的 yolo3,用 coco dataset 來試試看。
-- convert coco to pascal_voc format:
pascal_voc/
├── VOC2012/
│   ├── Annotations/         # XML annotation files
│   ├── ImageSets/
│   │   └── Main/
│   │       └── train.txt    # Training image names
│   └── JPEGImages/         # Image files (.jpg)
│
└── VOC2007/
    ├── Annotations/         # XML annotation files
    ├── ImageSets/
    │   └── Main/
    │       └── test.txt     # Testing image names
    └── JPEGImages/         # Image files (.jpg)
train.txt 是 filename list.
所以 自己去 annotations 找 filename.txt,
到 JPEGImages 找 filename.jpg
要分 train 和 validate。

coco dataset 的format:
一個 imagefolder 配一個 json,裡面有 folder 所有的 image 和 labels

datasets 的format 現在大概有三種
  • pascal_voc
  • coco
  • ultralytic yolo


dataloader( ) 中,參數是 filename list. txt 檔的 path,image folder path,label folder path
所以不用依照pascal_voc 的方式,只要 image,label 分開 folder放就可以。



這個: 說的 "YOLODataset" 就是哪個用空白格開的文字檔 (csv with space)
然後 folder 要依照
.
├── images
│   ├── train
│   └── val
└── labels
    ├── train
    └── val
好像有一個 filelist ..

還是專業的厲害,叫 gemma3:27b 從 dataset.py 找出 train.csv 的格式是什麼,一直鬼打牆說 train.csv 找不到。
換成 github copilot + sonnect 3.5,同樣的 prompt 就回答了(只是不知道鄭不正確):
Based on the code in dataset.py, I can explain how the train.csv file should be structured. The file is used to map image names to their corresponding label files.

The train.csv should contain two columns:
1. Image filename
2. Label filename

Here's an example of how train.csv should look:

```csv
image_name,label_name
image1.jpg,image1.txt
image2.jpg,image2.txt
dog_picture.jpg,dog_picture.txt
car_street.jpg,car_street.txt
```

Key points about the CSV structure:
- The image filenames should correspond to files in the `COCO/images/images/` directory
- The label filenames should correspond to files in the `COCO/labels/labels_new/` directory
- Each label file (.txt) contains the bounding box information in the format: <class_label> <x> <y> <width> <height&ht;`

You can create this CSV file using a simple Python script like this:

````python
import os
import pandas as pd

def create_train_csv(image_dir, label_dir, output_csv):
    image_files = [f for f in os.listdir(image_dir) if f.endswith(('.jpg', '.jpeg', '.png'))]
    data = []
    
    for img_file in image_files:
        # Assume label file has same name but .txt extension
        label_file = os.path.splitext(img_file)[0] + '.txt'
        if os.path.exists(os.path.join(label_dir, label_file)):
            data.append([img_file, label_file])
    
    df = pd.DataFrame(data, columns=['image_name', 'label_name'])
    df.to_csv(output_csv, index=False)

# Example usage
create_train_csv(
    'COCO/images/images/',
    'COCO/labels/labels_new/',
    'COCO/train.csv'
)
````

This script will:
1. Scan the images directory
2. Match image files with their corresponding label files
3. Create a CSV file with the correct format expected by the YOLODataset class

The dataset class then uses this CSV file to load the corresponding image and label pairs during training.
然後 COCO dataset 的 annotation 中 class (category 會到 90),但是只有列出 80 個。
據原始論文說是因為 2014 公佈時,object detection 只有這 80個,另外 10 個是 segmentation 的。
我照著說明,修改在這裡


他自己做好的 5k.part 是 ascii file,裡面是 image file 的 list
...
/images/val2014/COCO_val2014_000000581827.jpg
/images/val2014/COCO_val2014_000000581829.jpg
...
剛好有 5000 個 file

哪個 labels.tgz 其實是 tar,沒有gz
解開就是 YOLO 的 label 格式 txt,每個 image 都有一個。

2025/3/30

Disable Touchpad while Typing

很奇怪,gigabyte 的 AORUS 15X 在 ubuntu 24.04 下,dconf 的 "disable touchpad while typing" 功能竟然沒有用。
所以只好自己(請 gemini) 寫。 用 python 寫的。
停止 typing 到 re-enable touch 的時間有點太長。
但是改短threading.Timer( ) 的時間好像沒用 (resolution 好像不夠)。
叫 gemnini 用 c 寫,他說很複雜,用 kernel driver 他說最好不要。
所以只好將就用這個。

內容很簡單,就是 keyboard listener, on key press, disable touch and enable a timer.
timer timeout 的時候 re-enable touch

2025/3/26

Implement yolov3 from scratch and training

根據 yolov3 from scratch using pytorch 的 code section 整理整合的 code: 使用pascal VOC2012 train 做 training, val 做 validating。
training 500 次:


可以看到大約 56 epochs 的時候就 overfitting 了..

2025/3/14

Zed Editor

聽說可以免費用 Claude sonnet 3.7,所以來用用看。目前 Windows 版安裝檔還沒好,只能 build from source...
所以用 Linux 版。

都是用 keyboard Command.

第一個就是 Ctrl-I 叫出 AI Assistant.
然後問他 Zed 怎麼用..

就這樣,完了。

2025/3/13

miniconda in Windows -- change install, env and pkgs location

在 windows 就是麻煩,C: 沒空間,不能把新 HD mount 進來,不能建link到新 HD.然後一堆app 又一定要用 User/
像 conda 就是。
所以要改 path 很麻煩。

參考 這一篇,在自己的 user 目錄找到 .condarc,修改:
ssl_verify: true
channels:
  - defaults
envs_dirs:
  - D:/minicondaenvs
pkgs_dirs:
  - D:/minicondapkgs
這樣download 下來的 package file 和 create 的 environment 就會在 D:/mini....

修改玩參考 這一篇,可以看conda 有沒有正確依照.condarc:
>conda config --get
--add channels 'defaults'   # lowest priority
--add envs_dirs 'D:/minicondaenvs'
--add pkgs_dirs 'D:/minicondapkgs'
--set ssl_verify True

另外,因為windows 很麻煩,例如D:\Default 就是其他 user 不能寫入修改,所以記得要去 D:/miniconda (安裝目錄),和.condarc 的一堆目錄按右鍵,開啟一般user 的 write 權限。

2025/2/27

Enable SSH Server in Windows

是 Windows 10,所以參考: 測試有沒有安裝,在 PowerShell 下:
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
出現結果:
Name  : OpenSSH.Client~~~~0.0.1.0
State : Installed

Name  : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
所以安裝 server:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


Path          :
Online        : True
RestartNeeded : False

如果已經裝了,但是沒有設定自動啟動,就要手動啟動:
Start-Service sshd

然後linux就可以用 ssh 連回:
$ssh loyaltec\\charko.chang@192.168.144.78

2025/2/20

Intel Ultra 7, NPU.

要注意 intel 的 ai driver, library, toolkit 有分給 GPU (Arc) 跟 NPU 用的。

要先依照 linux-npu-driver 說明,自己 build driver. so 然後 install
因為後來 run 測試程式需要 build compiler with driver. 所以依照後面那個 "Building a driver together with the compiler" 說明比較好。
我有checckout v1.13.0 然後:
cd linux-npu-driver
git submodule update --init --recursive

cmake -B build -S . -DENABLE_NPU_COMPILER_BUILD=ON
cmake --build build --parallel $(nproc)

# install the driver in the system
sudo cmake --install build --prefix /usr

# reload the intel_vpu module to load new firmware
sudo rmmod intel_vpu
sudo modprobe intel_vpu
這樣就會 build NPU plugin 和 OpenVINO runtime
記得要把自己加到 render group.

最後 的 driver test,要在 linux-npu-driver 下做這些:
# Prepare the add_abc model in path pointed by basic.yaml
mkdir -p models/add_abc
curl -o models/add_abc/add_abc.xml https://raw.githubusercontent.com/openvinotoolkit/openvino/master/src/core/tests/models/ir/add_abc.xml
touch models/add_abc/add_abc.bin

# Run tests with add_abc.xml
npu-umd-test --config=validation/umd-test/configs/basic.yaml
才 run 得起來。

readme 的 llm example 跑不起來,會說缺 config,要 run example folder 下的 tinyllm。

run example folder 下的 code,一直會出現問題,一直到把 transformers downgrade 到 4.43.0 才 OK (在某個 downgrad 的過程中出現 linux-npu-driver 需要transformers >= 4.43.0)。
使用太新版會出現 rotary .. error
太舊版光是安裝就會出現 Tokenizer compile error
如果安裝過程出現 openssl-sys error,而系統又有安裝,是因為沒有安裝 pkg-config



另外用 gpu 跑 ollama 的可能參考:


這個方法成功了,又簡單,只是不知道最後是不是成功用 GPU run 了 (還是 run 在 gpu ?) 先依照Installing Client GPU,加入 intel repo. 安裝
sudo apt-get install -y libze-intel-gpu1 libze1 intel-opencl-icd clinfo intel-gsc libze-dev intel-ocloc
然後 download zip,解開就可以 run 了,有一個 script 啟動 ollama server,另外用 ollama 命令就跟平常一樣。
在 ollama server 的 output log 可以看到它有找到 intel GPU,並把一些 layer 交給 GPU.
但是還是一樣很慢...

2025/2/15

modify ollama model for cline

cline 使用 ollama 的話,有些 model 會一直 repeat 說過的話,然後出現Error.例如 deepseek-r1:14b
* cline is having trouble...

Cline uses complex prompts and iterative task execution that 
may be challenging for less capable models. For best results, 
it's recommended to use Claude 3.5 Sonnet for its advanced 
agentic coding capabilities.
這是因為 context windows 不夠大 (default 是 4096)
而 cline 需要很大的 context window.

所以要修改 context window 才行。

ollama 可以用 /parameter 命令來修改。
但是 cline 啟動的 ollama model 沒辦法這樣做。
所以要用 Modelfile 修改 model 的 default config.

ref: 修改 ollama 內的 model 的方法,就寫一個 Modelfile,放進要修改的參數,然後用 ollama command create 一個新 mode.
例如:
$ cat Modelfile-deepseek 
FROM deepseek-r1:14b

PARAMETER num_ctx 32768
然後用 ollama command:
ollama create deepseek-r1:14b-32k -f Modelfile-deepseek
create 完,用 ollama list 就可以看到 deepseek-r1:14b-32k 這個model

cline 改用這個 model,就不會有 Error 了。


但是要注意改num_ctx 改大之後,ollama load model 的 vram 也變大了。
以 deepseek-r1:14b 來看,num_ctx=4090 時,varm 是 10G
換成 num_ctx=32768 之後,vram 是 17G


other ref: num_ctx 是 model 可以記住的token 長度
num_predict 是 model 可以生成的 token 長度

2025/2/10

Transforms.ToTensor( ) 的注意事項

Pytorch 的 transforms.ToTesor()() 會把numpy 換成 tensor.
但是dimension sequence 不一樣.

ToTensor()()假設參數的 numpy array 是從 PILImage 來的,dimension是: H,W,C
ToTensor()()的 output,符合 pytorch 的 sequence, dimemsion 是: C,H,W

所以 經果 ToTensor( ), array 的 order 會被改掉。

所以...一個 400x500 的 jpg...
img = Image.open('image1.jpg')

tensor1 = transforms.ToTenor()(img)
tensor2 = torch.from_numpy(np.array(img))
tensor1 的 dimension sequence 是 [3,400,500]
tensor2 的 dimension sequence 是 [400,500,3]

另外 tensor1 的 dtype 是 float32, tesor2 是 uint8.
而且 tensor1 會做 normalize.

DeepSeek Janus

原來 deepseek-janus pro 有寫好 webui,是用gradio.
就是 clone...
git clone https://github.com/deepseek-ai/Janus.git
然後安裝 requirements.txt

最後啟動 demo/app_januspro.py 或是 demo/app_janusflow.py 就可以。

要注意的是
  • python 要 3.11
  • torch 要改 2.2.2
  • cd Janus && export PATHONPATH=`pwd`
  • 最後啟動的 app_janusXXX.py 在 demo.launch( ) 的 argument,要把 share=True 改成 server_name=0.0.0.0
Gradio 啟動時,share=True的話,會啟動frp,連到外部 proxy.
server_name=0.0.0.0 就是對 public ip,而不只是 127.0.0.1

2025/2/5

ssh connect with X forward in Windows Command console

ref: 首先Windows 要 Run Xserver,一般用 Xming 或是 XcXsrv。
然後在 Windows Command Console 要設定環境變數 DISPLAY
set DISPLAY=127.0.0.1:0.0
實際上後面的意思是
127.0.0.1:display_number.0.
雖然我也不知道 XLauncher 的 display number 是哪個...
可以在windows status bar 上把游標移到 X server 的地方停一下,會顯示 0.0.

然後就可以用 ssh -Y 連線了,因為 Windows 的 ssh client 沒有 -X 選項.
-Y 是 untrust X forward.
-X 是 trusrt X forward.


一定要設完環境變數再連 ssh,不然 ssh 不會設定好連線後, linux 端的環境變數。



要啟動 gnome-terminal的話,ref:Getting gnome-terminal via SSH and Xming,藥用
dbus-launch gnome-terminal



remote X 時,用 python 的 matplotlib.pyplot.show( ) 常常出現問題,
例如會說
libEGL warning: DRI3: failed to query the version
libEGL warning: DRI2: failed to authenticate
libEGL warning: DRI3: failed to query the version
有說明說,在 import matplotlib 後,加上:
matplotlib.use('TkAgg')
就可以。

2025/2/3

Fast RCNN

ref: Fast-RCNN 是一種 2stages 的 object detection network。
  • stage 1 : 把image 經過conv 變成 feature map,再用 RPN 把 feature map 上的region (包含物件的區域) 都找出來
  • stage 2 : 把所有regsion 都從 feature map 上切割出來,辨識它們的種類和位置大小
Stage 1 中,找出物件區域的方法,是 Anchor Box.
自己決定feature map 以每個格點為中心,都有N個 anchor box.
這N個 anchor box 的大小和長寬比例都不一樣。

然後再 feature map 上,針對每個格點上的每個 anchor box,判斷他是哪一個 class,或是都不是,就指定他是 background class。
所以RPN 的輸出是 class 和 regression(box 的 w,h).
然後每個featuer map 的格點都有 N 個 anchor box 對應的 class 和 regbox 值。
class : W, H, anchor_number, 2
Regre : W, H, anchor_numbwe, 4

RoIPool

一直看不懂 RoIPooling 是要做什麼用的。
ref 的那一篇就有說明了。

fast-rcnn 是 2-stages, 先把物件的區域(Region)辨識出來,並且把 feature map 上對應的Region 切出來。
這樣切出來的region 一定大小不一樣。
因為這些區域要經過 stage2,辨識出 class 和 bounding box,這是經果兩個各自的 linear (fc) 層做的。
fc 層的輸入必須是固定大小,
所以剛剛那些 stage 1 辨識出來的 region,都要scale 成同樣大小,符合 fc 的輸入。
這個scale 的方法就叫做 PoIPOOL,不單純用 scale是因為計算方便(?),然後用 maxpooling 一樣的方法,取區域中最大的值。

2025/1/21

CARLA : bounding box

ref: CARLA 裡面的每個物件,都有一個 bounding_box 屬性。

所以就想到,直接用這個屬性來 labeling.
有幾個文章github project 就是這樣做的: 甚至有一篇論文說怎樣可以做出比較準的 2D bounding box: Improve Bounding Box in CARLA simulator

2025/1/20

CARLA : sensor radar

資料內容:

ref: radar sensor point 的資料是:
  • altitude (float – radians) : Altitude angle of the detection.
  • azimuth (float – radians) : Azimuth angle of the detection.
  • depth (float – meters) : Distance from the sensor to the detection position.
  • velocity (float – m/s) : The velocity of the detected object towards the sensor.
但是沒有說坐標系...例如 0 度是在哪 ?

follow unreal engines coordinate system ?
ref:


操作

ref: 有說明,從 raw_data 轉成 上述內容的 sample code:
# To get a numpy [[vel, azimuth, altitude, depth],...[,,,]]:
points = np.frombuffer(radar_data.raw_data, dtype=np.dtype('f4'))
points = np.reshape(points, (len(radar_data), 4))
-- comment 排列方式跟上面的剛好不一樣

PythonAPI/example 中的 manual_control.py 有 G 可以toggle radar point 在畫面上。

2025/1/16

Xorg, VirtualGL and VNC

ref: 在headless server 上,要用 remote desktop 又要使用到 GPU 的話,就要用到這三個。
  • VirtualGL : 把 application 的 OpenGL 呼叫轉送到另一個xserver,並且把這個 xserver render 的結果拿來,交給真正負責application 顯示的 x server
  • Xorg : 負責一個GPU加速功能的 X server
  • TurboVNC : 負責顯示
所以要用 Xorg create 一個使用 GPU (Nvidia) 的 X config.
然後啟動一個 X server

然後啟動 TurboVNC server,這個server 會把畫面畫出來,並且傳給 vncviewer

然後用 vglrun 來啟動 application.


以 CARLA 為例,要在 headless server 上 remote run.

先 create 一個 nvidia 的 Xserver:
$ nvidia-xconfig --query-gpu-info
Number of GPUs: 1

GPU #0:
  Name      : NVIDIA TITAN RTX
  UUID      : GPU-XXXXXXXXXXXX
  PCI BusID : PCI:1:0:0

  Number of Display Devices: 1

  Display Device 0 (TV-6):
      No EDID information available.
看一下 GPU 的 PCI Bus Id.
然後 create 一個 xorg.conf:
$ sudo nvidia-xconfig -a --allow-empty-initial-configuration --use-display-device=None --virtual=1920x1080 --busid=PCI:1:0:0

Using X configuration file: "/etc/X11/xorg.conf".
Option "AllowEmptyInitialConfiguration" "True" added to Screen "Screen0".
Backed up file '/etc/X11/xorg.conf' as '/etc/X11/xorg.conf.backup'
New X configuration file written to '/etc/X11/xorg.conf'
然後因為 nvidia driver 版本大於 440.xx,所以在 xorg.conf 的 Screen 的地方加上:
Option "HardDPMS" "false"



啟動一個 Xserver session,為了讓一班 user 也能啟動 X session,要修改 /etc/X11/Xwrapper.conf,加入下面:
allowed_users=anybody
needs_root_rights=yes
然後 user 要在 tty group 裡。

啟動一個 X session,使用 display number 7

X.Org X Server 1.21.1.11
X Protocol Version 11, Revision 0
Current Operating System: Linux i7-14700 6.8.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Mon May 20 15:51:52 UTC 2024 x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-35-generic root=UUID=e4ea2afe-cc4e-42ce-a53f-5032e417f9f7 ro
xorg-server 2:21.1.12-1ubuntu1.1 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.42.2
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.7.log", Time: Fri Jan 17 05:52:20 2025
(==) Using config file: "/etc/X11/xorg.conf"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
The XKEYBOARD keymap compiler (xkbcomp) reports:
> Warning:          Could not resolve keysym XF86CameraAccessEnable
> Warning:          Could not resolve keysym XF86CameraAccessDisable
> Warning:          Could not resolve keysym XF86CameraAccessToggle
> Warning:          Could not resolve keysym XF86NextElement
> Warning:          Could not resolve keysym XF86PreviousElement
> Warning:          Could not resolve keysym XF86AutopilotEngageToggle
> Warning:          Could not resolve keysym XF86MarkWaypoint
> Warning:          Could not resolve keysym XF86Sos
> Warning:          Could not resolve keysym XF86NavChart
> Warning:          Could not resolve keysym XF86FishingChart
> Warning:          Could not resolve keysym XF86SingleRangeRadar
> Warning:          Could not resolve keysym XF86DualRangeRadar
> Warning:          Could not resolve keysym XF86RadarOverlay
> Warning:          Could not resolve keysym XF86TraditionalSonar
> Warning:          Could not resolve keysym XF86ClearvuSonar
> Warning:          Could not resolve keysym XF86SidevuSonar
> Warning:          Could not resolve keysym XF86NavInfo
Errors from xkbcomp are not fatal to the X server



啟動 Turbovnc 的 vnc server,負責 application 的 display,用 8 作為 display number:
$ /opt/TurboVNC/bin/vncserver :8

Desktop 'TurboVNC: i7-14700:8 (charles-chang)' started on display i7-14700:8

Starting applications specified in /opt/TurboVNC/bin/xstartup.turbovnc
Log file is /home/charles/.vnc/i7-14700:8.log
如果是第一次啟動,會要求給一個 vncviewer 用的 password.

vnc server 啟動之後,其他pc 就可以透過 viewer 來顯示 vncserver 的內容。
vncserver 的 service port 是 5900+display numner,
也就是說,剛剛的設定,service port 是 5908


之後就可以用 vglrun 來執行 application,讓執行程式使用 virtualgl 提供的 opengl 服務,並且經由 DISPLAY 變數傳送render 的結果:
~$ DISPLAY=:8 vglrun -d :7 glxgears
先指定DISPLAY環境變數是:8 (VNCSERVER),然後用 "-d :7" 指定 opengl rendering 交給 display :7 (nvidia X session) 負責。

2025/1/15

MESA-LOADER: failed to open iris

ref:
先是...
MESA-LOADER: failed to open iris: /usr/lib/dri/iris_dri.so: cannot open shared object file: 
No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load driver: iris
MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: 
No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  167
  Current serial number in output stream:  168
所以參考上面的 ref,去看 /usr/lib 下果然沒有 dri 目錄。所以把安裝位置 ln 過來...
sudo apt --reinstall install libgl1-mesa-dri
cd /usr/lib
sudo ln -s x86_64-linux-gnu/dri ./dri
然後 Error:
MESA-LOADER: failed to open iris: /home/charles/miniconda3/envs/carla/bin/../lib/libstdc++.so.6: 
version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libLLVM-17.so.1) 
(search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load driver: iris
MESA-LOADER: failed to open swrast: /home/charles/miniconda3/envs/carla/bin/../lib/libstdc++.so.6: 
version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libLLVM-17.so.1) 
(search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
X Error of failed request:  BadValue (integer parameter out of range for operation)
所以看一下 conda 系統的 libstdc++.so.6 的 GLIBCXX 支援版本有:
$ strings /home/charles/miniconda3/lib/libstdc++.so.6 | grep ^GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
...
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_DEBUG_MESSAGE_LENGTH
GLIBCXX_3.4.21
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.16
GLIBCXX_3.4.1
...
GLIBCXX_3.4.4
GLIBCXX_3.4.26
果然沒有 3.4.30

因為是 libstdc++.so.6.0.29
系統的 /usr/lib/x86-linux-gnu/libstdc++.so 是 6.0.33

所以把 /usr/lib/x86_64-linux-gnu/ 的 6.0.33 copy 到 env 的 lib,然後重新 ln libstdc++.so.6 到 libstdc++.so.6.0.33 就可以了。

md file, markdown reader in linux console

bat

有在 ubuntu 的 apt repo 里,所以用 apt install bat 就可以。
但是command 是 batcat,
他是希望跟 cat 一樣的用法。

install 完後,因為它支援 theme,所以default theme不喜歡的話,就要產生一個 config,然後改 default theme.
$ batcat --generate-config-file
Success! Config file written to /home/charles/.config/bat/config
然後去修改 ~/.config/bat/config
-- #--theme="TwoDark"
++ --theme="GitHub"
default theme 是給 darkmode用的。bright mode 可以用 "GitHub" 這個 theme.

使用方法就跟 cat 一樣:
batcat README.md



batcat 不太好用,markdown 語法沒有render的很好,有些還是 raw output,
所以用 mdcat 試試看。
是用 rust 寫的,apt 還沒有。
所以要clone 下來 build

跟 batcat 比起來是 render 多一點 markdown 語法了。



update : 最後還是去裝 chrome 的 extension : markdown viewer

2025/1/14

Carla : Install and run on Linux

網站說明有latest, stable, 0.9.15 ...etc,但是github 的 Download 只有 0.9.15,所以猜 latest 也是 0.9.15 (?)
github Download page 還有 nightly build,說明包含 bugfix 和 new feature,所以猜是 unstable.

Download CARLA_0.9.15.tar.gz,解開會有多目錄,所以在一個目錄中解開比較好。

從 Quick start package installation : Install Client Library
使用 tar.gz 檔安裝,PythonAPI/carla/dist 中有需要的 python packages file : *.whl
提供的 python version 是 : cp37,所以 carla-0.9.15 的 python 版本應該是 python3.7

這個folder 提供的對應 whl 檔,跟用 pip install carla 安裝的檔案相同。
使用的是 carla-0.9.15-cp37-cp37m-manylinux_2_27_x86_64.whl

除此之外,還要install pygame 和 numpy 兩個 package,就可以開始 run :
文件說明是
./CarlaUE4.sh
結果發現沒有使用 GPU,參考cannot run Carla using nvidia GPU under Linux with multi-GPU installed : PRIME instruction ignored by Carla #4716
加上 option
./CarlaUE4.sh -prefernvidia
就可以了。


從主網站 carla.org 進入可以看到release 0.10.0的說明。
0.10.0 的 python 版本不同了。

一樣從whl的檔名來看,0.10.0 的 python 版本應該是 3.10
一樣解開download 的 0.10.0 (這次是zip檔),到 PythonAPI/carla 安裝 requirement.txt,再裝 dist/*.whl,之後就可以啟動:
./CarlaUnreal.sh 
0.10.0 不用家 -prefernvidia,就會用 GPU了。

0.10.0 vRAM用到 8G以上,使用 RTX4070,移動鏡頭快一點就會出現 vulkan out of memory Error.


carla script 啟動的是 server,控制的化,可以參考 Python_API/Example 下的 python code.
在server running 的情況下, run 這些 python code 就可以調整carla 的內容。

在啟動 automatic_control.py 時出現 mesa load iris error.依照這一篇 解決。


ref:
run on server without display

可以 run carla server 在遠端,然後 client 才顯示出來。
.CarlaUE4.sh -prefernvidia -RenderOffScreen



carla 是一個 server ,其他 client 用 socket api 控制,就像遊戲的 server 一樣,
carla server 只對 localhost 開放,所以遠端無法控制。

使用現有的 python script 就可以操作。每個 script 都要獨立 run,所以用 & 到背景,不然就要每個都開一個 console.
  • 先把 carla run 起來,可以不show 出來 . (-RenderOffScreen)
  • 加入一些車流 : generate_traffic.py
  • 自動改變天氣 : dynamic_weathre.py
  • 開啟開車控制: manual_control.py,這時候才會出現畫面
  • 控制環境 (車燈,路燈...) : util/environment.py
要所有的車把車燈打開:
python environment.py --cars LowBeam All



這個 韓國人寫的,從頭開始寫 python code 控制 CARLA 也不錯,很清楚。



Docker

ubuntu 24.04 直接 run carla 0.9.15 的話,使用 vulkan 會出現 memory allocation error,使用 -prefernvidia 的話,run 一陣子就會自動 hang 住。
所以還是用 docker 來 run。
docker imagge 要用 carlasim 的 : carlasim/carla:0.9.15,latest 的更新比 0.9.15 還舊,所以用 0.9.15
要使用 nvidia 的話,就要用 --gpus all,這樣就要安裝 nvidia-toolkit:
sudo apt install nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
這樣docker 的 --cpus all 才會有作用。

啟動 carla docker 的command 是:
docker run --privileged --gpus all --net=host -e DISPLAY=$DISPLAY carlasim/carla:0.9.15 /bin/bash ./CarlaUE4.sh
啟動了之後,因為 --net=host,所以要 run PythonAPI/examples 下的 code 都一樣。
docker 改用 -it 刪掉 ./CarlaUE4.sh,進入 bash 看, 是 Ubuntu 18.04.3...