Well, this is not going to be the story from one of the projects. In this post I will try to show you the power (and simplicity) of #AI, solving one particular business case.
Assume that you purchase tomatoes, and when you receive them on stock you want automatically check their quality. If some tomatoes were spoiled, then you want to return them to you vendor.
General quality management task. Isn't it?
Well, in previous days you could add some option like: good quality, bad quality and storekeeper had to mark it. Then you just added some code to prevent posting items with bad quality on stock and job done.
Quick, but not effective. One more field to fill manually.
Hopefully we live in a cool time, where #AI is born and transform every task in a magical way. So, why not to use Artificial Intelligence here?
The idea is to
No human activities, no errors, no time losses, no money losses!
Sounds good, how to achieve that?
Probably you know, that Microsoft has Image Analyzer build in Business Central.
This is cool extension/service, but it will not solve our task. It works on computer vision engine, which can give us some basic tags: item category, colure, item description - everything that Microsoft decided to teach it. But, it will not give us tag: good tomato or bad tomato.
Yes. Very quickly (less than 5 min) we can build custom AI solution, and use it from anywhere.
The service is called Custom Vision.
So let's do that!
Very simple concept. Computer don't know how spoiled tomatoes look like, the same for good tomatoes. So we need to train computer, like we train children - showing him pictures and describing what's is illustrated on them.
Like any other AI service, we need data to train our custom AI model.
Typical question, where to search it and how many data do we need?
For our demo project i found 24 images of good and 14 images of bad tomatoes. All them should be with the same background. If we had millions of photos, then background could differ. If we have <100 images, background should be the same.
When you save your image files for future classification, save them in different folders, according to your tags. That will simplify tagging process in the future. Also save some images to the test folder - to test model.
Just go to https://www.customvision.ai/. Register using your Microsoft or Work account, and you are ready to build your custom ai model.
Create a project and fill some parameters.
In our case
And click Create project.
In the custom vision project, click on Add images, choose your first folder (with spoiled tomatoes), select all images (that's why we created separate folders) and upload them.
Then create new tag: spoiled tomato and finish the process.
Do the same with the second folder.
Now, you have tagged images in your project.
But you did not trained your model yet. You just gathered photos together and signed them. Now you should teach your child.
Just click on a green Train button, and in 5 seconds you will have your custom AI trained model!
How cool is that!
Remember, I told you to save some photos in a test folder? Good, if you followed my advice!
Click on a Quick Test button, upload one of your images, and check the result.
You will see how model is performing.
Click on Prediction URL and you will get all needed info to consume this AI model
That's it! Now you have your custom model published and ready for connections.
I mentioned earlier, that Business Central has out-of-the-box Image Analyzer extension.
According to the documentation it supports computer vision service, but not custom vision. I investigated api of both services, and found that they are very similar. So, I decided to check if my custom vision can be called using Image Analyzer extension.
Let's try to configure and Analyze image, using standard image analyzer.
Create new Item, upload picture of tomato, and we will get
So it works! Even from out-of-the-box.
I think, you wonder, why do we need to build custom solution, if you have working base extension. You can have reasons for that.
And the first reason is that Image Analyzer is written in C/Side. Yes! You heard that well. C/Side! Microsoft cheated here a bit - all the UI is build in AL, and all the business logic, including streaming picture to the service and analysing tags - in C/AL (using .Net).
The second reason, it does not work in some localisations. For example, I found that it works with CA localisation, and don't work with US. I've reported about that.
So, I decided to create new AL extension from scratch.
I will not describe it in detail. The source code can be found in my GitHub repo https://github.com/dkatson/Custom-Vision-And-Business-Central
It stream any picture from url or media (or blob) to custom vision service, get tags and save them.
Then you can do with your tags anything, even prevent spoiled Tomatoes to appear on the BC stock!
Publish and Post Purchase order with spoiled tomato inside.
Now your stock will be always fresh =)