Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How a Retailer Uses Machine Learning to Keep Shelves Full

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This retailer uses a combination of machine learning (ML) and computer vision to automatically detect empty or understocked shelves, predict demand, and trigger restocking alerts—so shelves stay full without constant manual checks. The system works by mounting cameras on store ceilings or shelves, feeding images to an ML model trained to recognize products and gaps, and integrating with inventory software to generate work orders for staff.

What You'll Need

  • Cameras (IP or USB) with a clear view of the shelves—typically ceiling-mounted or on the shelf edge.
  • A computer or edge device (like a small PC or Jetson) to run the ML model.
  • Machine learning software (e.g., TensorFlow, PyTorch, or a pre-built vision API) with a trained model for object detection.
  • Access to the store's inventory or point-of-sale (POS) system to compare detected stock levels with expected levels.
  • An alerting system (e.g., a dashboard, mobile app, or email) to notify staff when a shelf needs refilling.
  • Basic familiarity with Python or a similar language for scripting the integration.

Step-by-Step

  1. Define the shelf zones. Map out each aisle and shelf section in your store, assigning a unique ID to each zone. This will be the reference for where cameras should point and where alerts should be sent.
  2. Install cameras. Mount cameras so they have an unobstructed view of the product facings. For best results, place them directly above the shelf or on the opposite aisle, angled slightly downward. Ensure good lighting—avoid glare from overhead lights.
  3. Capture baseline images. Take clear photos of each shelf zone when it is fully stocked. These will serve as the “reference” for what a full shelf looks like.
  4. Label training data. If you’re training your own model, annotate the baseline images—draw bounding boxes around each product and label it with the product’s SKU or category. For a simpler start, you can use a pre-trained model that recognizes “product” vs. “empty shelf,” but for accuracy, you’ll want product-specific labels.
  5. Train the ML model. Use a framework like TensorFlow or PyTorch to train a detection model on your labeled images. If you don’t have the data or compute, use a cloud vision API (e.g., Google Vision, AWS Rekognition) that can be fine-tuned with a few examples.
  6. Set up the inference pipeline. Write a script that captures a new image from each camera on a schedule (e.g., every 5 minutes), runs the model to detect products and gaps, and compares the detected stock level against the expected level for that zone.
  7. Integrate with inventory data. Pull current stock counts from your POS or inventory system for each SKU. If the model detects fewer items than expected (for example, only 2 units when the system says 10), flag it as a potential discrepancy.
  8. Create alert rules. Define thresholds—e.g., if a shelf has less than 20% of its capacity, or if a specific SKU is out of stock for more than 30 minutes, trigger an alert.
  9. Notify staff. Send alerts to a mobile app or a dashboard that shows a store map with red markers on the affected zones. Prioritize alerts by severity (e.g., out-of-stock vs. low stock).
  10. Test and refine. Run the system for a week, compare its detections with manual checks, and adjust the model or thresholds as needed. Retrain periodically as packaging changes or new products are introduced.

Common Mistakes

  • Poor camera placement: Cameras that are too far away or at a steep angle miss products or confuse the model. Ensure the full shelf is visible and that the angle is stable.
  • Ignoring lighting changes: Shadows, glare, or flickering lights can cause false detections. Use diffused lighting and avoid placing cameras near windows.
  • Skipping the baseline: Without a clear “full shelf” reference, the model can’t tell what “empty” means. Always capture baseline images for each zone.
  • Not integrating with inventory: Vision alone can’t tell you if a shelf is empty because the product is in the back room or if it’s truly out of stock. Always cross-check with inventory counts.
  • Over-alerting: Setting thresholds too low (e.g., any gap triggers an alert) leads to alert fatigue. Use sensible thresholds like “less than 3 units” or “empty for 10 minutes.”

Tips

  • Start small: Pilot the system on one aisle or a category like beverages, then expand once you’ve validated accuracy.
  • Use a pre-trained model first: If you’re not an ML expert, use a cloud vision API that already detects “product” and “empty” classes, then fine-tune with your own images.
  • Schedule captures during off-peak hours: Run inference when the store is closed or less busy to reduce false positives from customers’ hands or bodies.
  • Combine with demand forecasting: Use historical sales data to predict which SKUs will run out soon, and have staff pre-stock before the shelf empties.
  • Keep the model updated: When a product’s packaging changes, retrain the model with new images to avoid missed detections.

Troubleshooting

If the system misses empty shelves: Check camera angle and lighting. Re-capture baseline images and retrain the model with more examples of empty shelves. Also, ensure the inference script is actually running—check logs for errors.

If there are too many false alerts: Adjust the detection threshold (e.g., require a higher confidence score) and increase the “empty” duration before alerting. Also, verify that the inventory integration is correct—if the system thinks a SKU has 10 units but the shelf shows 2, the inventory data might be stale.

If the model is slow: Use a lighter model (e.g., MobileNet) or run inference on a GPU. If using cloud APIs, ensure your internet connection is stable.

If cameras go offline: Set up a health check that pings each camera and alerts IT if a camera is unreachable. Have a manual fallback—staff can still do spot checks.

If the system works but staff ignore alerts: Make alerts actionable—include a photo of the shelf, the zone, and a suggested action. Integrate with the store’s task management system so alerts become work orders.

Frequently Asked Questions

Do I need to be an ML expert to implement this?

No. You can use cloud vision APIs that provide pre-trained models for product detection, and you only need basic scripting skills to call the API and send alerts.

How accurate is computer vision for shelf detection?

Accuracy depends on camera quality, lighting, and model training. In well-controlled conditions, detection accuracy can exceed 95%, but it varies by store layout and product types.

Can this work for non-retail environments, like a warehouse?

Yes, the same principles apply to any environment where you need to monitor stock levels on shelves, such as warehouses or storage rooms.

What if a product is hidden behind another product?

The model may miss it. To mitigate, use multiple camera angles or combine vision with RFID or weight sensors for high-value items.

How much does it cost to set up?

Costs vary widely: cameras can be $50–$200 each, a small computer like a Raspberry Pi or Jetson is $100–$500, and cloud API usage is typically per-image (a few cents per image). A pilot can cost under $1,000.

Is it legal to record customers with these cameras?

Recording in public areas of a store is generally allowed, but you should post clear signage and follow local privacy laws. Audio recording is more restricted—avoid it unless necessary.