### Install YOLOX from Source Source: https://github.com/megvii-basedetection/yolox/blob/main/README.md Clone the YOLOX repository and install it using pip. This is the initial setup step for using YOLOX. ```shell git clone git@github.com:Megvii-BaseDetection/YOLOX.git cd YOLOX pip3 install -v -e . # or python3 setup.py develop ``` -------------------------------- ### Install nebullvm Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/nebullvm/README.md Install the nebullvm library using pip. This is the simplest way to get started. ```bash pip install nebullvm ``` -------------------------------- ### Install YOLOX from Source Source: https://context7.com/megvii-basedetection/yolox/llms.txt Clone the repository and install YOLOX in editable mode. Includes verification of the installation. ```bash git clone git@github.com:Megvii-BaseDetection/YOLOX.git cd YOLOX pip3 install -v -e . python -c "import yolox; print(yolox.__version__)" ``` -------------------------------- ### Install ONNX Runtime Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/ONNXRuntime/README.md Install the ONNX Runtime library using pip. This is the first step before running any ONNX-based demos. ```shell pip install onnxruntime ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/CMakeLists.txt Initializes the CMake project and sets the C++ standard and build type. ```cmake cmake_minimum_required(VERSION 2.6) project(yolox) add_definitions(-std=c++11) option(CUDA_USE_STATIC_CUDA_RUNTIME OFF) set(CMAKE_CXX_STANDARD 11) set(CMAKE_BUILD_TYPE Debug) ``` -------------------------------- ### YOLOX C++ Demo Usage Example Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/README.md Alternative command-line arguments for specifying the engine file and input image paths. ```shell ./yolox -i ``` -------------------------------- ### Start MLFlow Tracking Server Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/mlflow_integration.md Start a local MLFlow tracking server to log and visualize experiments. Ensure the server is accessible. ```bash mlflow server --host 127.0.0.1 --port 8080 ``` -------------------------------- ### Prepare MegEngine Third-Party Dependencies Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md After cloning MegEngine, initialize and install its third-party dependencies, including MKL for optimized math operations. ```shell export megengine_root="path of MegEngine" cd $megengine_root && ./third_party/prepare.sh && ./third_party/install-mkl.sh ``` -------------------------------- ### Start MLFlow UI Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/mlflow_integration.md Launch the MLFlow UI to visualize logged experiments. Access it via your browser at the specified port. ```bash mlflow ui --port 5000 ``` -------------------------------- ### Install MegEngine Requirements Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/python/README.md Install the MegEngine library using pip. Ensure you use the correct index URL for MegEngine wheels. ```bash python3 -m pip install megengine -f https://megengine.org.cn/whl/mge.html ``` -------------------------------- ### Example: YOLOX-S VOC Training Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/train_custom_data.md This command demonstrates training the YOLOX-S model on a VOC dataset, using specified experiment files and pretrained weights. ```bash python tools/train.py -f exps/example/yolox_voc/yolox_voc_s.py -d 8 -b 64 --fp16 -o -c /path/to/yolox_s.pth [--cache] ``` -------------------------------- ### Install Databricks SDK Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/mlflow_integration.md Install the Databricks SDK for Python using pip to enable integration with Databricks MLFlow. ```bash pip install databricks-sdk ``` -------------------------------- ### Install MLFlow and python-dotenv Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/mlflow_integration.md Install the necessary libraries for MLFlow integration using pip. ```bash pip install mlflow python-dotenv ``` -------------------------------- ### Install YOLOX and Dependencies Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/quick_run.md Clone the YOLOX repository and install the necessary Python packages, including pycocotools. ```shell git clone git@github.com:Megvii-BaseDetection/YOLOX.git cd YOLOX pip3 install -U pip && pip3 install -r requirements.txt pip3 install -v -e . # or python3 setup.py develop ``` ```shell pip3 install cython; pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' ``` -------------------------------- ### Export MegEngine Install Path (Host With CUDA) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Set the MGE_INSTALL_PATH environment variable for a host build with CUDA, pointing to the installed inference-only release. ```shell export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_ON/Release/install ``` -------------------------------- ### Example: Training with mini-coco128 Dataset Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/train_custom_data.md This command shows how to train using the mini-coco128 dataset after downloading and unzipping it to the 'datasets' directory. It uses a specific experiment file and pretrained weights. ```bash python tools/train.py -f exps/example/custom/yolox_s.py -d 8 -b 64 --fp16 -o -c /path/to/yolox_s.pth ``` -------------------------------- ### Export MegEngine Install Path (Host No CUDA) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Set the MGE_INSTALL_PATH environment variable for a host build without CUDA, pointing to the installed inference-only release. ```shell export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_ON/Release/install ``` -------------------------------- ### Set up OpenVINO Environment Permanently (Linux) Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/cpp/README.md Permanently configures the OpenVINO environment by adding the setup script to the bashrc file. Requires sourcing bashrc after modification. ```shell vim ~/.bashrc ``` ```shell source /opt/intel/openvino_2021/bin/setupvars.sh ``` ```shell source ~/.bashrc ``` -------------------------------- ### Configure Weights & Biases Logging Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/quick_run.md Install and log in to Weights & Biases to enable logging of training metrics. Add the --logger wandb flag to the training command. ```shell pip install wandb wandb login ``` ```shell python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o [--cache] --logger wandb wandb-project yolox-m yolox-l yolox-x ``` ```shell python tools/train.py .... --logger wandb wandb-project \ wandb-name \ wandb-id \ wandb-save_dir \ wandb-num_eval_images \ wandb-log_checkpoints ``` -------------------------------- ### Multi-Machine Training Setup Source: https://github.com/megvii-basedetection/yolox/blob/main/README.md Configure and launch YOLOX training across multiple machines. Specify the total number of machines and the rank of the current node, along with the distributed training URL. ```shell python tools/train.py -n yolox-s -b 128 --dist-url tcp://123.123.123.123:12312 --num_machines 2 --machine_rank 0 ``` ```shell python tools/train.py -n yolox-s -b 128 --dist-url tcp://123.123.123.123:12312 --num_machines 2 --machine_rank 1 ``` -------------------------------- ### Set MegEngine Installation Path Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Export the `MGE_INSTALL_PATH` environment variable to point to the MegEngine installation directory. The exact path depends on the build configuration (host/CUDA/Android). ```shell # host without cuda: export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_ON/Release/install # or host with cuda: export MGE_INSTALL_PATH=${megengine_root}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_ON/Release/install # or cross build for android aarch64: export MGE_INSTALL_PATH=${megengine_root}/build_dir/android/arm64-v8a/Release/install ``` -------------------------------- ### Export MegEngine Install Path (Android AArch64) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Set the MGE_INSTALL_PATH environment variable for a cross-compiled Android AArch64 build, pointing to the installed release. ```shell export MGE_INSTALL_PATH=${megengine_root}/build_dir/android/arm64-v8a/Release/install ``` -------------------------------- ### Build YOLOX C++ Demo Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/README.md Standard CMake build process for the YOLOX C++ demo. Ensure TensorRT and OpenCV are installed. ```shell mkdir build cd build cmake .. make ``` -------------------------------- ### Get YOLOX Training Help Source: https://github.com/megvii-basedetection/yolox/blob/main/README.md Display the help message for the YOLOX training script to see all available command-line arguments and options. ```shell python -m yolox.tools.train --help ``` -------------------------------- ### Distributed Training Launcher with `launch` Source: https://context7.com/megvii-basedetection/yolox/llms.txt Launches distributed training across multiple GPUs or machines. It automatically handles port discovery, process group initialization, and rank assignment. Ensure `num_gpus_per_machine` and `num_machines` are set correctly for your hardware setup. ```python from yolox.core import launch from yolox.exp import get_exp, check_exp_value def train_worker(exp, args): trainer = exp.get_trainer(args) trainer.train() exp = get_exp(None, "yolox-s") check_exp_value(exp) # Simulated args namespace class Args: experiment_name = "yolox_s_coco" fp16 = True cache = None occupy = False logger = "tensorboard" resume = False ckpt = None start_epoch = None opts = [] # Launch on 4 GPUs on a single machine launch( main_func=train_worker, num_gpus_per_machine=4, num_machines=1, machine_rank=0, backend="nccl", dist_url="auto", # auto-selects a free port on localhost args=(exp, Args()), ) ``` -------------------------------- ### Build OpenCV for Host Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Compile OpenCV for the host system. This command configures CMake with installation prefix and builds the libraries. ```shell cd root_dir_of_opencv mkdir -p build/install cd build cmake -DBUILD_JAVA=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$PWD/install make install -j32 ``` -------------------------------- ### OpenCV Integration Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/CMakeLists.txt Finds and includes directories for OpenCV. Ensure OpenCV is installed and discoverable by CMake. ```cmake find_package(OpenCV) include_directories(${OpenCV_INCLUDE_DIRS}) ``` -------------------------------- ### Set OpenCV Installation Paths Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Export environment variables for OpenCV include and library paths. The paths differ based on whether OpenCV was built for host or Android. ```shell # host build: export OPENCV_INSTALL_INCLUDE_PATH=${path of opencv}/build/install/include export OPENCV_INSTALL_LIB_PATH=${path of opencv}/build/install/lib # or cross build for android aarch64: export OPENCV_INSTALL_INCLUDE_PATH=${path of opencv}/build_android/install/sdk/native/jni/include export OPENCV_INSTALL_LIB_PATH=${path of opencv}/build_android/install/sdk/native/libs/arm64-v8a ``` -------------------------------- ### Convert Customized YOLOX Model with Specific Exp File Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/trt_py_readme.md Example of converting a customized YOLOX model using a specific experiment file path. The converted model and engine file will be saved to your experiment output directory. ```shell python tools/trt.py -f /path/to/your/yolox/exps/yolox_s.py -c your_ckpt.pth ``` -------------------------------- ### Display Training Help Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/freeze_module.md Run the training command with the `--help` flag to view detailed information and available options for training. ```bash python3 -m yolox.tools.train --help ``` -------------------------------- ### Prepare and Run YOLOX Demo (Android) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Transfer necessary files (libraries, executable, model, image) to the Android device and then execute the YOLOX demo. The command includes parameters for warmup, threading, fast run, weight preprocessing, and FP16 usage. ```shell # adb push/scp $MGE_INSTALL_PATH/lib/libmegengine.so android_phone # adb push/scp $OPENCV_INSTALL_LIB_PATH/*.so android_phone # adb push/scp ./yolox yolox_s.mge android_phone # adb push/scp ../../../assets/dog.jpg android_phone # login in android_phone by adb or ssh # then run: LD_LIBRARY_PATH=. ./yolox yolox_s.mge dog.jpg cpu/multithread # * means warmup count, valid number >=0 ``` -------------------------------- ### Build YOLOX Demo (Host) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Compile the YOLOX demo for the host system. Ensure the CXX environment variable is set to g++. ```shell export CXX=g++ ./build.sh ``` -------------------------------- ### Run YOLOX-OpenVINO C++ Demo Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/cpp/README.md Executes the compiled YOLOX-OpenVINO C++ demo. Requires paths to the OpenVINO IR model files and an input image, along with the target device. ```shell ./yolox_openvino ``` -------------------------------- ### Clone and Prepare MegEngine Repository Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Clone the MegEngine repository and prepare its third-party dependencies. Ensure the `megengine_root` environment variable is set. ```shell git clone https://github.com/MegEngine/MegEngine.git # then init third_party export megengine_root="path of MegEngine" cd $megengine_root && ./third_party/prepare.sh && ./third_party/install-mkl.sh ``` -------------------------------- ### Build YOLOX-OpenVINO C++ Demo (Linux) Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/cpp/README.md Builds the YOLOX-OpenVINO C++ demo application using CMake and Make. Assumes OpenVINO environment is already set up. ```shell source /opt/intel/openvino_2021/bin/setupvars.sh ``` ```shell mkdir build ``` ```shell cd build ``` ```shell cmake .. ``` ```shell make ``` -------------------------------- ### Convert YOLOX-S Model to TensorRT Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/trt_py_readme.md Example of converting the yolox-s model to TensorRT format. Ensure you have the correct checkpoint file. ```shell python tools/trt.py -n yolox-s -c your_ckpt.pth ``` -------------------------------- ### Set up OpenVINO Environment (Linux) Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/cpp/README.md Temporarily sets up the OpenVINO environment for the current shell session. This command needs to be run every time a new shell is opened. ```shell source /opt/intel/openvino_2021/bin/setupvars.sh ``` -------------------------------- ### Run YOLOX Demo on Host Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Execute the YOLOX C++ demo on the host machine. Ensure `LD_LIBRARY_PATH` includes MegEngine and OpenCV libraries. Specify the model, image, device (CUDA/CPU), warmup count, and thread number. ```shell LD_LIBRARY_PATH=$MGE_INSTALL_PATH/lib/:$OPENCV_INSTALL_LIB_PATH ./yolox yolox_s.mge ../../../assets/dog.jpg cuda/cpu/multithread ``` -------------------------------- ### Run YOLOX C++ Demo Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/README.md Execute the compiled YOLOX demo with the serialized engine file and an input image. ```shell ./yolox ../model_trt.engine -i ../../../../assets/dog.jpg ``` -------------------------------- ### Build MegEngine for Host (with CUDA) Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Build MegEngine for host compilation with CUDA support enabled. This is for systems with NVIDIA GPUs. ```shell ./scripts/cmake-build/host_build.sh -c ``` -------------------------------- ### Configure YOLOX OpenVINO Demo Build Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/cpp/CMakeLists.txt Sets the minimum CMake version, C++ standard, project name, and finds necessary packages like OpenCV, Inference Engine, and ngraph. It then includes directories and links libraries for the executable. ```cmake cmake_minimum_required(VERSION 3.4.1) set(CMAKE_CXX_STANDARD 14) project(yolox_openvino_demo) find_package(OpenCV REQUIRED) find_package(InferenceEngine REQUIRED) find_package(ngraph REQUIRED) include_directories( ${OpenCV_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) add_executable(yolox_openvino yolox_openvino.cpp) target_link_libraries( yolox_openvino ${InferenceEngine_LIBRARIES} ${NGRAPH_LIBRARIES} ${OpenCV_LIBS} ) ``` -------------------------------- ### Convert YOLOX Model to TensorRT Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/python/README.md Use this command to convert a YOLOX model to TensorRT format. Specify the model name and checkpoint path. Ensure TensorRT and torch2trt are installed. ```shell python tools/trt.py -n -c ``` ```shell python tools/trt.py -n yolox-s -c your_ckpt.pth ``` -------------------------------- ### Navigate to ONNXRuntime Demo Directory Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/ONNXRuntime/README.md Change the current directory to the ONNXRuntime demo folder within the YOLOX project. ```shell cd /demo/ONNXRuntime ``` -------------------------------- ### YOLOX Inference Demo Usage Source: https://context7.com/megvii-basedetection/yolox/llms.txt Command-line usage for `tools/demo.py` to run object detection on images, video files, or live webcam streams. Results can be saved to disk. ```bash # Example usage for demo.py would go here, but is not provided in the source text. ``` -------------------------------- ### Load YOLOX Experiment by Name or File Source: https://context7.com/megvii-basedetection/yolox/llms.txt Use `get_exp` to load configurations from built-in names or custom files. Individual fields can be overridden using key=value pairs. ```python from yolox.exp import get_exp # By built-in name (resolves to yolox/exp/default/yolox_s.py) exp = get_exp(exp_file=None, exp_name="yolox-s") print(exp.depth, exp.width, exp.num_classes) # 0.33 0.5 80 # By custom experiment file exp = get_exp(exp_file="exps/example/yolox_voc/yolox_voc_s.py", exp_name=None) # Override individual fields from CLI-style key=value pairs exp.merge(["num_classes", "20", "max_epoch", "50"]) print(exp.num_classes, exp.max_epoch) # 20 50 # Validate that input size is divisible by 32 from yolox.exp import check_exp_value check_exp_value(exp) # raises AssertionError if input_size is not multiples of 32 ``` -------------------------------- ### Experiment Configuration Class (`Exp`) Source: https://context7.com/megvii-basedetection/yolox/llms.txt The `Exp` class is the central configuration object for YOLOX experiments. Subclassing `BaseExp` allows customization of model, data, augmentation, and training hyperparameters. The example shows how to define a custom experiment for a dataset with 5 classes. ```APIDOC ## `Exp` — Experiment Configuration Class The `Exp` class (subclassing `BaseExp`) is the central configuration object. It unifies all model, data, and training hyperparameters and exposes factory methods (`get_model`, `get_dataset`, `get_data_loader`, `get_optimizer`, `get_lr_scheduler`, `get_evaluator`, `get_trainer`) to build every component of the training pipeline. Subclass it to create custom experiments. ```python # exps/example/custom/yolox_s_custom.py import os from yolox.exp import Exp as MyExp class Exp(MyExp): def __init__(self): super(Exp, self).__init__() # Model: YOLOX-S size factors self.num_classes = 5 # custom dataset has 5 classes self.depth = 0.33 self.width = 0.50 self.act = "silu" # Data self.data_dir = "datasets/my_dataset" self.train_ann = "instances_train.json" self.val_ann = "instances_val.json" self.input_size = (640, 640) # Augmentation self.mosaic_prob = 1.0 self.mixup_prob = 0.5 self.enable_mixup = True self.degrees = 10.0 self.translate = 0.1 self.shear = 2.0 # Training self.max_epoch = 100 self.warmup_epochs = 3 self.no_aug_epochs = 10 self.basic_lr_per_img = 0.01 / 64.0 self.min_lr_ratio = 0.05 self.ema = True self.weight_decay = 5e-4 # Evaluation self.test_conf = 0.01 self.nmsthre = 0.65 self.exp_name = os.path.splitext(os.path.basename(__file__))[0] # Instantiate and inspect the experiment configuration exp = Exp() print(repr(exp)) # pretty-printed table of all hyperparameters ``` ``` -------------------------------- ### Run YOLOX Video Demo Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/quick_run.md Perform inference on a video file using a specified YOLOX model. Ensure the path to the video and model weights are correct. ```shell python tools/demo.py video -n yolox-s -c /path/to/your/yolox_s.pth --path /path/to/your/video --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu] ``` -------------------------------- ### Clone MegEngine Repository Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Clone the MegEngine repository to your local machine. This is the first step before preparing third-party dependencies. ```shell git clone https://github.com/MegEngine/MegEngine.git ``` -------------------------------- ### Import Experiment Configuration Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/freeze_module.md Import the desired experiment configuration or define your own by inheriting from `yolox.exp.BaseExp`. ```python from yolox.exp.default.yolox_s import Exp as MyExp ``` -------------------------------- ### Run YOLOX Demo on Android Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Transfer necessary files (libraries, executable, model, image) to the Android device and run the demo. The command arguments include model, image, device, warmup count, thread number, fast run, weight preprocess, and FP16 usage. ```shell # if cross android adb push/scp $MGE_INSTALL_PATH/lib/libmegengine.so android_phone # Push OpenCV libraries (adjust path as needed) # Example for aarch64: # adb push/scp $OPENCV_INSTALL_LIB_PATH/*.so android_phone # Push YOLOX executable and model adb push/scp ./yolox yolox_s.mge android_phone # Push image adb push/scp ../../../assets/dog.jpg android_phone # login in android_phone by adb or ssh # then run: LD_LIBRARY_PATH=. ./yolox yolox_s.mge dog.jpg cpu/multithread # * means warmup count, valid number >=0 ``` -------------------------------- ### Compile YOLOX Demo Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Compile the YOLOX C++ demo using the provided `build.sh` script. Set the `CXX` environment variable to the appropriate compiler for host or cross-compilation. ```shell run build.sh # if host: export CXX=g++ ./build.sh # or cross android aarch64 export CXX=aarch64-linux-android21-clang++ ./build.sh ``` -------------------------------- ### Build YOLOX Demo (Android AArch64) Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/demo/megengine_cpp_readme.md Compile the YOLOX demo for Android AArch64 using cross-compilation. Set the CXX environment variable to the appropriate clang++ compiler. ```shell export CXX=aarch64-linux-android21-clang++ ./build.sh ``` -------------------------------- ### Logging Training to Weights & Biases Source: https://github.com/megvii-basedetection/yolox/blob/main/README.md Enable logging of training metrics, predictions, and checkpoints to Weights & Biases. Use the `--logger wandb` argument and specify W&B project details. ```shell python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o [--cache] --logger wandb wandb-project yolox-m yolox-l yolox-x ``` -------------------------------- ### Convert Torch Checkpoint Weights Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/python/README.md Convert PyTorch model weights to MegEngine's pickle format using the provided conversion script. Specify the input PyTorch weights file and the desired output MegEngine pickle file. ```bash python3 convert_weights.py -w yolox_s.pth -o yolox_s_mge.pkl ``` -------------------------------- ### Run OpenVINO Inference with Python Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/OpenVINO/python/README.md Execute the OpenVINO inference script with the converted OpenVINO model and an input image. Optional arguments include output directory, score threshold, and target device. ```shell python openvino_inference.py -m -i ``` ```shell python openvino_inference.py -m -i -o -s -d ``` -------------------------------- ### Run YOLOX Inference on Images, Videos, and Webcam Source: https://context7.com/megvii-basedetection/yolox/llms.txt Use `tools/demo.py` for inference. Specify input type (image, video, webcam), model configuration, weights, and path. Optional arguments include confidence threshold, NMS threshold, input size, and device. ```bash python tools/demo.py image \ -n yolox-s \ -c yolox_s.pth \ --path assets/dog.jpg \ --conf 0.25 --nms 0.45 --tsize 640 \ --save_result --device gpu ``` ```bash python tools/demo.py image \ -f exps/default/yolox_m.py \ -c yolox_m.pth \ --path /data/images/ \ --conf 0.3 --nms 0.45 --tsize 640 \ --save_result --device gpu ``` ```bash python tools/demo.py video \ -n yolox-l -c yolox_l.pth \ --path /data/video.mp4 \ --conf 0.25 --nms 0.45 \ --save_result --device gpu ``` ```bash python tools/demo.py webcam \ -n yolox-s -c yolox_s.pth \ --camid 0 --conf 0.3 ``` -------------------------------- ### Executable Build and Linking Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/cpp/CMakeLists.txt Defines the main executable and links it against required libraries including nvinfer, cudart, and OpenCV. ```cmake add_executable(yolox ${PROJECT_SOURCE_DIR}/yolox.cpp) target_link_libraries(yolox nvinfer) target_link_libraries(yolox cudart) target_link_libraries(yolox ${OpenCV_LIBS}) ``` -------------------------------- ### Build MegEngine for Host (without CUDA) Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/cpp/README.md Build MegEngine for host compilation without CUDA support. This command generates the necessary libraries for inference. ```shell ./scripts/cmake-build/host_build.sh ``` -------------------------------- ### Multi-Node Training Configuration Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/quick_run.md Configure multi-node training by specifying the total number of machines and the rank of the current node. ```shell python tools/train.py --num_machines --machine_rank ... ``` -------------------------------- ### Use Legacy Weights for Demo and Evaluation Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/updates_note.md Add the `--legacy` flag when running demo or evaluation scripts if you need to use older, incompatible weights due to removed normalization operations. ```shell python tools/demo.py image -n yolox-s -c /path/to/your/yolox_s.pth --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device [cpu/gpu] [--legacy] ``` ```shell python tools/eval.py -n yolox-s -c yolox_s.pth -b 64 -d 8 --conf 0.001 [--fp16] [--fuse] [--legacy] yolox-m yolox-l yolox-x ``` -------------------------------- ### Build YOLOX Model from Experiment Source: https://context7.com/megvii-basedetection/yolox/llms.txt Construct the YOLOX model using `exp.get_model()`. This returns an `nn.Module` ready for training. Includes checking parameter count and loading pretrained weights. ```python import torch from yolox.exp import get_exp exp = get_exp(None, "yolox-s") model = exp.get_model() # Returns a YOLOX nn. Module ready for training print(model) # Check parameter count and GFLOPs from yolox.utils import get_model_info info = get_model_info(model, exp.test_size) print(info) # "Params: 8.97M, Gflops: 26.81" # Load pretrained weights ckpt = torch.load("yolox_s.pth", map_location="cpu") model.load_state_dict(ckpt["model"]) model.eval() ``` -------------------------------- ### YOLOX Training Script Commands Source: https://context7.com/megvii-basedetection/yolox/llms.txt Command-line arguments for the `tools/train.py` script to initiate single- or multi-GPU distributed training. Options include specifying experiment files, batch size, number of devices, FP16, and caching. ```bash # Single-GPU training with YOLOX-S on COCO (8 GPUs recommended) python tools/train.py -n yolox-s -d 1 -b 8 --fp16 # Multi-GPU training (8 GPUs, batch=64) python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o # Custom exp file with pretrained init and RAM caching python tools/train.py \ -f exps/example/yolox_voc/yolox_voc_s.py \ -d 4 -b 32 --fp16 -o \ -c yolox_s.pth \ --cache ram # Multi-machine training (run on each machine) # Master: python tools/train.py -n yolox-s -b 128 \ --dist-url tcp://192.168.1.1:12312 \ --num_machines 2 --machine_rank 0 # Worker: python tools/train.py -n yolox-s -b 128 \ --dist-url tcp://192.168.1.1:12312 \ --num_machines 2 --machine_rank 1 # With Weights & Biases logging python tools/train.py -n yolox-s -d 4 -b 32 --fp16 \ --logger wandb wandb-project my_yolox_project ``` -------------------------------- ### Configure YOLOX-S for VOC Dataset Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/train_custom_data.md This Python code snippet shows how to configure the `init` method of an Exp file for training YOLOX-S on the VOC dataset. It sets the number of classes to 20 and adjusts the model's depth and width. The `exp_name` is automatically derived from the file path. ```python class Exp(MyExp): def __init__(self): super(Exp, self).__init__() self.num_classes = 20 self.depth = 0.33 self.width = 0.50 self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] ``` -------------------------------- ### Train Model with Custom Experiment Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/freeze_module.md Use the `yolox.tools.train` module to train your model with a custom experiment configuration. Specify the path to your experiment file using the `-f` flag. ```bash python3 -m yolox.tools.train -f /path/to/my_exp.py ``` -------------------------------- ### Train Custom Model with COCO Pretrained Weights Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/train_custom_data.md Use this command to train your custom model, initializing with COCO pretrained weights. The `--cache` option can speed up training if sufficient RAM is available. ```bash python tools/train.py -f /path/to/your/Exp/file -d 8 -b 64 --fp16 -o -c /path/to/the/pretrained/weights [--cache] ``` -------------------------------- ### Verify Dependency Hashes Source: https://github.com/megvii-basedetection/yolox/blob/main/SECURITY.md Always verify hashes when downloading dependencies to ensure integrity. This command checks a dependency hash file. ```bash sha256sum -c ``` -------------------------------- ### Run Label Assignment Visualization Command Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/assignment_visualization.md Execute this command to generate visualizations of label assignment. Adjust the path to your experiment configuration file and specify desired parameters like dataset and batch size. ```shell python3 tools/visualize_assign.py -f /path/to/your/exp.py yolox-s -d 1 -b 8 --max-batch 2 ``` -------------------------------- ### Run TensorRT Python Demo with Image Input Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/python/README.md Execute the YOLOX TensorRT demo for image input. Use the --trt flag to enable TensorRT inference. The results will be saved if --save_result is included. ```shell python tools/demo.py image -n yolox-s --trt --save_result ``` -------------------------------- ### Prepare COCO Dataset for Training Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/quick_run.md Link the COCO dataset to the datasets directory within the YOLOX home directory. This is a prerequisite for training on COCO. ```shell cd ln -s /path/to/your/COCO ./datasets/COCO ``` -------------------------------- ### Run TensorRT Python Demo with Custom Config Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/TensorRT/python/README.md Run the YOLOX TensorRT demo using a custom experiment configuration file. This allows for inference with user-defined model settings and TensorRT acceleration. ```shell python tools/demo.py image -f exps/default/yolox_s.py --trt --save_result ``` -------------------------------- ### Run YOLOX Demo for Image Inference Source: https://github.com/megvii-basedetection/yolox/blob/main/demo/MegEngine/python/README.md Execute the YOLOX demo script for image inference. This command runs the specified YOLOX model with converted weights on a given image, applying confidence and NMS thresholds, and saves the results. ```bash python3 demo.py image -n yolox-s -c yolox_s_mge.pkl --path ../../../assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result ``` -------------------------------- ### Enable Image Caching for Faster Training Source: https://github.com/megvii-basedetection/yolox/blob/main/docs/updates_note.md Use the `--cache` flag to enable image caching in RAM for accelerated training. This feature requires significant system RAM. ```shell python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o [--cache] yolox-m yolox-l yolox-x ``` -------------------------------- ### Evaluate YOLOX Models (Batch Testing) Source: https://github.com/megvii-basedetection/yolox/blob/main/README.md Perform batch evaluation of YOLOX models. Options include specifying the model name, weights path, batch size, number of GPUs, confidence threshold, and enabling FP16 or fuse options. ```shell python -m yolox.tools.eval -n yolox-s -c yolox_s.pth -b 64 -d 8 --conf 0.001 [--fp16] [--fuse] yolox-m yolox-l yolox-x ```