Skip to content
Home Tutorials Roadmaps Courses Classroom Training Blog
Log in Join free
AI Intermediate Free

Image Classifier

Lesson 16 of 17 · AI Projects 94%

Build an image classifier using pre-trained models.

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))

Up next

Reinforcement Learning Basics

Lesson 17 of 17 · Reinforcement Learning