EfficientNet

raw JSON →
1.1.1 verified Fri May 01 auth: no python

Re-implementation of EfficientNet models for Keras and TensorFlow Keras, providing pretrained ImageNet weights for B0–B7 and Noisy Student weights for B0–B7. Current version 1.1.1, low maintenance.

pip install efficientnet
error ModuleNotFoundError: No module named 'efficientnet.model'
cause Old import path from pre-1.0.0 versions.
fix
Use 'from efficientnet import EfficientNetB0' instead.
error ValueError: Unknown activation function: swish
cause Loading old saved models with custom swish activation not registered.
fix
Use custom_objects={'swish': keras.activations.swish} when loading the model.
error TypeError: __init__() missing 1 required positional argument: 'input_shape'
cause Misunderstanding of arguments: models expect input_shape or input_tensor, but modern API uses positional args differently.
fix
Specify input_shape as a tuple, e.g., EfficientNetB0(input_shape=(224,224,3)).
breaking API changed in v1.0.0: models must be imported from framework-specific modules. Previously trained models are not compatible; use model.load_weights or roll back.
fix Use the new import pattern (from efficientnet import EfficientNetB0). Re-train or load weights carefully.
deprecated The 'swish' custom object is no longer required; the library now uses Keras' built-in Swish activation. If you have custom code relying on 'swish', update it.
fix Remove any custom swish registration; use keras.activations.swish directly.

Load an EfficientNetB0 model with ImageNet weights and run a prediction.

from efficientnet import EfficientNetB0
from tensorflow.keras.applications.imagenet_utils import decode_predictions
import numpy as np

# Load model with pretrained weights
model = EfficientNetB0(weights='imagenet')

# Create a dummy image (224x224)
dummy = np.random.rand(1, 224, 224, 3).astype(np.float32)

# Predict
preds = model.predict(dummy)
print(decode_predictions(preds, top=3)[0])