{
  "id": 6209043,
  "title": "Stop Guessing Your Macros: Building a Precise Calorie Estimator with SAM and GPT-4o 🥗🚀",
  "url": "https://urgent.news/2026/09/08/stop-guessing-your-macros-building-a-precise-calorie-estimator-with",
  "topic": "ai",
  "section": "AI",
  "published": "2026-09-08T01:26:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/wellallytech/stop-guessing-your-macros-building-a-precise-calorie-estimator-with-sam-and-gpt-4o-3bf4"
  },
  "original_language": "en",
  "account": "In this tutorial, we will build a precise calorie estimator using a combination of the Segment Anything Model (SAM) and GPT-4o API. The goal is to overcome the limitations of traditional dietary analysis apps that struggle to differentiate between food items on a single plate and accurately estimate portion sizes. The architecture involves several key steps:\n\n1. User uploads a photo of their meal.\n2. The image is preprocessed using OpenCV to prepare it for SAM.\n3. SAM generates masks for each distinct food item in the image, providing spatial context that helps GPT-4o understand the scale and boundaries of each dish.\n4. GPT-4o receives the original image and the masked metadata in a structured JSON format. It analyzes the image and the segment clues to identify food items, estimate their weight in grams, and provide detailed nutritional information such as calories, protein, fats, and carbs.\n5. The final calorie and macro report is returned to the user.\n\nTo implement this system, you will need Python 3.9 or higher, an OpenAI API key for accessing GPT-4o, PyTorch for running SAM locally, and FastAPI for creating the API layer. The tutorial provides code snippets for each step, starting with segmenting the plate using SAM and ending with setting up the FastAPI backend to handle API requests and responses.",
  "summary": "We’ve all been there: staring at a delicious plate of pasta, trying to figure out if it’s 400 calories or 800 calories for our fitness tracker. Traditional Dietary Analysis apps often fail because they can't distinguish between different food items on a single plate or accurately estimate portion sizes. In this tutorial, we are going to bridge that gap using a Multimodal Vision pipeline. By…",
  "key_points": [
    "User uploads meal photo to estimator system",
    "SAM generates masks for distinct food items",
    "GPT-4o analyzes image and metadata to estimate calories and macros"
  ],
  "editors_take": "Combining SAM and GPT-4o enables the creation of precise calorie estimators that overcome traditional dietary analysis app limitations in identifying food items and estimating portion sizes.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}