{"id":2088,"library":"keras-applications","title":"Keras Applications","description":"Keras Applications provides reference implementations of popular deep learning models alongside pre-trained weights. Currently at version 1.0.8, this standalone library historically served as the primary source for models like VGG, ResNet, and MobileNet. However, these models have since been fully integrated into the core Keras library and are now primarily accessed via `tf.keras.applications` within TensorFlow-based Keras environments.","status":"maintenance","version":"1.0.8","language":"en","source_language":"en","source_url":"https://github.com/keras-team/keras-applications","tags":["deep learning","computer vision","pre-trained models","neural networks","image classification","tensorflow","keras"],"install":[{"cmd":"pip install keras-applications","lang":"bash","label":"Install standalone package (legacy)"},{"cmd":"pip install tensorflow","lang":"bash","label":"Recommended for modern use (includes Keras Applications via tf.keras)"}],"dependencies":[{"reason":"Keras is the high-level API for TensorFlow, and Keras Applications models are now primarily accessed through `tf.keras.applications`.","package":"tensorflow","optional":false}],"imports":[{"note":"The standalone `keras_applications` library is deprecated; models are now part of `tf.keras.applications` or `keras.applications` in Keras 3.","wrong":"from keras_applications.resnet50 import ResNet50","symbol":"ResNet50","correct":"from tensorflow.keras.applications.resnet50 import ResNet50"},{"note":"Preprocessing functions are now typically model-specific and found alongside the model import in `tf.keras.applications`.","wrong":"from keras_applications.imagenet_utils import preprocess_input","symbol":"preprocess_input","correct":"from tensorflow.keras.applications.resnet50 import preprocess_input"}],"quickstart":{"code":"import numpy as np\nfrom tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input, decode_predictions\nfrom tensorflow.keras.preprocessing import image\nimport os\n\n# Create a dummy image for demonstration\ndummy_image_path = 'dummy_elephant.jpg'\nif not os.path.exists(dummy_image_path):\n    try:\n        from PIL import Image\n        img_data = np.random.randint(0, 255, size=(224, 224, 3), dtype=np.uint8)\n        dummy_img = Image.fromarray(img_data)\n        dummy_img.save(dummy_image_path)\n        print(f\"Created dummy image: {dummy_image_path}\")\n    except ImportError:\n        print(\"Pillow not installed. Skipping dummy image creation.\")\n        print(\"Please provide a real image path to run the example.\")\n        dummy_image_path = None\n\nif dummy_image_path:\n    # Load the pre-trained ResNet50 model\n    # weights='imagenet' downloads weights if not already present\n    model = ResNet50(weights='imagenet')\n    print(\"ResNet50 model loaded successfully.\")\n\n    # Load an image and resize it to the target size expected by ResNet50\n    img = image.load_img(dummy_image_path, target_size=(224, 224))\n    x = image.img_to_array(img)\n    x = np.expand_dims(x, axis=0) # Add batch dimension\n\n    # Preprocess the image for the model (e.g., channel reordering, mean subtraction)\n    x = preprocess_input(x)\n\n    # Make predictions\n    preds = model.predict(x)\n\n    # Decode the top 3 predictions\n    decoded_preds = decode_predictions(preds, top=3)[0]\n    print('Predicted:', decoded_preds)\n\n    # Clean up dummy image\n    os.remove(dummy_image_path)\nelse:\n    print(\"Quickstart example requires Pillow to create a dummy image.\")","lang":"python","description":"This quickstart demonstrates how to load a pre-trained `ResNet50` model, preprocess a sample image, and make predictions using the `tf.keras.applications` module. Weights are automatically downloaded upon first instantiation. The example includes creating a dummy image for immediate execution."},"warnings":[{"fix":"Migrate your imports to `from tensorflow.keras.applications import ...` if using TensorFlow with Keras 2.x/3.x, or `from keras.applications import ...` if using standalone Keras 3 with another backend. Remove `pip install keras-applications` and rely on `tensorflow` or `keras` installation.","message":"The standalone `keras-applications` GitHub repository and Python package are officially deprecated. All Keras Application models have been integrated into the core Keras library and the TensorFlow pip package. Direct imports from `keras_applications` may not work or might refer to an outdated version.","severity":"breaking","affected_versions":"<=1.0.8 (standalone package)"},{"fix":"Always import and apply the `preprocess_input` function specific to the model you are using (e.g., `from tensorflow.keras.applications.vgg16 import preprocess_input`).","message":"Each Keras Application model expects a specific type of input preprocessing. Failing to call the correct `preprocess_input` function for the chosen model (e.g., converting RGB to BGR, zero-centering pixels, or scaling to [-1, 1]) will lead to unstable training, incorrect feature extraction, or poor prediction accuracy when using pre-trained weights.","severity":"gotcha","affected_versions":"All versions, especially when using pre-trained weights."},{"fix":"Standardize on `from tensorflow.keras import ...` or `import tensorflow.keras as keras` for TensorFlow-based projects. For Keras 3 (standalone `keras` package), use `from keras import ...`. Avoid mixing `keras` and `tf.keras` imports in the same codebase. Consider migrating older Keras 2 code to `tf_keras` if maintaining compatibility is paramount for inactive projects.","message":"With TensorFlow 2.x, Keras is deeply integrated as `tf.keras`. Using `import keras` (standalone Keras 2) and `tf.keras` interchangeably or in the same environment can lead to confusion and `AttributeError` or `ModuleNotFoundError` issues, especially when loading saved models. Keras 3 further changes import paths for multi-backend support.","severity":"gotcha","affected_versions":"Keras 2.x and TensorFlow 2.x onwards; Keras 3.x"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}