{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# PointNeXt ModelNet40 free-GPU smoke/eval\n",
        "\n",
        "This notebook targets Google Colab Free or Kaggle free GPU. It installs PointNeXt/OpenPoints from source, builds the CUDA ops, downloads the ModelNet40 PointNeXt-S C=64 checkpoint from Hugging Face Hub, verifies SHA-256 when the manifest is available, and runs the ModelNet40 test command.\n",
        "\n",
        "A T4/P100 is enough for this smoke path. Full S3DIS/ScanNet training is not a free-GPU target.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import torch, platform\n",
        "print('python:', platform.python_version())\n",
        "print('torch:', torch.__version__)\n",
        "print('cuda available:', torch.cuda.is_available())\n",
        "print('gpu:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU only')\n",
        "assert torch.cuda.is_available(), 'Enable GPU runtime: Runtime -> Change runtime type -> GPU'\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Clone with submodules. If you are testing a PR branch, replace --branch master.\n",
        "!git clone --recurse-submodules https://github.com/guochengqian/PointNeXt.git\n",
        "%cd PointNeXt\n",
        "!git submodule update --init --recursive\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Install Python deps. Colab's preinstalled PyTorch is usually OK; avoid reinstalling torch unless needed.\n",
        "!python -m pip install -U pip setuptools wheel ninja gdown huggingface_hub\n",
        "!python -m pip install -r requirements.txt --no-deps\n",
        "!python -m pip install -e openpoints\n",
        "!python -m pip install -e .\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Build the CUDA ops used by PointNeXt. This takes a few minutes on Colab Free.\n",
        "!cd openpoints/cpp/pointnet2_batch && python setup.py install\n",
        "!cd openpoints/cpp/pointops && python setup.py install\n",
        "# chamfer/emd are optional for classification, but building them makes the environment closer to a full source install.\n",
        "!cd openpoints/cpp/chamfer_dist && python setup.py install\n",
        "!cd openpoints/cpp/emd && python setup.py install\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Download the ModelNet40 PointNeXt-S C=64 checkpoint.\n",
        "# If the HF repo is still private, set HF_TOKEN in Colab secrets and pass --token.\n",
        "!python tools/download_checkpoint.py modelnet40-pointnext-s-c64 --output-dir ./hf_cache\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Run ModelNet40 evaluation. The dataset is downloaded automatically by OpenPoints.\n",
        "CKPT='hf_cache/checkpoints/modelnet40/pointnext-s-c64.pth'\n",
        "!CUDA_VISIBLE_DEVICES=0 python examples/classification/main.py --cfg cfgs/modelnet40ply2048/pointnext-s.yaml model.encoder_args.width=64 mode=test --pretrained_path $CKPT wandb.use_wandb=False dataloader.num_workers=2\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Expected released checkpoint result: about OA 94.0 / mAcc 91.1 on ModelNet40. For a quick smoke check, successful CUDA op import, checkpoint download/hash verification, dataset load, and a completed test loop are the main pass criteria.\n"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "pygments_lexer": "ipython3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
