0% found this document useful (0 votes)
3 views2 pages

Experiment 10 Python

This document outlines a step-by-step process for building a convolutional neural network (CNN) using TensorFlow to predict images from the CIFAR-10 dataset. It includes steps for importing libraries, normalizing image data, constructing the model, compiling it, training, evaluating accuracy, and making predictions on sample images. The final output displays a sample image along with its predicted class label.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Experiment 10 Python

This document outlines a step-by-step process for building a convolutional neural network (CNN) using TensorFlow to predict images from the CIFAR-10 dataset. It includes steps for importing libraries, normalizing image data, constructing the model, compiling it, training, evaluating accuracy, and making predictions on sample images. The final output displays a sample image along with its predicted class label.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT-10

ML for image prediction input:-


# Step 1: Import Libraries

import tensorflow as tf

from [Link] import datasets, layers, models

import [Link] as plt

import numpy as np

# Step 2: Load CIFAR-10 Dataset

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()

class_names = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer',

'Dog', 'Frog', 'Horse', 'Ship', 'Truck']

# Step 3: Normalize pixel values (0-255 → 0-1)

train_images = train_images / 255.0

test_images = test_images / 255.0

# Step 4: Build CNN Model

model = [Link]([

layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,3)),

layers.MaxPooling2D((2,2)),

layers.Conv2D(64, (3,3), activation='relu'),

layers.MaxPooling2D((2,2)),

[Link](),

[Link](64, activation='relu'),

[Link](10)

])
# Step 5: Compile Model

[Link](optimizer='adam',

loss=[Link](from_logits=True),

metrics=['accuracy'])

# Step 6: Train Model

history = [Link](train_images, train_labels, epochs=5,

validation_data=(test_images, test_labels))

# Step 7: Evaluate Model

test_loss, test_acc = [Link](test_images, test_labels, verbose=2)

print("\nTest Accuracy:", test_acc)

# Step 8: Predict One Image

predictions = [Link](test_images)

# Display sample image and prediction

index = 5

[Link](test_images[index])

[Link]("Predicted: " + class_names[[Link](predictions[index])])

[Link]()

You might also like