Skip to content

Building an intelligent Telegram Bot using Python & Tensorflow. The Telegram Bot will be able classify images that we send to it.

Notifications You must be signed in to change notification settings

BarraHarrison/Telegram-AI-Image-Classification-Bot

Repository files navigation

Intelligent Telegram Bot using Python & Tensorflow

A Telegram Bot is integrated with a convolutional neural network to classify images into one of the following categories:

Plane, Car, Bird, Cat, Deer, Dog, Frog, Horse, Ship and Truck

The bot was built using Python, Tensorflow and the Telegram Bot API.

Connecting to the Telegram Server

  • The bot connects to the Telegram server using the Bot API Token.
  • This Token was generated by the BotFather (Telegram Chat).
  • The token is stored in the token.txt for security reasons.
  • Application.builder method allows the bot to communicate with the Telegram server.

Functions in the Telegram Bot

  • Start function: Sends a welcome message to the user.

  • Train function: Trains the CNN model using the CIFAR-10 dataset in a seperate thread so the bot remains responsive.

  • Help function: Shows the commands that you can use.

  • Stop function: Stops the conversation with the Telegram bot.

  • Image Classification: Processed with OpenCV and predicted using the trained CNN model.

Convolutional Neural Network (CNN)

  • A CNN is a type of deep learning model used for image and video recognition.
  • It uses layers (convolutional, pooling) to extract and learn spatial features from the images.

The CNN in this project was built with the following architecture:

  • Convolutional Layers: Extracts features from the input image.
  • Pooling Layers: Downsamples the image and reduces complexity
  • Dense Layers: Fully connected layers for classification.

Saving the Trained Model

  • Model saved using .keras so it can be re-used.
  • .keras is compatible with Tensorflow

Bot Performance

  • Performed well when classifying images of cars
  • Struggled to classify images of dogs and planes
  • The CNN model (trained on CIFAR-10) may have limitations due to a small dataset to work from.

Future Improvements

  • Training the model with a larger and more diverse dataset.

  • Add commands for the user so they can see the training accuracy and loss.

  • Deploying the bot using a GPU for faster predictions

  • A GPU (Graphics Processing Unit) more suited than CPUs when it comes to rendering high-quality graphics

  • To do this I would need to use a cloud-platform which has GPU support such as AWS EC2 or Azure

About

Building an intelligent Telegram Bot using Python & Tensorflow. The Telegram Bot will be able classify images that we send to it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages