Build an image classifier using pre-trained models.
Introduction to AI
What is AI?
Machine Learning Basics
How Machine Learning Works
AI Applications
AI in the Real World
Reinforcement Learning
Reinforcement Learning Basics
AI
Intermediate
FREE
Image Classifier
Lesson 2 of 17
Intermediate
Interactive
Syntax
AI
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.preprocessing import image
import numpy as np
model = ResNet50(weights="imagenet")
img = image.load_img("cat.jpg", target_size=(224, 224))
Image Classifier Concept
PYTHON
# Conceptual image classifier def classify_by_color(r, g, b): if r > 200 and g < 100 and b < 100: return "Red object" elif r < 100 and g > 200 and b < 100: return "Green object" elif r < 100 and g < 100 and b > 200: return "Blue object" elif r > 200 and g > 200 and b > 200: return "White/bright object" else: return "Mixed color" # Test print(classify_by_color(255, 0, 0)) print(classify_by_color(0, 255, 0)) print(classify_by_color(128, 128, 128))