Top Related Projects
Reference implementations of popular deep learning models.
Models and examples built with TensorFlow
Datasets, Transforms and Models specific to Computer Vision
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
Quick Overview
The fchollet/deep-learning-models
repository on GitHub contains a collection of pre-trained deep learning models for various computer vision tasks, including image classification, object detection, and semantic segmentation. These models are implemented using the Keras deep learning library and can be easily integrated into your own projects.
Pros
- Extensive Model Collection: The repository provides a wide range of pre-trained deep learning models, covering a variety of popular architectures and tasks, making it a valuable resource for researchers and developers.
- Ease of Use: The models are well-documented and easy to use, with clear instructions on how to load and use them in your own projects.
- Keras Integration: The models are implemented using the Keras deep learning library, which is widely used and well-supported, making it easy to integrate them into your existing projects.
- Customization: The models can be fine-tuned or used as feature extractors, allowing you to adapt them to your specific needs.
Cons
- Limited Model Updates: The repository may not always have the latest versions of the models, as the maintainer may not be able to keep up with the rapid pace of deep learning research.
- Potential Licensing Issues: Some of the pre-trained models may have licensing restrictions, which could limit their use in commercial projects.
- Dependency on Keras: The models are tightly coupled with the Keras library, which may not be suitable for all projects or users who prefer other deep learning frameworks.
- Limited Documentation: While the repository is well-documented, some users may find the documentation lacking in certain areas, such as advanced usage or fine-tuning.
Code Examples
Here are a few examples of how to use the pre-trained models from the fchollet/deep-learning-models
repository:
- Loading and Using a Pre-Trained Image Classification Model:
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
import numpy as np
# Load the pre-trained VGG16 model
model = VGG16(weights='imagenet', include_top=True)
# Load and preprocess an image
img_path = 'path/to/your/image.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
# Make a prediction
preds = model.predict(x)
print('Predicted:', decode_predictions(preds, top=3)[0])
- Using a Pre-Trained Model as a Feature Extractor:
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
import numpy as np
# Load the pre-trained VGG16 model without the top layer
model = VGG16(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# Load and preprocess an image
img_path = 'path/to/your/image.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
# Extract features from the image
features = model.predict(x)
- Fine-Tuning a Pre-Trained Model:
from keras.applications.vgg16 import VGG16
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.optimizers import Adam
# Load the pre-trained VGG16 model
base_model = VGG16(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# Add custom layers on top of the pre-trained model
model = Sequential()
model.add(base_model)
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
# Freeze the base model layers
for layer in base_
Competitor Comparisons
Reference implementations of popular deep learning models.
Pros of keras-applications
- More comprehensive collection of pre-trained models
- Better integration with the Keras ecosystem
- Regular updates and maintenance by the Keras team
Cons of keras-applications
- Larger repository size due to more models
- Potentially more complex for beginners due to wider range of options
Code Comparison
deep-learning-models:
from keras.applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet')
keras-applications:
from keras_applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet', backend=keras.backend, layers=keras.layers, models=keras.models)
The main difference is that keras-applications requires explicit backend, layers, and models arguments, providing more flexibility but also requiring more setup.
Both repositories offer pre-trained deep learning models for various tasks, with keras-applications being the more official and comprehensive option. deep-learning-models is maintained by François Chollet, the creator of Keras, but keras-applications is now the primary repository for Keras applications and receives more frequent updates.
While deep-learning-models is simpler to use for beginners, keras-applications offers more flexibility and a wider range of models. The choice between them depends on the specific needs of the project and the user's familiarity with Keras.
Models and examples built with TensorFlow
Pros of models
- Larger collection of pre-trained models and implementations
- More active development and community support
- Broader range of applications beyond just deep learning
Cons of models
- Can be more complex to navigate due to its size
- May have steeper learning curve for beginners
- Some models may be less optimized or more experimental
Code Comparison
deep-learning-models:
from keras.applications.vgg16 import VGG16
model = VGG16(weights='imagenet', include_top=False)
models:
import tensorflow as tf
model = tf.keras.applications.VGG16(weights='imagenet', include_top=False)
Summary
Both repositories offer valuable resources for deep learning practitioners. deep-learning-models provides a focused collection of Keras implementations, while models offers a more extensive range of TensorFlow models and tools. The choice between them depends on your specific needs, familiarity with the frameworks, and the breadth of models you require for your projects.
Datasets, Transforms and Models specific to Computer Vision
Pros of vision
- More comprehensive collection of computer vision models and tools
- Active development with frequent updates and contributions
- Seamless integration with the PyTorch ecosystem
Cons of vision
- Steeper learning curve for beginners due to its extensive features
- Potentially more complex setup and configuration
Code Comparison
deep-learning-models:
from keras.applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet')
vision:
import torchvision.models as models
model = models.resnet50(pretrained=True)
Both repositories provide pre-trained models, but vision offers a wider range of models and utilities specifically tailored for computer vision tasks. deep-learning-models focuses on Keras implementations, while vision is built for PyTorch, offering tighter integration with the PyTorch ecosystem.
vision provides more extensive documentation, examples, and community support, making it a robust choice for advanced computer vision projects. However, deep-learning-models may be more approachable for those already familiar with Keras and TensorFlow.
Ultimately, the choice between these repositories depends on your preferred deep learning framework and the specific requirements of your computer vision project.
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Pros of transformers
- Extensive library of pre-trained models for various NLP tasks
- Active community and frequent updates
- Comprehensive documentation and examples
Cons of transformers
- Steeper learning curve for beginners
- Larger library size and potential overhead
- May be overkill for simpler NLP tasks
Code comparison
transformers:
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')
deep-learning-models:
from keras.applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet')
The transformers library offers a wide range of pre-trained models for NLP tasks, while deep-learning-models focuses on computer vision models. transformers provides more flexibility and options for NLP tasks, but may be more complex for beginners. deep-learning-models is simpler to use for image-related tasks but has a more limited scope.
transformers is actively maintained and updated, with a large community contributing to its development. deep-learning-models, while useful, has not been updated as frequently.
Overall, the choice between these libraries depends on the specific task at hand and the user's familiarity with NLP and computer vision concepts.
Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
Pros of Detectron2
- More comprehensive and feature-rich for object detection and segmentation tasks
- Actively maintained with frequent updates and community support
- Includes pre-trained models and datasets for various computer vision tasks
Cons of Detectron2
- Steeper learning curve due to its complexity and extensive features
- Requires more computational resources for training and inference
- Less suitable for general-purpose deep learning tasks outside computer vision
Code Comparison
deep-learning-models:
from keras.applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet')
Detectron2:
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
cfg = get_cfg()
cfg.merge_from_file("path/to/config.yaml")
predictor = DefaultPredictor(cfg)
Summary
Detectron2 is a more specialized and comprehensive framework for object detection and segmentation, while deep-learning-models provides simpler implementations of various deep learning architectures. Detectron2 offers more features and active development but requires more expertise and resources. deep-learning-models is more accessible for general deep learning tasks but lacks the advanced computer vision capabilities of Detectron2.
YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
Pros of YOLOv5
- Specialized for object detection tasks with state-of-the-art performance
- Extensive documentation and community support
- Includes pre-trained models and easy-to-use inference scripts
Cons of YOLOv5
- Limited to object detection, less versatile for other deep learning tasks
- Larger repository size due to included datasets and pre-trained models
- Steeper learning curve for customization compared to more general frameworks
Code Comparison
YOLOv5:
import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
results = model('image.jpg')
results.print()
deep-learning-models:
from tensorflow.keras.applications import ResNet50
model = ResNet50(weights='imagenet')
from tensorflow.keras.preprocessing import image
img = image.load_img('image.jpg', target_size=(224, 224))
x = image.img_to_array(img)
preds = model.predict(x)
YOLOv5 focuses on object detection with a streamlined API, while deep-learning-models provides a broader range of pre-trained models for various tasks. YOLOv5 offers more specialized functionality, while deep-learning-models provides greater flexibility for different deep learning applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Trained image classification models for Keras
THIS REPOSITORY IS DEPRECATED. USE THE MODULE keras.applications
INSTEAD.
Pull requests will not be reviewed nor merged. Direct any PRs to keras.applications
. Issues are not monitored either.
This repository contains code for the following Keras models:
- VGG16
- VGG19
- ResNet50
- Inception v3
- CRNN for music tagging
All architectures are compatible with both TensorFlow and Theano, and upon instantiation the models will be built according to the image dimension ordering set in your Keras configuration file at ~/.keras/keras.json
. For instance, if you have set image_dim_ordering=tf
, then any model loaded from this repository will get built according to the TensorFlow dimension ordering convention, "Width-Height-Depth".
Pre-trained weights can be automatically loaded upon instantiation (weights='imagenet'
argument in model constructor for all image models, weights='msd'
for the music tagging model). Weights are automatically downloaded if necessary, and cached locally in ~/.keras/models/
.
Examples
Classify images
from resnet50 import ResNet50
from keras.preprocessing import image
from imagenet_utils import preprocess_input, decode_predictions
model = ResNet50(weights='imagenet')
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
print('Predicted:', decode_predictions(preds))
# print: [[u'n02504458', u'African_elephant']]
Extract features from images
from vgg16 import VGG16
from keras.preprocessing import image
from imagenet_utils import preprocess_input
model = VGG16(weights='imagenet', include_top=False)
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
features = model.predict(x)
Extract features from an arbitrary intermediate layer
from vgg19 import VGG19
from keras.preprocessing import image
from imagenet_utils import preprocess_input
from keras.models import Model
base_model = VGG19(weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('block4_pool').output)
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
block4_pool_features = model.predict(x)
References
- Very Deep Convolutional Networks for Large-Scale Image Recognition - please cite this paper if you use the VGG models in your work.
- Deep Residual Learning for Image Recognition - please cite this paper if you use the ResNet model in your work.
- Rethinking the Inception Architecture for Computer Vision - please cite this paper if you use the Inception v3 model in your work.
- Music-auto_tagging-keras
Additionally, don't forget to cite Keras if you use these models.
License
- All code in this repository is under the MIT license as specified by the LICENSE file.
- The ResNet50 weights are ported from the ones released by Kaiming He under the MIT license.
- The VGG16 and VGG19 weights are ported from the ones released by VGG at Oxford under the Creative Commons Attribution License.
- The Inception v3 weights are trained by ourselves and are released under the MIT license.
Top Related Projects
Reference implementations of popular deep learning models.
Models and examples built with TensorFlow
Datasets, Transforms and Models specific to Computer Vision
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot