terça-feira, 7 de novembro de 2017

Generic Telegram bot for image classification using DL4J

This might be useful for someone else. Using the TelegramBots Java API I build a generic bot which you can use for any ComputationGraph you exported from a DeepLearning4J application.

The bot simple gets any image it receives and use the model to predict an output. All you have to do is ask for a BotFather key and set a few system properties:


  • bot.username: Your bot userame
  • bot.token: The bot token you got from BotFather
  • classifier.labels: The model labels separated by comma
  • classifier.modelpath: The full filesystem path to the model
  • classifier.inputformat: Input image height, width and number of channels separated by comma




How it works:

  • First you train your model using DeepLearning4J API and export it. See as example what we did in our Brazilian coin classification post;
  • Second you get a bot key using BotFather;
  • Now you can clone the code from github and build it using mvn clean package (I am considering you already have maven);
  • Finally you can run classification-bot.jar and provide the system properties according to your model. See an example:
Starting the bot in command line


You can also clone the code from my github and built it using mvn clean package. 
This is the Brazilian Coin Classsification bot in action:

The bot in action: start a chat with it and send images


Every time you send an image to the bot it will run the model against it, so be careful if the bot is added to a group!

Notice that the code is poor, but it is enough to show my model in action to others - it also only support ComputationGraph. Another problem is with the image size, telegram reduce the image size and it may lead to bad predictions! If you want to make improvements feel free to send me PullRequests.



Nenhum comentário:

Postar um comentário