{"library":"ncnn","title":"NCNN Neural Network Inference Framework","description":"NCNN is a high-performance neural network inference framework optimized for mobile platforms. The `ncnn` Python library provides official Python bindings, allowing users to load and run NCNN models from Python applications. It enables efficient deep learning inference on devices with limited computational resources. The library's versioning (`1.0.YYYYMMDD`) reflects a frequent release cadence, often aligned with new features or fixes in the core C++ NCNN project.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install ncnn"],"cli":null},"imports":["import ncnn","from ncnn import Net","from ncnn import Mat"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import ncnn\nimport numpy as np\nimport os\n\n# NCNN requires model files (.param and .bin)\n# For a runnable quickstart, we'll demonstrate the API flow.\n# In a real scenario, you'd replace these with actual converted model files.\n\n# Create dummy files - these are NOT functional NCNN models\n# but allow the API calls to proceed without immediate file not found errors.\n# A real NCNN model conversion would generate proper .param and .bin.\nwith open(\"dummy_model.param\", \"w\") as f:\n    f.write(\"7767517\\n0\\n\") # Minimal valid param content for an empty net\nwith open(\"dummy_model.bin\", \"wb\") as f:\n    f.write(b'') # Empty bin content\n\ntry:\n    # 1. Initialize NCNN network\n    net = ncnn.Net()\n    print(\"NCNN Net initialized.\")\n\n    # Optional: Configure options (e.g., enable Vulkan if available)\n    # net.opt.use_vulkan_compute = True \n\n    # 2. Load model structure (.param) and weights (.bin)\n    # Note: These dummy files will load but won't perform actual inference.\n    # Replace \"dummy_model.param\" and \"dummy_model.bin\" with your converted NCNN model paths.\n    ret_param = net.load_param(\"dummy_model.param\")\n    ret_bin = net.load_model(\"dummy_model.bin\")\n\n    if ret_param == 0 and ret_bin == 0:\n        print(\"Dummy NCNN model files loaded successfully.\")\n    else:\n        print(f\"Failed to load dummy model. param_ret={ret_param}, bin_ret={ret_bin}\")\n        # A non-zero return code means failure, e.g., malformed model files.\n\n    # 3. Prepare input data (e.g., from an image or NumPy array)\n    # This step is for demonstration; actual inference won't happen with dummy model.\n    dummy_input_array = np.random.rand(224, 224, 3).astype(np.float32) * 255\n    mat_in = ncnn.Mat.from_pixels(dummy_input_array, ncnn.PIXEL_RGB, 224, 224)\n    print(f\"Dummy input Mat created with shape: {mat_in.w}x{mat_in.h}x{mat_in.c}\")\n\n    # 4. Create an extractor and push input (for a real model)\n    # ex = net.create_extractor()\n    # ex.input(\"data\", mat_in) # \"data\" is a common input blob name\n\n    # 5. Run inference and extract output (for a real model)\n    # ret, mat_out = ex.extract(\"output\") # \"output\" is a common output blob name\n\n    print(\"NCNN API usage demonstrated. For real inference, replace dummy files with actual NCNN models.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up dummy files\n    if os.path.exists(\"dummy_model.param\"):\n        os.remove(\"dummy_model.param\")\n    if os.path.exists(\"dummy_model.bin\"):\n        os.remove(\"dummy_model.bin\")","lang":"python","description":"This quickstart demonstrates the basic API flow for initializing an NCNN network, loading (dummy) model files, and preparing input data using `ncnn.Mat`. It uses placeholder model files to be runnable without actual model conversion, but you would replace them with your own `.param` and `.bin` files for real inference.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"1.0.20260114","pypi_latest":"1.0.20260114","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":6.6,"avg_import_s":0.01,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"ncnn","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"ncnn","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":6.8,"import_time_s":0.01,"mem_mb":0.2,"disk_size":"296M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"ncnn","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"ncnn","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":6.4,"import_time_s":0.01,"mem_mb":0.2,"disk_size":"304M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"ncnn","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"ncnn","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.8,"import_time_s":0.01,"mem_mb":0.2,"disk_size":"292M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"ncnn","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"ncnn","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.8,"import_time_s":0.01,"mem_mb":0.2,"disk_size":"291M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"ncnn","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"ncnn","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.1,"import_time_s":0.01,"mem_mb":0.2,"disk_size":"306M"}]}}