{"id":5766,"library":"effdet","title":"EfficientDet for PyTorch","description":"effdet is a PyTorch implementation of the EfficientDet object detection model. It aims to faithfully reproduce the original TensorFlow models while providing PyTorch flexibility. The library is currently at version 0.4.1 and has a steady release cadence, often aligning with updates to its `timm` dependency and PyTorch versions, focusing on performance and accuracy.","status":"active","version":"0.4.1","language":"en","source_language":"en","source_url":"https://github.com/rwightman/efficientdet-pytorch","tags":["pytorch","object-detection","efficientdet","deep-learning","computer-vision","timm"],"install":[{"cmd":"pip install effdet","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core PyTorch deep learning framework.","package":"torch"},{"reason":"Standard library for computer vision tasks in PyTorch.","package":"torchvision"},{"reason":"PyTorch Image Models, provides backbones (e.g., EfficientNet) and various utilities. A key dependency for effdet models.","package":"timm"},{"reason":"Used for COCO dataset evaluation and utilities.","package":"pycocotools"},{"reason":"Used for managing model configurations.","package":"omegaconf"}],"imports":[{"note":"The `create_model` function is the recommended high-level API for instantiating models, including loading pretrained weights. Direct import of `EfficientDet` and `DetBenchTrain` is less common for typical usage and mostly for advanced customization.","wrong":"from effdet import EfficientDet, DetBenchTrain","symbol":"create_model","correct":"from effdet import create_model"}],"quickstart":{"code":"import torch\nfrom effdet import create_model\nfrom effdet.data import resolve_input_config\nfrom torchvision import transforms\nfrom PIL import Image\nimport os\n\n# Create a dummy image for a runnable example\ndummy_image_path = \"dummy_image.png\"\nif not os.path.exists(dummy_image_path):\n    img = Image.new('RGB', (640, 640), color = 'red')\n    img.save(dummy_image_path)\n\n# 1. Load a pre-trained EfficientDet model\n# Use 'tf_efficientdet_d0' for a small, fast model.\n# bench_task='predict' is crucial for inference mode.\nmodel_name = 'tf_efficientdet_d0'\nmodel = create_model(model_name, pretrained=True, bench_task='predict')\nmodel.eval()\n\n# 2. Prepare the image for inference\nimg = Image.open(dummy_image_path).convert('RGB')\n\n# Resolve input configuration from the model's pretrained_cfg\ninput_config = resolve_input_config(model.pretrained_cfg)\n\n# Define image transformation pipeline\ntransform = transforms.Compose([\n    transforms.Resize(input_config['input_size']),\n    transforms.ToTensor(),\n    transforms.Normalize(mean=input_config['mean'], std=input_config['std'])\n])\n\n# Apply transformations and add a batch dimension\ninput_tensor = transform(img).unsqueeze(0)\n\n# 3. Perform inference\nwith torch.no_grad():\n    output = model(input_tensor)\n\n# The output format is typically [x1, y1, x2, y2, score, class]\n# Print top 5 detected objects (if any)\nif output.numel() > 0:\n    print(f\"Detected objects (top 5, if available):\\n{output[0][:5]}\")\nelse:\n    print(\"No objects detected.\")\n\n# Clean up dummy image\nos.remove(dummy_image_path)","lang":"python","description":"This quickstart demonstrates how to load a pre-trained EfficientDet model, prepare a dummy image, and perform inference to detect objects. It utilizes the high-level `create_model` function and standard PyTorch image transformations."},"warnings":[{"fix":"Update your code to expect `XYXY` format for bounding boxes. This format is `[x_min, y_min, x_max, y_max]`.","message":"The bounding box output format for 'Predict' and 'Train' benches changed from `XYWH` (x, y, width, height) to `XYXY` (x1, y1, x2, y2). Users upgrading from older versions or following outdated tutorials must adjust their parsing logic.","severity":"breaking","affected_versions":"<=0.2.x to >=0.2.4 (and current)"},{"fix":"Ensure your `timm` installation matches the requirements of your `effdet` version. Check `effdet`'s `requirements.txt` or GitHub README for the exact `timm` version compatibility.","message":"`effdet` has tight dependencies on `timm` (PyTorch Image Models) versions. Upgrading `effdet` often requires updating `timm` to a specific version (e.g., `>=0.3` or `>=0.9`) due to API changes in `timm`'s helper functions and model backbones.","severity":"breaking","affected_versions":"All versions, specifically when upgrading `effdet` or `timm` independently."},{"fix":"When resizing input images, ensure both width and height are multiples of 128 (e.g., 512x512, 640x640, 768x768). Non-compliant sizes might lead to errors or unexpected behavior.","message":"Input image dimensions must be divisible by 128 due to the EfficientDet's BiFPN (Bi-directional Feature Pyramid Network) architecture, which processes features at various scales (P3 to P7).","severity":"gotcha","affected_versions":"All versions"},{"fix":"If reproducing old results or encountering training issues, use the `--legacy-focal` argument in training scripts to revert to the previous focal loss implementation. Otherwise, the new focal loss is used by default.","message":"The default focal loss implementation changed. The older version, which might have more numerical stability issues but potentially lower memory usage, can be explicitly enabled during training.","severity":"deprecated","affected_versions":">=0.2.4 (since its introduction around 2020-12-07 update)"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}