Help Needed: Counting Detected Objects and Calculating Calories in Roboflow Workflow

Project Type: Object Detection
Operating System & Browser: [Windows 11, Chrome]
Project Universe Link or Workspace/Project ID: Detect, Count, and Visualize 2

Hi everyone,

I’m working on a school project where I trained a Roboflow object detection model to recognize two types of chocolate bars: Bounty and Twix. The model is working well and successfully detecting the bars in images.

The Goal:
I want to:

  1. Count each type of chocolate bar detected and store it in a dictionary format like:
    {"Bounty": 2, "Twix": 1}
  2. Assign calorie values to each bar (e.g., Bounty = 103 kcal, Twix = 95 kcal).
  3. Calculate the total calorie count and display it on screen when the model is deployed.

It’s enough if this works on Roboflow’s web interface, but ideally, I’d love to get it working on an embedded device too.

The Problem:
The Workflow UI looks great and seems like it should make this easy, but I keep running into problems.

Right now, the output I get is just a list of detected labels, after using a Property Definition block on the model:
[
“Bounty”,
“Bounty”,
“Twix”
]

I can’t figure out how to transform that list into a dictionary with counts. When I try using the AI Beta for help, it suggests blocks or operations that don’t exist. I also haven’t been able to get a Custom Python block to work.

If anyone has tips on how to do this, especially how to properly use custom blocks in the Workflow, I’d really appreciate it. I’ll admit I’m struggling to fully understand how the Workflow system is supposed to work.

Thanks in advance!

1 Like

Hi @Broeloe,

You can count objects with Property Definition block with Extract Property operation followed by Count Unique Items, consider below example workflow:

When I run it with my chess pieces detection model, I get following result:

[
  {
    "property_definition": {
      "white-rook": 2,
      "black-knight": 2,
      "white-queen": 1,
      "white-bishop": 2,
      "black-queen": 1,
      "white-pawn": 8,
      "black-king": 1,
      "black-pawn": 8,
      "black-bishop": 2,
      "white-knight": 2,
      "white-king": 1,
      "black-rook": 2,
      "board": 1
    }
  }
]

In order to calculate total calories, you will need to make use of Custom Python Block

You’ll only left with writing your calories calculation logic to achieve your final goal.

It’s enough if this works on Roboflow’s web interface, but ideally, I’d love to get it working on an embedded device too.

Custom Python Block will only work on dedicated deployment or your local deployment. In workflows builder you can connect to your deployment by clicking hyperlink next to Running on (in left top corner of workflows editor). You can consult documentation on how to run inference locally, you can also use installation package created with each release (i.e. here: Release v0.51.0 · roboflow/inference · GitHub)

Hope this answers your question!

Grzegorz

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.