Proxmox / Debian 12 LXC / CodeProject.ai / Coral usb TPU

To assist others who may struggle with setup, I’ve documented my experience transitioning from a Docker-based configuration to a more stable manual installation of Debian 12 in an LXC container for use with a Coral TPU. The previous method using Proxmox, LXC, Docker, and Codeproject was unreliable and had a lengthy boot process, which was not ideal for AI detection tasks with Blue Iris. Here are the steps I followed for a successful setup.

Installation Steps

Proxmox Host Configuration

  1. Create the Container’s Root Group:

    groupadd -g 100000 Codeproject
    
  2. Set Up Udev Rules for Coral TPU:
    Create a file named 60-coraltpu.rules in /etc/udev/rules.d/ and add the following lines:

    SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", GROUP="100000"
    SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", GROUP="100000"
    

LXC Container Creation

  • Create an Unprivileged LXC Container:
    • Use Debian 12 with 4 CPU cores and 4 GB RAM (initially required for installation; resources can be adjusted later).
  • Configure Networking as Needed.

Identify the Coral TPU Device

  • On the Proxmox host, run:
    lsusb
    
    This command will help identify the bus number of your Coral device (e.g., Bus 004 Device 002: ID 18d1:9302 Google Inc.).

Modify LXC Configuration

  • Edit the LXC configuration file to include the USB device:
    nano /etc/pve/lxc/<lxcid>.conf
    
    Add these lines, replacing <BUS_ID> with your actual bus ID:
    usb0: host=1a6e:089a,usb4=1 # coral ID pre-load
    usb1: host=18d1:9302,usb4=1 # coral ID post-load
    lxc.mount.entry: /dev/bus/usb/<BUS_ID> dev/bus/usb/<BUS_ID> none bind,optional,create=dir
    

Inside the Container

  1. Enable SSH Access:
    Modify the SSH configuration to allow root login:

    sed -i /"^PermitRootLogin.*$"/d /etc/ssh/sshd_config
    echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
    systemctl restart sshd
    
  2. Retrieve the Container’s IP Address:

    ip -c -4 -brief address show
    
  3. Install Required Packages:
    Download and install Microsoft package repository:

    wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb
    apt update && apt upgrade
    apt install unzip dotnet-sdk-7.0 sudo psmisc curl xz-utils jq
    
  4. Install Codeproject AI Server:
    Download and unpack the Codeproject AI server:

    wget https://www.codeproject.com/KB/Articles/5322557/codeproject.ai-server_2.6.5_Ubuntu_x64.zip
    unzip codeproject.ai-server_2.6.5_Ubuntu_x64.zip
    rm codeproject.ai-server_2.6.5_Ubuntu_x64.zip
    dpkg -i codeproject.ai-server_2.6.5_Ubuntu_x64.deb
    rm codeproject.ai-server_2.6.5_Ubuntu_x64.deb
    
    pushd "/usr/bin/codeproject.ai-server-2.6.5/" && bash start.sh && popd
    cd /usr/bin/codeproject.ai-server-2.6.5 && bash start.sh
    
  5. Monitor Installation Logs:
    Check logs in your browser until installation completes; you may need to terminate the process in your SSH session once it appears stalled.

  6. Install Coral Module:
    Navigate to the module directory and run the setup script:

    cd /usr/bin/codeproject.ai-server-2.6.5/modules/ObjectDetectionCoral && sudo bash ../../setup.sh
    
  7. Enable Services:
    Enable the Codeproject AI server service:

    systemctl enable codeproject.ai-server
    
  8. Set Coral Module to Autostart:
    Edit modulesettings.json to set autostart value to true:

    nano /usr/bin/codeproject.ai-server-2.6.5/modules/ObjectDetectionCoral/modulesettings.json
    
  9. Reboot and Test:
    After rebooting, you should experience no disconnection issues that were present with Docker.

Performance Outcome

With this setup, I achieved a response time of approximately 29ms for detecting tiny objects, demonstrating significant improvement over previous configurations that utilized Docker.

This streamlined approach not only enhances reliability but also reduces latency issues associated with Docker setups, making it an effective solution for AI detection tasks using Coral TPUs in Proxmox environments.

If you start vanila without a gpu or tpu and get the error below.

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

you can try this

apt install libgl1-mesa-dev
cd /usr/bin/codeproject.ai-server-2.6.5/modules/ObjectDetectionYOLOv5-6.2 && sudo bash ../../setup.sh