{"id":4356,"library":"fastai","title":"fastai","description":"fastai is a deep learning library that simplifies training fast and accurate neural nets using modern best practices. It's built on top of PyTorch and offers both high-level APIs for quick model development and lower-level components for researchers. The library maintains an active development pace with frequent patch and minor releases, often tied to PyTorch version updates, to ensure compatibility and leverage the latest deep learning advancements.","status":"active","version":"2.8.7","language":"en","source_language":"en","source_url":"https://github.com/fastai/fastai","tags":["deep learning","machine learning","pytorch","neural networks","computer vision","nlp","tabular","transfer learning"],"install":[{"cmd":"pip install fastai","lang":"bash","label":"Standard Installation"},{"cmd":"pip install \"torch>=X.X,<Y.Y\" torchvision torchaudio --index-url https://download.pytorch.org/whl/cuXX\npip install fastai","lang":"bash","label":"Recommended: Install PyTorch First (Specify CUDA Version)"}],"dependencies":[{"reason":"fastai is built on PyTorch and requires a compatible version.","package":"torch","optional":false},{"reason":"A foundational library providing essential extensions and utilities for fastai.","package":"fastcore","optional":false},{"reason":"Used for progress bars during training.","package":"fastprogress","optional":false}],"imports":[{"note":"Recommended for computer vision applications. The `all` module imports many common fastai components and external libraries (e.g., numpy as np, pandas as pd, matplotlib.pyplot as plt) for interactive use.","symbol":"vision.all","correct":"from fastai.vision.all import *"},{"note":"Recommended for natural language processing tasks, similarly providing an extensive set of imports.","symbol":"text.all","correct":"from fastai.text.all import *"},{"note":"Recommended for tabular data applications.","symbol":"tabular.all","correct":"from fastai.tabular.all import *"},{"note":"For core fastai functionality without application-specific modules. Importing `fastai` directly (as was common in v1) is deprecated in v2.","wrong":"from fastai import *","symbol":"basics","correct":"from fastai.basics import *"}],"quickstart":{"code":"import os\nfrom fastai.vision.all import *\n\n# Ensure the necessary directory for models is available\n# os.environ['XDG_CACHE_HOME'] = os.environ.get('XDG_CACHE_HOME', './.cache')\n\n# Download and untar the dataset (Oxford-IIIT Pet Dataset)\npath = untar_data(URLs.PETS)/'images'\n\n# Define a function to label images (e.g., determine if an image name starts with an uppercase letter, meaning it's a cat)\ndef is_cat(x): return x[0].isupper()\n\n# Create DataLoaders from image files in the specified path\n# valid_pct splits data for validation, seed ensures reproducibility\n# label_func applies 'is_cat' for labels, item_tfms resizes images\ndls = ImageDataLoaders.from_name_func(\n    path, get_image_files(path), valid_pct=0.2, seed=42,\n    label_func=is_cat, item_tfms=Resize(224)\n)\n\n# Create a Learner with a pre-trained ResNet34 model and error_rate as a metric\nlearn = vision_learner(dls, resnet34, metrics=error_rate)\n\n# Fine-tune the model for one epoch. This is a form of transfer learning.\nlearn.fine_tune(1)\n\nprint(\"Model training complete for image classification. You can now use `learn.predict(img)` for inference.\")","lang":"python","description":"This quickstart demonstrates how to train an image classification model using fastai. It downloads the Oxford-IIIT Pet Dataset, creates `DataLoaders`, initializes a `Learner` with a pre-trained `resnet34` model, and fine-tunes it for one epoch. This showcases fastai's high-level API for rapidly achieving state-of-the-art results."},"warnings":[{"fix":"Refer to the fastai v2 migration guides and rewrite data loading and callback logic according to the new API. The overall architecture remains similar, making the transition less daunting than a full rewrite.","message":"fastai v2 is a complete rewrite and is *not API-compatible* with fastai v1. Code written for v1 will break. Key changes include data loading (`DataBunch` in v1 to `DataBlock`/`DataLoaders` in v2) and the callback API (e.g., `on_*_begin` to `before_*`).","severity":"breaking","affected_versions":"All versions migrating from fastai v1 to v2+"},{"fix":"Always check the fastai release notes or official documentation for the precise PyTorch version range supported by your installed fastai version. It is often recommended to install PyTorch first, ensuring the correct CUDA toolkit version, before installing fastai.","message":"PyTorch Version Compatibility: fastai generally requires specific PyTorch versions. While recent versions (2.8.7+) may be more lenient, historically, strict compatibility has been crucial. Installing an incompatible PyTorch version can lead to runtime errors or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For production code or when clarity is paramount, consider more explicit imports (e.g., `from fastai.vision.data import ImageDataLoaders`). Be aware of fastai's design philosophy, which prioritizes interactive use and rapid prototyping with `import *`.","message":"The heavy use of `from fastai.app_name.all import *` for convenience in interactive notebooks can lead to namespace pollution and make it difficult to trace the origin of functions and classes, potentially causing name clashes or confusion in larger projects.","severity":"gotcha","affected_versions":"All v2+ versions"},{"fix":"For optimal performance on Windows, it is highly recommended to use Windows Subsystem for Linux (WSL) or run fastai from a standalone Python script where `num_workers` can be utilized effectively.","message":"On Windows, when running fastai code within Jupyter notebooks, `num_workers` for `DataLoader` is automatically reset to 0 to avoid multiprocessing-related hangs. This significantly slows down data loading, especially for I/O-heavy tasks like computer vision.","severity":"gotcha","affected_versions":"All v2+ versions on Windows with Jupyter"},{"fix":"If encountering such errors, check fastai's and PyTorch's official documentation for compatible NumPy versions. Downgrading NumPy might be necessary, but ensure it doesn't break other critical dependencies.","message":"Dependency conflicts with NumPy: Newer versions of NumPy (e.g., NumPy 2.0) can cause incompatibility issues with other compiled modules that fastai, or its underlying libraries, might depend on. This can result in 'procedure not found' or similar errors during runtime.","severity":"gotcha","affected_versions":"Potentially all versions when new NumPy releases occur"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}