import streamlit as st
# Custom CSS for better styling
st.markdown("""
""", unsafe_allow_html=True)
# Main Title
st.markdown('
ConvNeXT Image Classification
', unsafe_allow_html=True)
# Description
st.markdown("""
ConvNeXT is a state-of-the-art image classification model developed by Facebook. The model ConvNextForImageClassification can load ConvNeXT models that compete favorably with Transformers in terms of accuracy and scalability, achieving 87.8% ImageNet top-1 accuracy and outperforming Swin Transformers on COCO detection and ADE20K segmentation, while maintaining the simplicity and efficiency of standard ConvNets.
This annotator is compatible with all the models trained/fine-tuned by using ConvNextForImageClassification for PyTorch or TFConvNextForImageClassification for TensorFlow models in Hugging Face.
The model used in this demo is image_classifier_convnext_tiny_224_local
, adapted from Hugging Face and curated for scalability and production-readiness using Spark NLP.
""", unsafe_allow_html=True)
# Image Classification Overview
st.markdown('What is Image Classification?
', unsafe_allow_html=True)
st.markdown("""
Image Classification is a computer vision task where an algorithm is trained to recognize and classify objects within images. This process involves assigning a label or category to an image based on its visual content.
How It Works
Image classification typically involves the following steps:
- Data Collection: Gather a dataset of labeled images.
- Preprocessing: Normalize and resize images to prepare them for the model.
- Model Training: Use a machine learning model, such as ConvNeXT, to learn patterns and features from the images.
- Inference: Apply the trained model to new images to predict their labels.
Why Use Image Classification?
Image classification can automate and streamline many tasks, such as:
- Identifying objects in photos for content tagging.
- Enhancing search functionality by categorizing images.
- Supporting autonomous systems like self-driving cars.
Applications
Applications of image classification span across various industries:
- Healthcare: Diagnosing diseases from medical images.
- Retail: Sorting and tagging product images.
- Security: Facial recognition for authentication.
Importance
Image classification is crucial because it enables machines to interpret visual data, which is essential for creating intelligent systems capable of understanding and interacting with the world in a more human-like manner.
The ConvNeXT model used in this example is a state-of-the-art approach for image classification, offering advanced performance and scalability. It utilizes convolutional architecture to capture intricate patterns and relationships within images, enhancing classification accuracy and efficiency.
""", unsafe_allow_html=True)
# How to Use
st.markdown('How to Use the Model
', unsafe_allow_html=True)
st.code('''
import sparknlp
from sparknlp.base import *
from sparknlp.annotator import *
from pyspark.ml import Pipeline
# Load image data
imageDF = spark.read \\
.format("image") \\
.option("dropInvalid", value = True) \\
.load("src/test/resources/image/")
# Define Image Assembler
imageAssembler = ImageAssembler() \\
.setInputCol("image") \\
.setOutputCol("image_assembler")
# Define ConvNeXT classifier
imageClassifier = ConvNextForImageClassification \\
.pretrained("image_classifier_convnext_tiny_224_local", "en") \\
.setInputCols(["image_assembler"]) \\
.setOutputCol("class")
# Create pipeline
pipeline = Pipeline().setStages([imageAssembler, imageClassifier])
# Apply pipeline to image data
pipelineDF = pipeline.fit(imageDF).transform(imageDF)
# Show results
pipelineDF \\
.selectExpr("reverse(split(image.origin, '/'))[0] as image_name", "class.result") \\
.show(truncate=False)
''', language='python')
# Results
st.markdown('Results
', unsafe_allow_html=True)
st.markdown("""
Image Name |
Result |
dog.JPEG |
[whippet] |
cat.JPEG |
[Siamese] |
bird.JPEG |
[peacock] |
""", unsafe_allow_html=True)
# Model Information
st.markdown('Model Information
', unsafe_allow_html=True)
st.markdown("""
Attribute |
Description |
Model Name |
image_classifier_convnext_tiny_224_local |
Compatibility |
Spark NLP 5.0.0+ |
License |
Open Source |
Edition |
Official |
Input Labels |
[image_assembler] |
Output Labels |
[class] |
Language |
en |
Size |
107.6 MB |
""", unsafe_allow_html=True)
# Predicted Entities
st.markdown('Predicted Entities
', unsafe_allow_html=True)
st.markdown("""
- turnstile
- damselfly
- mixing bowl
- sea snake
- cockroach
- ...and many more
""", unsafe_allow_html=True)
# Data Source Section
st.markdown('Data Source
', unsafe_allow_html=True)
st.markdown("""
The ConvNeXT model is available on Hugging Face. This model was trained on a large dataset of images and can be used for accurate image classification.
""", unsafe_allow_html=True)
# References
st.markdown('References
', unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
# Community & Support
st.markdown('Community & Support
', unsafe_allow_html=True)
st.markdown("""
- Official Website: Documentation and examples
- Slack: Live discussion with the community and team
- GitHub: Bug reports, feature requests, and contributions
- Medium: Spark NLP articles
- YouTube: Video tutorials
""", unsafe_allow_html=True)