
Let’s recall the famous scene from the film Rain Man¹, in which the protagonists are in a restaurant and toothpicks accidentally spill onto the floor. Raymond, played by Dustin Hoffman, looks for a moment at the scattered toothpicks and, without a second’s thought, gives their exact number—246. A moment later the cashier confirms that the package contained 250 sticks, of which 4 remained in the box. For the average person such an ability seems almost superhuman—this is an example of so-called savant syndrome, i.e., extremely developed skills in a narrow domain in people with neurodevelopmental disorders.
Now let’s imagine a similar scene in our production facility. Instead of toothpicks we have rolls, loaves, cookies, packages. Instead of a savant genius—a computer with access to a camera and artificial intelligence.
What if we taught the computer to identify the quantities of our products in this way? Could it, in the blink of an eye, count items on the line, verify order picking, check whether any basket was mixed up? Technology already gives us such a possibility today—we just need to implement it properly.
¹ Rain Man is a 1988 American drama directed by Barry Levinson that won four Oscars, including Best Picture, Best Director, Best Original Screenplay, and Best Actor in a Leading Role—for Dustin Hoffman.
Przegląd Piekarski i Cukierniczy — May 2025
Order picking in the bakery—we prefer not to remember it exists
In modern bakeries and confectioneries, the picking process is one of the most demanding stages of the company’s entire operation. Although often invisible from the outside, it is this process that largely determines delivery effectiveness. Picking, i.e., creating product sets for particular points of sale, takes place under heavy time pressure—most often in the early morning, right after the end of night production.
At this critical moment, every unit of bread, every cake and every batch of cookies must be assigned to the appropriate shops, sorted according to allocation tables, and flawlessly loaded into the vehicles whose routes were planned earlier. The whole constitutes a meticulously designed logistics process which—as it turns out—often exceeds the baking stage itself in complexity.
Additional difficulties include the conditions under which picking is carried out: limited visibility, low temperatures, and reduced cognitive performance of staff due to the time of day. Sensitive products such as confectionery also require the use of specialized protective packaging, which further raises organizational requirements.
To make matters worse, it is worth mentioning that picking is performed by people who are not among the best-educated and most independent. There are not many volunteers to do this hard work at such an early hour and for low pay.
In this article I will try to present how, with the help of artificial-intelligence algorithms, one can reduce the burdensomeness of this process.
How to teach a machine to identify and count objects in a bakery — using the Computer Vision capability of the Azure Cognitive Services suite
Let the robots do it for us
In the face of such dynamic and rapid technological development, intuition suggests that we wait a moment, and perhaps in about three years robots will take care of everything. Well—no robots will help. Yes, such humanoid machines already exist, but they are very expensive and not worth buying, because it makes no economic sense. Secondly, even if such cheap plastic robots appeared, they would have to be taught everything. That is, we would probably have to do exactly what I will try to discuss in this article today. Thirdly, even if they were trained and even if there were many of them and they were cheap, at the current state of technological development they will not replace humans in the picking process, because it is a bit too complicated even for an LLM².
² LLM stands for Large Language Model, i.e., a large language model. It is an advanced artificial-intelligence system based on neural-network architecture (most often transformers) that has been trained on enormous text datasets.
How do you eat a whale?
Getting a handle on the logistics distribution of bread and confectionery is a very difficult task for a human being; it is also a difficult task for artificial intelligence. This task is as big as a whale. Is it possible to quickly improve the picking process so that we can entrust it to artificial intelligence? Yes, it is—only, like any great work, it must be done in small steps. It is a whole mosaic of small projects that fit together like puzzles. If we are efficient in carrying out these small projects, the day will come when we combine all these small improvements and create a fully autonomous distribution system—practically without cost. Is this possible at the current state of technological development? This process resembles eating a whale. How do you eat a whale? You have to divide it into small pieces and then successively eat them every day.
Some time ago I wrote an article for this magazine³ describing how artificial intelligence can manage the logistics process in route planning for vehicles and in quickly finding alternative solutions.
Here I described a small project, very easy to implement. In this case, fleet management by artificial intelligence is a service provided by specialized companies, as I described in the aforementioned article. And because it is a service, it must be constructed in such a way as to be very easy for its users. In fact, nothing needs to be done here—one simply needs to implement it.
³ “The transport problem in a bakery,” Przegląd Piekarski i Cukierniczy | Yearbook 2024 — Issue 12.
How to teach a cat to count?
Another puzzle in implementing artificial intelligence in a bakery could be visual analysis of products. To launch a robot that could do anything, the robot must see and recognize objects. To speed up the picking process or the control of picked products, one would need to teach some machine to distinguish, count, detect shortages or damage to products.
Building such a smart, counting computer camera on one’s own is possible—it is just quite tedious and time-consuming. Using special libraries in the Python language (Keras or PyTorch), one can teach a computer to distinguish individual shapes, count baskets, etc. Fortunately, teaching a computer to recognize objects is already a service for sale, and one does not have to pay much for it. Thanks to this, the entire process of teaching a machine to control picking may turn out to be relatively simple and pleasant.
We should consider the introduction of artificial intelligence into the bakery in terms of small projects, and each project should be completed in a few days. Above all, it must be closed, it must work, and it must bring concrete conveniences. One should rather “grow to like” such a process for it to be effective.
What would this look like?
Let us imagine that on the loading dock we place a single set for a specific shop. We press a button, four cameras take photos from four sides. Then a printout comes out of the wall or a table appears on the monitor in which the entire assortment has been counted and compared in the table with the expected state. In this way a check of the batch for shipment has been carried out. If this is a too fanciful way of control, we can apply the same approach by installing a camera that counts the amount of bread coming out of individual ovens. We can count products that came back as returns and compare those results with documents. We can also count rolls on production belts or perform automatic inventories in warehouses of bulk raw materials. It does not matter in what way we use the ability of machines to identify, count, and automatically estimate. Undoubtedly such a skill would be useful and would constitute strong support for people running bakeries. Simply counting baskets before and after a route would already be a great convenience. The owner would have a table in which it would be easy to catch where and when the number of baskets in circulation stopped matching. Besides, such an analysis of basket tables for the entire month can be given to the free version of chatGPT4.5 to compute. It will do it and indicate who lost the baskets.
How to detect the number of loaves in baskets using Custom Vision Studio
1. Go to: https://customvision.ai
• Sign in with a Microsoft account; you will be asked to link the account to an Azure subscription.
2. Create a new project
• Click “New Project”
• Fill in:
– Name: e.g., cat counting bread
– Description: detecting loaves of bread in baskets
– Resource: choose an existing Azure resource or create a new one
– Project Type: Object Detection
– Domain: preferably General [A1]—a universal domain for most applications. Choose this option if you do not have specific requirements regarding the type of images.
3. Add photos with loaves of bread
• Click “Add images.” Upload photos showing baskets with your own loaves or whatever you want the machine to count.
• Each photo should contain from 1 to many loaves in various positions and lighting conditions.
4. Tag the photos (a key step!)
• After adding photos, click a photo. Mark each loaf of bread with a bounding box and assign it a tag, e.g., bread. The more diverse cases, the better the model works. There must be at least 30 photos with different arrangements of bread.
5. Click “Train”
• Choose Quick training
• Training will take a few minutes
• After completion you will see metrics: Precision, Recall, Average Precision
6. Test your model
• Click “Quick Test”
• Upload a new photo with a basket and check whether the model correctly detects and counts loaves.
The above validation results for the Precision parameter indicate that the model counted 57
When we are already satisfied with the results, we must publish the model.
After publishing the model we receive API keys that allow us to connect the model with a local computer, smartphone, or tablet.
Finally—and this is always important in business—the cost is rather trivial in relation to the effectiveness of this service.
Summary
The description presented is fairly enigmatic. In the publication I indicate how to teach a camera to count. Of course, the first time one will still have to toil a bit for everything to work. With each subsequent time, it will be easier and easier. Let us assume that we devote one or two days to this work. As a result we obtain an effective tool that will count something, e.g., cars in a parking lot. Let us assume that every hour we will count cars in the parking lot. The machine will do this automatically, creating a time table.
There will be the date, hour and minute, and the number of vehicles. You can also teach the computer to distinguish these vehicles. The machine can also count customers entering the store; it can also count people in a café. Let us imagine that we have 15 guests, and then when we open the sales register on the cash register it turns out that two coffees and one doughnut were sold. Perhaps someone sold something outside the register? Automatic counting systems have enormous potential for optimizing business processes. As can be seen from the above instructions, teaching a machine to count is not a process that exceeds human capabilities.
Wojciech Moszczyński
Wojciech Moszczyński—graduate of the Department of Econometrics and Statistics at Nicolaus Copernicus University in Toruń, specialist in econometrics, finance, data science and management accounting. He specializes in the optimization of production and logistics processes. He conducts research in the development and application of artificial intelligence. For years he has been involved in the popularization of machine learning and data science in business environments.