### Install documentation dependencies Source: https://github.com/ashawkey/kiuikit/blob/main/docs/readme.md Install the full project dependencies and documentation-specific requirements before building. ```bash pip install -e ".[full]" pip install -r docs/requirements.txt ``` -------------------------------- ### Install Kiuikit via Inline Command Source: https://github.com/ashawkey/kiuikit/blob/main/README.md A quick installation command for the minimal package. ```bash pip install kiui ``` -------------------------------- ### Render Mesh Examples Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/render.md Common command-line usage patterns for rendering meshes with various configurations and output options. ```bash ## open a GUI to render a mesh kire mesh.obj kire mesh.obj --force_cuda_rast # if you cannot use OpenGL backend (usually happens for headless servers), this will fallback to CUDA backend with some limitations (ref: https://nvlabs.github.io/nvdiffrast/#rasterizing-with-cuda-vs-opengl-new) kire mesh.obj --H 800 --W 800 --ssaa 2 # set resolution and use super-sampling anti-aliasing kire mesh.obj --front_dir +x # specify mesh front-facing dir, default is +z (OpenGL convention). You can use [+-][xyz] to specify axis, and [123] to specify clockwise rotation (per 90 degree). kire mesh.glb --pbr # render with PBR (metallic + roughness) kire mesh.glb --pbr --envmap env.hdr # specify hdr file ## we can also run without GUI on headless servers kire mesh.obj --save_video out.mp4 --wogui # save 360 degree rotating video kire mesh.obj --save out --wogui # save rendered images to the out folder (controlled by --elevation and --num_azimuth) ``` -------------------------------- ### Verify package installation Source: https://github.com/ashawkey/kiuikit/blob/main/AGENTS.md Use this command to check if the package is correctly installed and importable. ```bash python -c "import kiui" ``` -------------------------------- ### Build documentation Source: https://github.com/ashawkey/kiuikit/blob/main/AGENTS.md Commands to install documentation requirements and build the Sphinx documentation. ```bash pip install -r docs/requirements.txt sphinx-build docs/source docs/build -b dirhtml ``` -------------------------------- ### Remesh CLI Installation and Usage Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/remesh.md Commands for installing dependencies and executing the remeshing tool. ```bash # install torch_scatter following https://github.com/rusty1s/pytorch_scatter # e.g., for torch2.1.0+cu121 pip install torch-scatter -f https://data.pyg.org/whl/torch-2.1.0+cu121.html # help python -m kiui.cli.remesh --help # example python -m kiui.cli.remesh --mesh chest.glb --iters 1000 ``` -------------------------------- ### Install Kiuikit via pip Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/index.md Use these commands to install the package from PyPI or the latest version directly from the GitHub repository. ```bash # released pip install kiui # install the minimal package pip install kiui[full] # install optional dependencies # latest pip install -U git+https://github.com/ashawkey/kiuikit.git ``` -------------------------------- ### Install Kiuikit Source: https://github.com/ashawkey/kiuikit/blob/main/README.md Commands to install the package via pip, including optional dependencies and the latest version from source. ```bash # released pip install kiui # install the minimal package pip install kiui[full] # install optional dependencies # latest pip install git+https://github.com/ashawkey/kiuikit.git # only the minimal package ``` -------------------------------- ### Render 3D models with Blender CLI Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/blender.md Commands for installing dependencies and executing the blender_render script with various rendering options. ```bash # make sure you are using python>=3.10, tested with bpy==4.0.0 pip install bpy mathutils # help python -m kiui.cli.blender_render --help # example python -m kiui.cli.blender_render --mesh chest.glb --gpu 0 --depth --normal --pbr --camera --blend # example with wireframe python -m kiui.cli.blender_render --mesh chest.glb --wireframe ``` -------------------------------- ### Print Torch and CUDA environment information Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/sys.md Executes the kiss torch command to display details about the installed PyTorch, CUDA, and Triton versions. ```bash kiss torch ``` -------------------------------- ### Build documentation Source: https://github.com/ashawkey/kiuikit/blob/main/docs/readme.md Navigate to the docs directory and execute the make command to generate HTML files. ```bash cd docs make html ``` -------------------------------- ### Access CLI Help Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Display help information for the video tools using either the module or the kivi shortcut. ```bash python -m kiui.video --help ``` ```bash kivi --help ``` -------------------------------- ### Create Share-Friendly Preview Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Generate a compressed video preview with specific size and quality constraints. ```bash # Create a preview that stays under 10 MB (default) kivi preview input.mp4 # Specify output path and target size kivi preview input.mp4 output.mp4 --target-mb 20 # Cap resolution and framerate kivi preview input.mp4 --max-resolution 1280 --max-fps 24 # Adjust quality floor kivi preview input.mp4 --crf 18 --preset slow # Drop audio kivi preview input.mp4 --audio-kbps 0 ``` -------------------------------- ### Using the kiss CLI Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/sys.md Commands for accessing help documentation and printing system information. ```bash # help kiss --help # print OS/system information kiss os ``` -------------------------------- ### Invoke Renderer Help Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/render.md Display the help menu for the renderer command-line interface. ```bash # invoke renderer kire --help # this is short for python -m kiui.render --help ``` -------------------------------- ### Build package metadata Source: https://github.com/ashawkey/kiuikit/blob/main/AGENTS.md Use this command to verify build and metadata integrity. ```bash python -m build ``` -------------------------------- ### Load, Inspect, and Write Mesh Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/mesh.md Demonstrates loading a mesh from a file, inspecting its attributes using kiui.lo, and exporting it to a new format. ```python import kiui from kiui.mesh import Mesh # load mesh device = torch.device("cuda" if torch.cuda.is_available() else "cpu") mesh = Mesh.load('model.glb', device=device) # inspect attributes kiui.lo(mesh.v, mesh.f, mesh.albedo, mesh.vt, mesh.ft, mesh.vn, mesh.fn) # write mesh (can change to obj format) mesh.write('model.obj') ``` -------------------------------- ### Configure video output format Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Specify codec, CRF, and preset parameters when splitting videos. ```bash kivi split input.mp4 out_dir --uniform 10 \ --codec libx265 --crf 22 --preset fast ``` -------------------------------- ### Miscellaneous CLI Usage Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/misc_cli.md Commands for background removal, pose detection, image captioning, edge detection, depth estimation, super-resolution, timers, mesh conversion, aesthetic prediction, directory comparison, and dependency locking. ```bash # background removal utils python -m kiui.cli.bg --help python -m kiui.cli.bg input.png output.png python -m kiui.cli.bg input_folder output_folder # openpose detector python -m kiui.cli.pose --help # blip2 image captioning python -m kiui.cli.blip --help # hed edge detector python -m kiui.cli.hed --help # zoe depth estimation (extra dep: pip install timm==0.6.11) python -m kiui.cli.depth_zoe --help # midas depth estimation (dpt-large) python -m kiui.cli.depth_midas --help # sr (Real-ESRGAN from https://github.com/ai-forever/Real-ESRGAN/tree/main) python -m kiui.sr --help python -m kiui.sr image.jpg --scale 2 # save to image_2x.jpg kisr image.jpg --scale 2 # short cut cmd # made-in-heaven timer (https://github.com/ashawkey/made-in-heaven-timer) python -m kiui.cli.timer --help # mesh format conversion (only for a single textured mesh in obj/glb) python -m kiui.cli.convert input.obj output.glb kico input.obj output.glb # short cut cmd kico mesh_folder/ video_folder --fmt .mp4 # render all meshes into rotating videos # aesthetic predictor v2 (https://github.com/christophschuhmann/improved-aesthetic-predictor) python -m kiui.cli.aes --help # compare content of two directories python -m kiui.cli.dircmp # lock requirements.txt package versions based on current environment python -m kiui.cli.lock_version ``` -------------------------------- ### Read and inspect an image using kiui Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/utils.md Demonstrates loading an image file and printing its metadata or shape using the lo utility. ```python import kiui x = kiui.read_image('image.png') kiui.lo(x) ``` -------------------------------- ### Split video using CLI commands Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Use these commands to split video files based on timestamps, uniform intervals, or segment lengths. ```bash # Split at custom timestamps (absolute seconds) kivi split input.mp4 out_dir \ --timestamps 10 20 30 # Split into uniform 10-second segments (last may be shorter) kivi split input.mp4 out_dir \ --uniform 10 # Only keep explicitly selected segments, drop the rest kivi split input.mp4 out_dir \ --timestamps 60 --drop_last ``` -------------------------------- ### Construct Camera Rays for OpenGL Convention Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md Ray construction logic requiring axis negation to align with the OpenGL camera convention. ```python rays_d = np.stack([ (x - cx + 0.5) / focal, (y - cy + 0.5) / focal * (-1.0), np.ones_like(x) * (-1.0), ], axis=-1) # [hw, 3] ``` -------------------------------- ### Camera Data Processing and Point Cloud Generation Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md A complete script for loading camera parameters and depth maps, adjusting for camera conventions, and exporting the resulting point cloud as a PLY file. ```python import os import re import cv2 import kiui import glob import tqdm import numpy as np from plyfile import PlyData, PlyElement def glob_sorted(path: str): paths = glob.glob(path) def _natural_key(name: str): return [int(part) if part.isdigit() else part for part in re.split(r"(\d+)", name)] return sorted( paths, key=lambda p: _natural_key(os.path.splitext(os.path.basename(p))[0]), ) def export_ply_with_color(point_cloud: np.ndarray, colors: np.ndarray, file_path: str) -> None: assert point_cloud.shape[0] == colors.shape[0] vertices = np.zeros( point_cloud.shape[0], dtype=[("x", "f4"), ("y", "f4"), ("z", "f4"), ("red", "u1"), ("green", "u1"), ("blue", "u1")], ) vertices["x"] = point_cloud[:, 0].astype(np.float32) vertices["y"] = point_cloud[:, 1].astype(np.float32) vertices["z"] = point_cloud[:, 2].astype(np.float32) vertices["red"] = colors[:, 0].astype(np.uint8) vertices["green"] = colors[:, 1].astype(np.uint8) vertices["blue"] = colors[:, 2].astype(np.uint8) el = PlyElement.describe(vertices, "vertex") os.makedirs(os.path.dirname(file_path) or ".", exist_ok=True) PlyData([el]).write(file_path) def load_data(path: str, target_size: tuple[int, int] = (320, 180)): # load camera cam_params = kiui.read_json(path) width, height = int(cam_params['renderProductResolution'][0]), int(cam_params['renderProductResolution'][1]) proj = np.array(cam_params["cameraProjection"]).reshape(4, 4).T # [4, 4], perspective projection (T is for col-major to row-major) w2c = np.array(cam_params["cameraViewTransform"]).reshape(4, 4).T # [4, 4], world2cam # get intrinsics from projection matrix fx = proj[0, 0] * (width / 2.0) fy = proj[1, 1] * (height / 2.0) cx = (1.0 - proj[0, 2]) * (width / 2.0) cy = (1.0 - proj[1, 2]) * (height / 2.0) c2w = np.linalg.inv(w2c) # load depth path_depth = path.replace("camera_params", "distance_to_camera").replace(".json", ".exr") depth = kiui.read_image(path_depth, mode="float") depth = depth.astype(np.float32) # [H, W] # downsample depth and intrinsics for visualization d_width, d_height = int(target_size[0]), int(target_size[1]) d_depth = cv2.resize(depth, (d_width, d_height), interpolation=cv2.INTER_NEAREST) scale_x = float(d_width) / float(width) scale_y = float(d_height) / float(height) d_fx = fx * scale_x d_fy = fy * scale_y d_cx = cx * scale_x d_cy = cy * scale_y # create world space point cloud ### IMPORTANT: toggle camera convention # here the camera is OpenGL convention actually # either toggle the c2w convention # c2w[:, 1] *= -1 # c2w[:, 2] *= -1 # or toggle the rays construction (but don't do both!). OPENGL_RAYS = True x, y = np.meshgrid(np.arange(d_width), np.arange(d_height), indexing="xy") x = x.reshape(-1) y = y.reshape(-1) rays_d = np.stack([ (x - d_cx + 0.5) / d_fx, (y - d_cy + 0.5) / d_fy * (-1.0 if OPENGL_RAYS else 1.0), np.ones_like(x) * (-1.0 if OPENGL_RAYS else 1.0), ], axis=-1) # [hw, 3] rays_d = rays_d @ c2w[:3, :3].T # [hw, 3] rays_o = np.expand_dims(c2w[:3, 3], 0).repeat(rays_d.shape[0], 0) # [hw, 3] # since depth is to camera center, we need to normalize the rays_d rays_d = rays_d / np.linalg.norm(rays_d, axis=-1, keepdims=True) rays_o = rays_o.reshape(d_height, d_width, 3) rays_d = rays_d.reshape(d_height, d_width, 3) valid_mask = np.isfinite(d_depth) & (d_depth > 0) points = rays_d[valid_mask] * d_depth[valid_mask][:, None] + rays_o[valid_mask] # [N, 3] in world space # load rgb for color visualization path_rgb = path.replace("camera_params", "ldr_color").replace(".json", ".png") rgb = kiui.read_image(path_rgb, mode="float") # [H, W, 3] d_rgb = cv2.resize(rgb, (d_width, d_height), interpolation=cv2.INTER_AREA) d_rgb = d_rgb[valid_mask] # [N, 3] return c2w, points, d_rgb ``` -------------------------------- ### Inspect Media Information Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Retrieve detailed metadata for video or image files. ```bash kivi info input.mp4 ``` ```bash # Inspect an image kivi info photo.jpg ``` -------------------------------- ### Execute Slurm utility commands via CLI Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/slurm.md Use these commands to interact with the Slurm cluster, including checking info, queue status, job history, logs, and resource usage. ```bash python -m kiui.slurm --help # short cut: ks --help # check cluster information (sinfo) — partitions, nodes, state with color ks info ks i # short cut # check node details (scontrol show node) + running jobs on that node ks i # check job details (scontrol show job / sacct fallback) ks job ks j # short cut # also supports job name lookup (active jobs via squeue, then history via sacct) ks j # show current user's jobs (squeue) with color-coded state, pending wait times ks queue ks q # short cut # show all users' jobs ks q -a # show specific user's jobs ks q -u # check job history (sacct), default last 3 days ks history ks h # short cut # check job history for the last 7 days ks h -d 7 # check job history for all users ks h -a # ── Log viewing ──────────────────────────────────────────────────── # Show per-rank training log (rank 0 by default, log_0.txt) ks log ks l # short cut # Show a specific rank's log ks l -r 2 # Show the raw sbatch shell log (job.out) ks l -b # Show the unified all-rank APS log ks l --aps # With --batch, show stderr (job.err) instead ks l -b -e # Show last 500 lines ks l -n 500 # Show all lines (no truncation) ks l -a # Stream the log (tail -f) ks l -f # Interactive: pick from your running jobs ks l ks l -u # ── Cancel jobs ──────────────────────────────────────────────────── # Interactive cancel (checkbox selection + confirmation) ks cancel ks c # short cut # Direct cancel specific job(s) by ID ks c ks c # ── Pending jobs ─────────────────────────────────────────────────── # Show top 10 pending jobs sorted by priority (all users + your jobs) ks pending ks p # short cut # Show top 20 pending jobs ks p -n 20 # ── Resource usage ───────────────────────────────────────────────── # Show cluster resource usage by user (sorted by GPU count) ks usage ks u # short cut # Show top 10 users by resource usage ks u -n 10 # Filter usage by partition ks u -p batch ``` -------------------------------- ### Convert camera-to-world matrices to point cloud Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md Generates points and colors representing camera axes for visualization. Requires a list of 4x4 camera-to-world matrices. ```python def c2w_to_pointcloud(c2ws: list[np.ndarray], point_per_axis: int = 5, axis_length: float = 1.0): # visualize the camera poses as point clouds, c2w is [4, 4] # debug: add the identity pose to visualize c2ws.append(np.array([ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], ])) axis_points = [] axis_colors = [] # Right, Up, Forward unit directions are columns of rotation in c2w for c2w in c2ws: R = c2w[:3, :3] t = c2w[:3, 3] dirs = [ (R[:, 0], np.array([1, 0, 0], dtype=np.float32)), # Right (X) - Red (R[:, 1], np.array([0, 1, 0], dtype=np.float32)), # Up (Y) - Green (R[:, 2], np.array([0, 0, 1], dtype=np.float32)), # Forward (Z) - Blue ] for d, col in dirs: for k in range(point_per_axis): p = t + d * (axis_length * (k / (point_per_axis - 1))) axis_points.append(p) axis_colors.append(col) axis_points_np = np.stack(axis_points, axis=0).astype(np.float32) axis_colors_np = np.stack(axis_colors, axis=0).astype(np.float32) return axis_points_np, axis_colors_np ``` -------------------------------- ### Construct Camera Rays for OpenCV Convention Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md Ray construction logic for the OpenCV convention where the camera is aligned with the 2D image coordinate system. ```python rays_d = np.stack([ (x - cx + 0.5) / focal, (y - cy + 0.5) / focal, np.ones_like(x), ], axis=-1) # [hw, 3] ``` -------------------------------- ### Resize Video Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/video.md Change the resolution of a video file, with optional encoder and framerate overrides. ```bash kivi resize input.mp4 output_640p.mp4 \ --width 640 --height 480 ``` ```bash kivi resize input.mp4 output.mp4 \ --width 640 --height 480 \ --codec libx264 \ --crf 23 \ --fps 30 ``` -------------------------------- ### Process camera parameters and export point cloud Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md Iterates through camera JSON files, aggregates data, and exports the final result as a PLY file. ```python camera_paths = glob_sorted("camera_params/*.json") all_c2ws = [] all_points = [] all_colors = [] for path in tqdm.tqdm(camera_paths): c2w, points, rgb = load_data(path, target_size=(320, 180)) all_c2ws.append(c2w) all_points.append(points) all_colors.append(rgb) # visualize the camera poses as point clouds axis_points, axis_colors = c2w_to_pointcloud(all_c2ws, point_per_axis=5, axis_length=1.0) all_points.append(axis_points) all_colors.append(axis_colors) # concatenate all the points and colors all_points = np.concatenate(all_points, axis=0) all_colors = np.concatenate(all_colors, axis=0) all_colors = np.clip(all_colors * 255.0, 0.0, 255.0).astype(np.uint8) # save colored point cloud (e.g., check with meshlab) export_ply_with_color(all_points, all_colors, "world_pointcloud.ply") ``` -------------------------------- ### Convert Between OpenGL and OpenCV Conventions Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md Negate the up and forward directions to transform a camera pose matrix between OpenGL and OpenCV conventions. ```python pose # camera2world, [4, 4] # convert between opengl and colmap convention pose[:, 1] *= -1 # up pose[:, 2] *= -1 # forward ``` -------------------------------- ### Camera Pose Matrix Structure Source: https://github.com/ashawkey/kiuikit/blob/main/docs/source/camera.md The standard 4x4 transformation matrix representing the camera-to-world (c2w) pose. ```default [[Right_x, Up_x, Forward_x, Position_x], [Right_y, Up_y, Forward_y, Position_y], [Right_z, Up_z, Forward_z, Position_z], [0, 0, 0, 1 ]] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.