Giter VIP home page Giter VIP logo

svm_image_classification's Introduction

TensorFlow MNIST Classifier

This repository contains a simple TensorFlow-based neural network model for classifying MNIST handwritten digits dataset. The model is implemented using TensorFlow 2.9.2.

Setup

Before running the code, make sure you have the required dependencies installed. You can install them using the following command:

pip install tensorflow

Usage Import the TensorFlow library and check the version:

import tensorflow as tf
print("TensorFlow version:", tf.__version__)

Expected output: TensorFlow version: 2.9.2

Load and preprocess the MNIST dataset:

mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

Define the neural network model:

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10)
])

Make predictions and apply softmax:

predictions = model(x_train[:1]).numpy()
softmax_predictions = tf.nn.softmax(predictions).numpy()

Define the loss function:

loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)

Calculate the loss for a sample:

loss = loss_fn(y_train[:1], predictions).numpy()

Compile the model:

model.compile(optimizer='adam',
              loss=loss_fn,
              metrics=['accuracy'])

Train the model:

model.fit(x_train, y_train, epochs=5)

Evaluate the model on the test set:

test_loss, test_accuracy = model.evaluate(x_test, y_test, verbose=2)

Create a probability model:

probability_model = tf.keras.Sequential([
  model,
  tf.keras.layers.Softmax()
])

Make predictions using the probability model:

prediction_probabilities = probability_model(x_test[:5])

License This project is licensed under the MIT License - see the LICENSE file for details. Feel free to modify the content according to your needs, and make sure to update any necessary links or additional information.

svm_image_classification's People

Contributors

lakshyarathore363 avatar tanishqpal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.