Loading

Food Recognition Benchmark 2022

MMdetection training and submissions (Quick, Active)

MMdetection training and evaluation code, getting 0.11 score on the leaderboard

jerome_patel

AIcrowd-Logo

🍕 Food Recognition Benchmark

Problem Statement

Detecting & Segmenting various kinds of food from an image. For ex. Someone got into new restaurent and get a food that he has never seen, well our DL model is in rescue, so our DL model will help indentifying which food it is from the class our model is being trained on!

Dataset

We will be using data from Food Recognition Challenge - A benchmark for image-based food recognition challange which is running since 2020.

https://www.aicrowd.com/challenges/food-recognition-benchmark-2022#datasets

We have a total of 39k training images with 3k validation set and 4k public-testing set. All the images are RGB and annotations exist in MS-COCO format.

Reference: This notebook is based on the notebook created by [Shraddhaa Mohan](https://www.linkedin.com/in/shraddhaa-mohan-20a008185/) and [Rohit Midha](https://www.linkedin.com/in/rohitmidha/) for previous iteration of the challenge. You can find the [original notebook here](https://colab.research.google.com/drive/1vKAQ9D3dgubbBc2jGYGQB0-lZXlT8hTh#scrollTo=Dha6_NXmIzB9).

In this Notebook, we will first do an analysis of the Food Recognition Dataset and then use maskrcnn for training on the dataset.

The Challenge

  • Given Images of Food, we are asked to provide Instance Segmentation over the images for the food items.
  • The Training Data is provided in the COCO format, making it simpler to load with pre-available COCO data processors in popular libraries.
  • The test set provided in the public dataset is similar to Validation set, but with no annotations.
  • The test set after submission is much larger and contains private images upon which every submission is evaluated.
  • Pariticipants have to submit their trained model along with trained weights. Immediately after the submission the AICrowd Grader picks up the submitted model and produces inference on the private test set using Cloud GPUs.
  • This requires Users to structure their repositories and follow a provided paradigm for submission.

The Notebook

  • Installation of MMDetection
  • Training a simple model with MMDetection
  • Local Evaluation/Quick Submision using MMDetection
  • Active Submission using trained model

GPU Check

Do a quick check if you have been allocated a GPU.

If this command fails for you, please go to Runtime -> Change Runtime Type -> Hardware Accelerator -> GPU

In [ ]:
!nvidia-smi
Tue Feb  8 14:10:18 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla P100-PCIE...  Off  | 00000000:00:04.0 Off |                    0 |
| N/A   38C    P0    26W / 250W |      0MiB / 16280MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Setting our Workspace 💼

In this section we will be downloading our dataset, unzipping it & downloading mmdetection repo/library and importing all libraries that we will be using

In [ ]:
# Login to AIcrowd
!pip install aicrowd-cli > /dev/null
!aicrowd login
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
google-colab 1.0.0 requires requests~=2.23.0, but you have requests 2.27.1 which is incompatible.
datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.
Please login here: https://api.aicrowd.com/auth/1CKFukIf1WjTbKWuxmq7upTdCwiL5O4Kez4IP4EVrAE
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: www-browser: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: links2: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: elinks: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: links: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: lynx: not found
/usr/bin/xdg-open: 851: /usr/bin/xdg-open: w3m: not found
xdg-open: no method available for opening 'https://api.aicrowd.com/auth/1CKFukIf1WjTbKWuxmq7upTdCwiL5O4Kez4IP4EVrAE'
API Key valid
Gitlab access token valid
Saved details successfully!
In [ ]:
# List dataset for this challenge
!aicrowd dataset list -c food-recognition-benchmark-2022

# Download dataset
!aicrowd dataset download -c food-recognition-benchmark-2022
                          Datasets for challenge #962                           
┌───┬────────────────────────────────┬────────────────────────────────┬────────┐
│ #  Title                           Description                       Size │
├───┼────────────────────────────────┼────────────────────────────────┼────────┤
│ 0 │ public_validation_set_2.0.tar… │ Validation Dataset (contains   │    59M │
│   │                                │ 1000 images and 498            │        │
│   │                                │ categories, with annotations)  │        │
│ 1 │ public_test_release_2.0.tar.gz │ [Public] Testing Dataset       │   197M │
│   │                                │ (contains 3000 images and 498  │        │
│   │                                │ categories, without            │        │
│   │                                │ annotations)                   │        │
│ 2 │ public_training_set_release_2… │ Training Dataset (contains     │ 2.14GB │
│   │                                │ 39962 images and 498           │        │
│   │                                │ categories)                    │        │
└───┴────────────────────────────────┴────────────────────────────────┴────────┘
public_validation_set_2.0.tar.gz: 100% 62.4M/62.4M [00:02<00:00, 26.8MB/s]
public_test_release_2.0.tar.gz: 100% 207M/207M [00:07<00:00, 27.8MB/s]
public_training_set_release_2.0.tar.gz: 100% 2.30G/2.30G [02:01<00:00, 18.9MB/s]
In [ ]:
# Create data directory
!mkdir -p data/ data/train data/val data/test
!cp *test* data/test && cd data/test && echo "Extracting test dataset" && tar -xvf *test* > /dev/null
!cp *val* data/val && cd data/val && echo "Extracting val dataset" &&  tar -xvf *val* > /dev/null
!cp *train* data/train && cd data/train && echo "Extracting train dataset" &&  tar -xvf *train* > /dev/null
Extracting test dataset
Extracting val dataset
Extracting train dataset

Mount the Google Drive

In [ ]:
#alternatively copy files from drive

from google.colab import drive
drive.mount('/content/drive')
Mounted at /content/drive

Installation

In [ ]:
import torch
TORCH_VERSION = torch.__version__.split("+")[0]
CUDA_VERSION = torch.__version__.split("+")[-1]
print("torch: ", TORCH_VERSION, "; cuda: ", CUDA_VERSION)

#we have used torch version 1.10.0 and cuda 11.1 as it is preinstalled in this colab version
!pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/$CUDA_VERSION/torch$TORCH_VERSION/index.html
# If there is not yet a detectron2 release that matches the given torch + CUDA version, you need to install a different pytorch.
#don't forget to restart the runtime 

# Install mmdetection
!rm -rf mmdetection
!git clone https://github.com/open-mmlab/mmdetection.git
%cd mmdetection

!pip install -e .

!pip install Pillow
!pip uninstall pycocotools -y
!pip install -q git+https://github.com/waleedka/coco.git#subdirectory=PythonAPI
torch:  1.10.0 ; cuda:  cu111
Looking in links: https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html
Collecting mmcv-full
  Downloading https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/mmcv_full-1.4.4-cp37-cp37m-manylinux1_x86_64.whl (68.5 MB)
     |████████████████████████████████| 68.5 MB 141 kB/s 
Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (7.1.2)
Collecting addict
  Downloading addict-2.4.0-py3-none-any.whl (3.8 kB)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (1.19.5)
Collecting yapf
  Downloading yapf-0.32.0-py2.py3-none-any.whl (190 kB)
     |████████████████████████████████| 190 kB 5.2 MB/s 
Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (3.13)
Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (21.3)
Requirement already satisfied: opencv-python>=3 in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (4.1.2.30)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->mmcv-full) (3.0.7)
Installing collected packages: yapf, addict, mmcv-full
Successfully installed addict-2.4.0 mmcv-full-1.4.4 yapf-0.32.0
Cloning into 'mmdetection'...
remote: Enumerating objects: 22983, done.
remote: Total 22983 (delta 0), reused 0 (delta 0), pack-reused 22983
Receiving objects: 100% (22983/22983), 25.77 MiB | 34.36 MiB/s, done.
Resolving deltas: 100% (16110/16110), done.
/content/mmdetection
Obtaining file:///content/mmdetection
Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmdet==2.21.0) (3.2.2)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmdet==2.21.0) (1.19.5)
Requirement already satisfied: pycocotools in /usr/local/lib/python3.7/dist-packages (from mmdet==2.21.0) (2.0.4)
Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mmdet==2.21.0) (1.15.0)
Collecting terminaltables
  Downloading terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet==2.21.0) (2.8.2)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet==2.21.0) (3.0.7)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet==2.21.0) (1.3.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet==2.21.0) (0.11.0)
Installing collected packages: terminaltables, mmdet
  Running setup.py develop for mmdet
Successfully installed mmdet-2.21.0 terminaltables-3.1.10
Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (7.1.2)
Found existing installation: pycocotools 2.0.4
Uninstalling pycocotools-2.0.4:
  Successfully uninstalled pycocotools-2.0.4
  Building wheel for pycocotools (setup.py) ... done

Note: Before continuing restart runtime

To restart runtime : Runtime > Restart Runtime

Imports

In [ ]:
%cd /content/

#Directories present
import numpy as np
import pandas as pd
import os
for dirname, _, filenames in os.walk('data/'):
        print(dirname)
import os
import sys
sys.path.append("mmdetection")
import time
import matplotlib
import matplotlib.pylab as plt
plt.rcParams["axes.grid"] = False
/content
data/
data/val
data/val/images
data/test
data/test/images
data/train
data/train/images

So, the data directory is something like this:

Reading Data

In [ ]:
# For reading annotations file
import json
from pycocotools.coco import COCO

# Reading annotations.json
TRAIN_ANNOTATIONS_PATH = "data/train/annotations.json"
TRAIN_IMAGE_DIRECTIORY = "data/train/images/"

VAL_ANNOTATIONS_PATH = "data/val/annotations.json"
VAL_IMAGE_DIRECTIORY = "data/val/images/"

train_coco = COCO(TRAIN_ANNOTATIONS_PATH)
loading annotations into memory...
Done (t=4.58s)
creating index...
index created!
In [ ]:
# Reading the annotation files
with open(TRAIN_ANNOTATIONS_PATH) as f:
  train_annotations_data = json.load(f)

with open(VAL_ANNOTATIONS_PATH) as f:
  val_annotations_data = json.load(f)
train_annotations_data['annotations'][0]
Out[ ]:
{'area': 5059.0,
 'bbox': [39.5, 39.5, 167.0, 92.0],
 'category_id': 1352,
 'id': 184135,
 'image_id': 131094,
 'iscrowd': 0,
 'segmentation': [[115.0,
   206.5,
   98.0,
   204.5,
   74.5,
   182.0,
   65.0,
   167.5,
   47.5,
   156.0,
   39.5,
   137.0,
   39.5,
   130.0,
   51.0,
   118.5,
   62.00000000000001,
   112.5,
   76.0,
   113.5,
   121.5,
   151.0,
   130.5,
   169.0,
   131.5,
   185.0,
   128.5,
   195.0]]}

Data Format 🔍

Our COCO data format is something like this -

"info": {...},
"categories": [...],
"images": [...],
"annotations": [...],

In which categories is like this

[
  {'id': 2578,
  'name': 'water',
  'name_readable': 'Water',
  'supercategory': 'food'},
  {'id': 1157,
  'name': 'pear',
  'name_readable': 'Pear',
  'supercategory': 'food'},
  ...
  {'id': 1190,
  'name': 'peach',
  'name_readable': 'Peach',
  'supercategory': 'food'}
]

Info is empty ( not sure why )

images is like this

[
  {'file_name': '065537.jpg', 
  'height': 464, 
  'id': 65537, 
  'width': 464},
  {'file_name': '065539.jpg', 
  'height': 464, 
  'id': 65539, 
  'width': 464},
 ...
  {'file_name': '069900.jpg', 
  'height': 391, 
  'id': 69900, 
  'width': 392},
]

Annotations is like this

{'area': 44320.0,
 'bbox': [86.5, 127.49999999999999, 286.0, 170.0],
 'category_id': 2578,
 'id': 102434,
 'image_id': 65537,
 'iscrowd': 0,
 'segmentation': [[235.99999999999997,
   372.5,
   169.0,
   372.5,
   ...
   368.5,
   264.0,
   371.5]]}

Fixing the Data

In [ ]:
#fix dataset
import numpy as np
import pandas as pd
import cv2
import json
from tqdm.notebook import tqdm

# Reading annotations.json
TRAIN_ANNOTATIONS_PATH = "/content/data/train/annotations.json"
TRAIN_IMAGE_DIRECTIORY = "/content/data/train/images/"

VAL_ANNOTATIONS_PATH = "/content/data/val/annotations.json"
VAL_IMAGE_DIRECTIORY = "/content/data/val/images/"

# train_coco = COCO(TRAIN_ANNOTATIONS_PATH)

# Reading the annotation files
with open(TRAIN_ANNOTATIONS_PATH) as f:
  train_annotations_data = json.load(f)

with open(VAL_ANNOTATIONS_PATH) as f:
  val_annotations_data = json.load(f)



# Function for taking a annotation & directiory of images and returning new annoation json with fixed image size info
def fix_data(annotations, directiory, VERBOSE = False):
  for n, i in enumerate(tqdm((annotations['images']))):
   
      img = cv2.imread(directiory+i["file_name"])
 
      if img.shape[0] != i['height']:
          annotations['images'][n]['height'] = img.shape[0]
          if VERBOSE:
            print(i["file_name"])
            print(annotations['images'][n], img.shape)

      if img.shape[1] != i['width']:
          annotations['images'][n]['width'] = img.shape[1]
          if VERBOSE:
            print(i["file_name"])
            print(annotations['images'][n], img.shape)

  return annotations

train_annotations_data = fix_data(train_annotations_data, TRAIN_IMAGE_DIRECTIORY)

with open('/content/data/train/new_ann.json', 'w') as f:
    json.dump(train_annotations_data, f)

val_annotations_data = fix_data(val_annotations_data, VAL_IMAGE_DIRECTIORY)

with open('/content/data/val/new_ann.json', 'w') as f:
    json.dump(val_annotations_data, f)

Setting up hyperparameters

Modify the model configuration hyperparameters for our training

  • Load the configuration files and modify them for our dataset.
  • Set the desired hyperparameters as well
  • Start training and logging
In [ ]:
# You can add more model configs like below.
MODELS_CONFIG = {
    'htc_without_semantic_r50_fpn_1x': {
        'config_file': 'configs/htc/htc_without_semantic_r50_fpn_1x_coco.py'
    }
}

# Pick the model you want to use
selected_model = 'htc_without_semantic_r50_fpn_1x' # chose any config you want from the MODELS_CONFIG

# Name of the config file.
config_file = MODELS_CONFIG[selected_model]['config_file']

config_fname = os.path.join('mmdetection', config_file)
assert os.path.isfile(config_fname), '`{}` not exist'.format(config_fname)
config_fname
Out[ ]:
'mmdetection/configs/htc/htc_without_semantic_r50_fpn_1x_coco.py'
In [ ]:
%cd /content/

# Explore classes to predict, we will use this while editing the config
annotation_path = os.path.join("data", "train/new_ann.json")
json_file = open(annotation_path)
coco = json.load(json_file)
print(coco["categories"])
classes_names = [category["name"] for category in coco["categories"]]
print(classes_names)
/content
[{'id': 1565, 'name': 'bread-wholemeal', 'name_readable': 'Bread, wholemeal', 'supercategory': 'food'}, {'id': 2099, 'name': 'jam', 'name_readable': 'Jam', 'supercategory': 'food'}, {'id': 2578, 'name': 'water', 'name_readable': 'Water', 'supercategory': 'food'}, {'id': 1556, 'name': 'bread-sourdough', 'name_readable': 'Bread, sourdough', 'supercategory': 'food'}, {'id': 1154, 'name': 'banana', 'name_readable': 'Banana', 'supercategory': 'food'}, {'id': 1352, 'name': 'soft-cheese', 'name_readable': 'Soft cheese', 'supercategory': 'food'}, {'id': 1893, 'name': 'ham-raw', 'name_readable': 'Ham, raw', 'supercategory': 'food'}, {'id': 1310, 'name': 'hard-cheese', 'name_readable': 'Hard cheese', 'supercategory': 'food'}, {'id': 1264, 'name': 'cottage-cheese', 'name_readable': 'Cottage cheese', 'supercategory': 'food'}, {'id': 1536, 'name': 'bread-half-white', 'name_readable': 'Bread, half white', 'supercategory': 'food'}, {'id': 2512, 'name': 'coffee-with-caffeine', 'name_readable': 'Coffee, with caffeine', 'supercategory': 'food'}, {'id': 1166, 'name': 'fruit-salad', 'name_readable': 'Fruit salad', 'supercategory': 'food'}, {'id': 2949, 'name': 'pancakes', 'name_readable': 'Pancakes', 'supercategory': 'food'}, {'id': 2498, 'name': 'tea', 'name_readable': 'Tea', 'supercategory': 'food'}, {'id': 2973, 'name': 'salmon-smoked', 'name_readable': 'Salmon, smoked', 'supercategory': 'food'}, {'id': 1056, 'name': 'avocado', 'name_readable': 'Avocado', 'supercategory': 'food'}, {'id': 1111, 'name': 'spring-onion-scallion', 'name_readable': 'Spring onion / scallion', 'supercategory': 'food'}, {'id': 2524, 'name': 'ristretto-with-caffeine', 'name_readable': 'Ristretto, with caffeine', 'supercategory': 'food'}, {'id': 1886, 'name': 'ham', 'name_readable': 'Ham', 'supercategory': 'food'}, {'id': 2022, 'name': 'egg', 'name_readable': 'Egg', 'supercategory': 'food'}, {'id': 1915, 'name': 'bacon-frying', 'name_readable': 'Bacon, frying', 'supercategory': 'food'}, {'id': 1013, 'name': 'chips-french-fries', 'name_readable': 'Chips, french fries', 'supercategory': 'food'}, {'id': 2446, 'name': 'juice-apple', 'name_readable': 'Juice, apple', 'supercategory': 'food'}, {'id': 1788, 'name': 'chicken', 'name_readable': 'Chicken', 'supercategory': 'food'}, {'id': 1069, 'name': 'tomato-raw', 'name_readable': 'Tomato, raw ', 'supercategory': 'food'}, {'id': 1085, 'name': 'broccoli', 'name_readable': 'Broccoli', 'supercategory': 'food'}, {'id': 259, 'name': 'shrimp-boiled', 'name_readable': 'Shrimp, boiled', 'supercategory': 'food'}, {'id': 50, 'name': 'beetroot-steamed-without-addition-of-salt', 'name_readable': 'Beetroot, steamed, without addition of salt', 'supercategory': 'food'}, {'id': 1078, 'name': 'carrot-raw', 'name_readable': 'Carrot, raw', 'supercategory': 'food'}, {'id': 1143, 'name': 'chickpeas', 'name_readable': 'Chickpeas', 'supercategory': 'food'}, {'id': 2743, 'name': 'french-salad-dressing', 'name_readable': 'French salad dressing', 'supercategory': 'food'}, {'id': 1487, 'name': 'pasta-hornli', 'name_readable': 'Pasta, Hörnli', 'supercategory': 'food'}, {'id': 2730, 'name': 'sauce-cream', 'name_readable': 'Sauce, cream', 'supercategory': 'food'}, {'id': 8025, 'name': 'meat-balls', 'name_readable': 'Meat balls', 'supercategory': 'food'}, {'id': 1483, 'name': 'pasta', 'name_readable': 'Pasta', 'supercategory': 'food'}, {'id': 2738, 'name': 'tomato-sauce', 'name_readable': 'Tomato sauce', 'supercategory': 'food'}, {'id': 1311, 'name': 'cheese', 'name_readable': 'Cheese', 'supercategory': 'food'}, {'id': 1157, 'name': 'pear', 'name_readable': 'Pear', 'supercategory': 'food'}, {'id': 1213, 'name': 'cashew-nut', 'name_readable': 'Cashew nut', 'supercategory': 'food'}, {'id': 1210, 'name': 'almonds', 'name_readable': 'Almonds', 'supercategory': 'food'}, {'id': 1144, 'name': 'lentils', 'name_readable': 'Lentils', 'supercategory': 'food'}, {'id': 1022, 'name': 'mixed-vegetables', 'name_readable': 'Mixed vegetables', 'supercategory': 'food'}, {'id': 1203, 'name': 'peanut-butter', 'name_readable': 'Peanut butter', 'supercategory': 'food'}, {'id': 1151, 'name': 'apple', 'name_readable': 'Apple', 'supercategory': 'food'}, {'id': 1169, 'name': 'blueberries', 'name_readable': 'Blueberries', 'supercategory': 'food'}, {'id': 1061, 'name': 'cucumber', 'name_readable': 'Cucumber', 'supercategory': 'food'}, {'id': 2171, 'name': 'cocoa-powder', 'name_readable': 'Cocoa powder', 'supercategory': 'food'}, {'id': 3332, 'name': 'greek-yaourt-yahourt-yogourt-ou-yoghourt', 'name_readable': 'Greek Yaourt, yahourt, yogourt ou yoghourt', 'supercategory': 'food'}, {'id': 2115, 'name': 'maple-syrup-concentrate', 'name_readable': 'Maple syrup (Concentrate)', 'supercategory': 'food'}, {'id': 3181, 'name': 'buckwheat-grain-peeled', 'name_readable': 'Buckwheat, grain peeled', 'supercategory': 'food'}, {'id': 2053, 'name': 'butter', 'name_readable': 'Butter', 'supercategory': 'food'}, {'id': 2555, 'name': 'herbal-tea', 'name_readable': 'Herbal tea', 'supercategory': 'food'}, {'id': 2750, 'name': 'mayonnaise', 'name_readable': 'Mayonnaise', 'supercategory': 'food'}, {'id': 2836, 'name': 'soup-vegetable', 'name_readable': 'Soup, vegetable', 'supercategory': 'food'}, {'id': 2618, 'name': 'wine-red', 'name_readable': 'Wine, red', 'supercategory': 'food'}, {'id': 2620, 'name': 'wine-white', 'name_readable': 'Wine, white', 'supercategory': 'food'}, {'id': 387, 'name': 'green-bean-steamed-without-addition-of-salt', 'name_readable': 'Green bean, steamed, without addition of salt', 'supercategory': 'food'}, {'id': 1924, 'name': 'sausage', 'name_readable': 'Sausage', 'supercategory': 'food'}, {'id': 2939, 'name': 'pizza-margherita-baked', 'name_readable': 'Pizza, Margherita, baked', 'supercategory': 'food'}, {'id': 1879, 'name': 'salami', 'name_readable': 'Salami', 'supercategory': 'food'}, {'id': 1098, 'name': 'mushroom', 'name_readable': 'Mushroom', 'supercategory': 'food'}, {'id': 3739, 'name': 'bread-meat-substitute-lettuce-sauce', 'name_readable': '(bread, meat substitute, lettuce, sauce)', 'supercategory': 'food'}, {'id': 2350, 'name': 'tart', 'name_readable': 'Tart', 'supercategory': 'food'}, {'id': 2543, 'name': 'tea-verveine', 'name_readable': 'Tea, verveine', 'supercategory': 'food'}, {'id': 1468, 'name': 'rice', 'name_readable': 'Rice', 'supercategory': 'food'}, {'id': 2521, 'name': 'white-coffee-with-caffeine', 'name_readable': 'White coffee, with caffeine', 'supercategory': 'food'}, {'id': 1222, 'name': 'linseeds', 'name_readable': 'Linseeds', 'supercategory': 'food'}, {'id': 1208, 'name': 'sunflower-seeds', 'name_readable': 'Sunflower seeds', 'supercategory': 'food'}, {'id': 1889, 'name': 'ham-cooked', 'name_readable': 'Ham, cooked', 'supercategory': 'food'}, {'id': 1068, 'name': 'bell-pepper-red-raw', 'name_readable': 'Bell pepper, red, raw ', 'supercategory': 'food'}, {'id': 1070, 'name': 'zucchini', 'name_readable': 'Zucchini', 'supercategory': 'food'}, {'id': 1123, 'name': 'green-asparagus', 'name_readable': 'Green asparagus', 'supercategory': 'food'}, {'id': 2751, 'name': 'tartar-sauce', 'name_readable': 'Tartar sauce', 'supercategory': 'food'}, {'id': 1595, 'name': 'lye-pretzel-soft', 'name_readable': 'Lye pretzel (soft)', 'supercategory': 'food'}, {'id': 1060, 'name': 'cucumber-pickled', 'name_readable': 'Cucumber, pickled ', 'supercategory': 'food'}, {'id': 3630, 'name': 'curry-vegetarian', 'name_readable': 'Curry, vegetarian', 'supercategory': 'food'}, {'id': 5641, 'name': 'yaourt-yahourt-yogourt-ou-yoghourt-natural', 'name_readable': 'Yaourt, yahourt, yogourt ou yoghourt, natural', 'supercategory': 'food'}, {'id': 3358, 'name': 'soup-of-lentils-dahl-dhal', 'name_readable': 'Soup of lentils, Dahl (Dhal)', 'supercategory': 'food'}, {'id': 2837, 'name': 'soup-cream-of-vegetables', 'name_readable': 'Soup, cream of vegetables', 'supercategory': 'food'}, {'id': 2815, 'name': 'balsamic-vinegar', 'name_readable': 'Balsamic vinegar', 'supercategory': 'food'}, {'id': 1967, 'name': 'salmon', 'name_readable': 'Salmon', 'supercategory': 'food'}, {'id': 2923, 'name': 'salt-cake-vegetables-filled', 'name_readable': 'Salt cake (vegetables, filled)', 'supercategory': 'food'}, {'id': 1914, 'name': 'bacon', 'name_readable': 'Bacon', 'supercategory': 'food'}, {'id': 1187, 'name': 'orange', 'name_readable': 'Orange', 'supercategory': 'food'}, {'id': 1494, 'name': 'pasta-noodles', 'name_readable': 'Pasta, noodles', 'supercategory': 'food'}, {'id': 1376, 'name': 'cream', 'name_readable': 'Cream', 'supercategory': 'food'}, {'id': 2303, 'name': 'cake-chocolate', 'name_readable': 'Cake, chocolate', 'supercategory': 'food'}, {'id': 1505, 'name': 'pasta-spaghetti', 'name_readable': 'Pasta, spaghetti', 'supercategory': 'food'}, {'id': 1229, 'name': 'black-olives', 'name_readable': 'Black olives', 'supercategory': 'food'}, {'id': 1323, 'name': 'parmesan', 'name_readable': 'Parmesan', 'supercategory': 'food'}, {'id': 1482, 'name': 'spaetzle', 'name_readable': 'Spaetzle', 'supercategory': 'food'}, {'id': 1050, 'name': 'salad-lambs-ear', 'name_readable': "Salad, lambs' ear", 'supercategory': 'food'}, {'id': 1040, 'name': 'salad-leaf-salad-green', 'name_readable': 'Salad, leaf / salad, green', 'supercategory': 'food'}, {'id': 1010, 'name': 'potatoes-steamed', 'name_readable': 'Potatoes steamed', 'supercategory': 'food'}, {'id': 1094, 'name': 'white-cabbage', 'name_readable': 'White cabbage', 'supercategory': 'food'}, {'id': 1309, 'name': 'halloumi', 'name_readable': 'Halloumi', 'supercategory': 'food'}, {'id': 1075, 'name': 'beetroot-raw', 'name_readable': 'Beetroot, raw', 'supercategory': 'food'}, {'id': 1538, 'name': 'bread-grain', 'name_readable': 'Bread, grain', 'supercategory': 'food'}, {'id': 727, 'name': 'applesauce-unsweetened-canned', 'name_readable': 'Applesauce, unsweetened, canned', 'supercategory': 'food'}, {'id': 1327, 'name': 'cheese-for-raclette', 'name_readable': 'Cheese for raclette', 'supercategory': 'food'}, {'id': 1102, 'name': 'mushrooms', 'name_readable': 'Mushrooms', 'supercategory': 'food'}, {'id': 1566, 'name': 'bread-white', 'name_readable': 'Bread, white', 'supercategory': 'food'}, {'id': 870, 'name': 'curds-natural-with-at-most-10-fidm', 'name_readable': 'Curds, natural, with at most 10% fidm', 'supercategory': 'food'}, {'id': 1517, 'name': 'bagel-without-filling', 'name_readable': 'Bagel (without filling)', 'supercategory': 'food'}, {'id': 732, 'name': 'quiche-with-cheese-baked-with-puff-pastry', 'name_readable': 'Quiche, with cheese, baked, with puff pastry', 'supercategory': 'food'}, {'id': 2840, 'name': 'soup-potato', 'name_readable': 'Soup, potato', 'supercategory': 'food'}, {'id': 2859, 'name': 'bouillon-vegetable', 'name_readable': 'Bouillon, vegetable', 'supercategory': 'food'}, {'id': 1727, 'name': 'beef-sirloin-steak', 'name_readable': 'Beef, sirloin steak', 'supercategory': 'food'}, {'id': 2967, 'name': 'taboule-prepared-with-couscous', 'name_readable': 'Taboulé, prepared, with couscous', 'supercategory': 'food'}, {'id': 1055, 'name': 'eggplant', 'name_readable': 'Eggplant', 'supercategory': 'food'}, {'id': 1522, 'name': 'bread', 'name_readable': 'Bread', 'supercategory': 'food'}, {'id': 3399, 'name': 'turnover-with-meat-small-meat-pie-empanadas', 'name_readable': 'Turnover with meat (small meat pie, empanadas)', 'supercategory': 'food'}, {'id': 1121, 'name': 'mungbean-sprouts', 'name_readable': 'Mungbean sprouts', 'supercategory': 'food'}, {'id': 1321, 'name': 'mozzarella', 'name_readable': 'Mozzarella', 'supercategory': 'food'}, {'id': 1496, 'name': 'pasta-penne', 'name_readable': 'Pasta, penne', 'supercategory': 'food'}, {'id': 3415, 'name': 'lasagne-vegetable-prepared', 'name_readable': 'Lasagne, vegetable, prepared', 'supercategory': 'food'}, {'id': 1180, 'name': 'mandarine', 'name_readable': 'Mandarine', 'supercategory': 'food'}, {'id': 1176, 'name': 'kiwi', 'name_readable': 'Kiwi', 'supercategory': 'food'}, {'id': 1058, 'name': 'french-beans', 'name_readable': 'French beans', 'supercategory': 'food'}, {'id': 4335, 'name': 'tartar-meat', 'name_readable': 'Tartar (meat)', 'supercategory': 'food'}, {'id': 2918, 'name': 'spring-roll-fried', 'name_readable': 'Spring roll (fried)', 'supercategory': 'food'}, {'id': 1757, 'name': 'pork-chop', 'name_readable': 'Pork, chop', 'supercategory': 'food'}, {'id': 2964, 'name': 'caprese-salad-tomato-mozzarella', 'name_readable': 'Caprese salad (Tomato Mozzarella)', 'supercategory': 'food'}, {'id': 1032, 'name': 'leaf-spinach', 'name_readable': 'Leaf spinach', 'supercategory': 'food'}, {'id': 1569, 'name': 'roll-of-half-white-or-white-flour-with-large-void', 'name_readable': 'Roll of half-white or white flour, with large void', 'supercategory': 'food'}, {'id': 1500, 'name': 'pasta-ravioli-stuffing', 'name_readable': 'Pasta, ravioli, stuffing', 'supercategory': 'food'}, {'id': 2320, 'name': 'omelette-plain', 'name_readable': 'Omelette, plain', 'supercategory': 'food'}, {'id': 1980, 'name': 'tuna', 'name_readable': 'Tuna', 'supercategory': 'food'}, {'id': 2131, 'name': 'dark-chocolate', 'name_readable': 'Dark chocolate', 'supercategory': 'food'}, {'id': 2711, 'name': 'sauce-savoury', 'name_readable': 'Sauce (savoury)', 'supercategory': 'food'}, {'id': 1199, 'name': 'dried-raisins', 'name_readable': 'Dried raisins', 'supercategory': 'food'}, {'id': 2470, 'name': 'ice-tea', 'name_readable': 'Ice tea', 'supercategory': 'food'}, {'id': 1174, 'name': 'kaki', 'name_readable': 'Kaki', 'supercategory': 'food'}, {'id': 2395, 'name': 'macaroon', 'name_readable': 'Macaroon', 'supercategory': 'food'}, {'id': 2461, 'name': 'smoothie', 'name_readable': 'Smoothie', 'supercategory': 'food'}, {'id': 2269, 'name': 'crepe-plain', 'name_readable': 'Crêpe, plain', 'supercategory': 'food'}, {'id': 1837, 'name': 'chicken-nuggets', 'name_readable': 'Chicken nuggets', 'supercategory': 'food'}, {'id': 2966, 'name': 'chili-con-carne-prepared', 'name_readable': 'Chili con carne, prepared', 'supercategory': 'food'}, {'id': 1942, 'name': 'veggie-burger', 'name_readable': 'Veggie burger', 'supercategory': 'food'}, {'id': 5792, 'name': 'cream-spinach', 'name_readable': 'Cream spinach', 'supercategory': 'food'}, {'id': 1958, 'name': 'cod', 'name_readable': 'Cod', 'supercategory': 'food'}, {'id': 1086, 'name': 'chinese-cabbage', 'name_readable': 'Chinese cabbage', 'supercategory': 'food'}, {'id': 2930, 'name': 'hamburger-bread-meat-ketchup', 'name_readable': 'Hamburger (Bread, meat, ketchup)', 'supercategory': 'food'}, {'id': 2841, 'name': 'soup-pumpkin', 'name_readable': 'Soup, pumpkin', 'supercategory': 'food'}, {'id': 2944, 'name': 'sushi', 'name_readable': 'Sushi', 'supercategory': 'food'}, {'id': 1204, 'name': 'chestnuts', 'name_readable': 'Chestnuts', 'supercategory': 'food'}, {'id': 2513, 'name': 'coffee-decaffeinated', 'name_readable': 'Coffee, decaffeinated', 'supercategory': 'food'}, {'id': 2807, 'name': 'sauce-soya', 'name_readable': 'Sauce, soya', 'supercategory': 'food'}, {'id': 2742, 'name': 'balsamic-salad-dressing', 'name_readable': 'Balsamic salad dressing', 'supercategory': 'food'}, {'id': 1506, 'name': 'pasta-twist', 'name_readable': 'Pasta, twist', 'supercategory': 'food'}, {'id': 2736, 'name': 'bolognaise-sauce', 'name_readable': 'Bolognaise sauce', 'supercategory': 'food'}, {'id': 1113, 'name': 'leek', 'name_readable': 'Leek', 'supercategory': 'food'}, {'id': 3221, 'name': 'fajita-bread-only', 'name_readable': 'Fajita (bread only)', 'supercategory': 'food'}, {'id': 1009, 'name': 'potato-gnocchi', 'name_readable': 'Potato-gnocchi', 'supercategory': 'food'}, {'id': 1731, 'name': 'beef-cut-into-stripes-only-meat', 'name_readable': 'Beef, cut into stripes (only meat)', 'supercategory': 'food'}, {'id': 1453, 'name': 'rice-noodles-vermicelli', 'name_readable': 'Rice noodles/vermicelli', 'supercategory': 'food'}, {'id': 2553, 'name': 'tea-ginger', 'name_readable': 'Tea, ginger', 'supercategory': 'food'}, {'id': 2530, 'name': 'tea-green', 'name_readable': 'Tea, green', 'supercategory': 'food'}, {'id': 1554, 'name': 'bread-whole-wheat', 'name_readable': 'Bread, whole wheat', 'supercategory': 'food'}, {'id': 1116, 'name': 'onion', 'name_readable': 'Onion', 'supercategory': 'food'}, {'id': 1112, 'name': 'garlic', 'name_readable': 'Garlic', 'supercategory': 'food'}, {'id': 2952, 'name': 'hummus', 'name_readable': 'Hummus', 'supercategory': 'food'}, {'id': 633, 'name': 'pizza-with-vegetables-baked', 'name_readable': 'Pizza, with vegetables, baked', 'supercategory': 'food'}, {'id': 2634, 'name': 'beer', 'name_readable': 'Beer', 'supercategory': 'food'}, {'id': 3080, 'name': 'glucose-drink-50g', 'name_readable': 'Glucose drink 50g', 'supercategory': 'food'}, {'id': 1791, 'name': 'chicken-wing', 'name_readable': 'Chicken, wing', 'supercategory': 'food'}, {'id': 1024, 'name': 'ratatouille', 'name_readable': 'Ratatouille', 'supercategory': 'food'}, {'id': 1214, 'name': 'peanut', 'name_readable': 'Peanut', 'supercategory': 'food'}, {'id': 8730, 'name': 'high-protein-pasta-made-of-lentils-peas', 'name_readable': 'High protein pasta (made of lentils, peas, ...)', 'supercategory': 'food'}, {'id': 1084, 'name': 'cauliflower', 'name_readable': 'Cauliflower', 'supercategory': 'food'}, {'id': 733, 'name': 'quiche-with-spinach-baked-with-cake-dough', 'name_readable': 'Quiche, with spinach, baked, with cake dough', 'supercategory': 'food'}, {'id': 1228, 'name': 'green-olives', 'name_readable': 'Green olives', 'supercategory': 'food'}, {'id': 1218, 'name': 'brazil-nut', 'name_readable': 'Brazil nut', 'supercategory': 'food'}, {'id': 2991, 'name': 'eggplant-caviar', 'name_readable': 'Eggplant caviar', 'supercategory': 'food'}, {'id': 1547, 'name': 'bread-pita', 'name_readable': 'Bread, pita', 'supercategory': 'food'}, {'id': 1513, 'name': 'pasta-wholemeal', 'name_readable': 'Pasta, wholemeal', 'supercategory': 'food'}, {'id': 2728, 'name': 'sauce-pesto', 'name_readable': 'Sauce, pesto', 'supercategory': 'food'}, {'id': 2031, 'name': 'oil', 'name_readable': 'Oil', 'supercategory': 'food'}, {'id': 1455, 'name': 'couscous', 'name_readable': 'Couscous', 'supercategory': 'food'}, {'id': 2714, 'name': 'sauce-roast', 'name_readable': 'Sauce, roast', 'supercategory': 'food'}, {'id': 2607, 'name': 'prosecco', 'name_readable': 'Prosecco', 'supercategory': 'food'}, {'id': 2899, 'name': 'crackers', 'name_readable': 'Crackers', 'supercategory': 'food'}, {'id': 1560, 'name': 'bread-toast', 'name_readable': 'Bread, toast', 'supercategory': 'food'}, {'id': 1985, 'name': 'shrimp-prawn-small', 'name_readable': 'Shrimp / prawn (small)', 'supercategory': 'food'}, {'id': 1367, 'name': 'panna-cotta', 'name_readable': 'Panna cotta', 'supercategory': 'food'}, {'id': 1090, 'name': 'romanesco', 'name_readable': 'Romanesco', 'supercategory': 'food'}, {'id': 3262, 'name': 'water-with-lemon-juice', 'name_readable': 'Water with lemon juice', 'supercategory': 'food'}, {'id': 2504, 'name': 'espresso-with-caffeine', 'name_readable': 'Espresso, with caffeine', 'supercategory': 'food'}, {'id': 3042, 'name': 'egg-scrambled-prepared', 'name_readable': 'Egg, scrambled, prepared', 'supercategory': 'food'}, {'id': 2454, 'name': 'juice-orange', 'name_readable': 'Juice, orange', 'supercategory': 'food'}, {'id': 2577, 'name': 'ice-cubes', 'name_readable': 'Ice cubes', 'supercategory': 'food'}, {'id': 1607, 'name': 'braided-white-loaf', 'name_readable': 'Braided white loaf', 'supercategory': 'food'}, {'id': 1293, 'name': 'emmental-cheese', 'name_readable': 'Emmental cheese', 'supercategory': 'food'}, {'id': 1592, 'name': 'croissant-wholegrain', 'name_readable': 'Croissant, wholegrain', 'supercategory': 'food'}, {'id': 2172, 'name': 'hazelnut-chocolate-spread-nutella-ovomaltine-caotina', 'name_readable': 'Hazelnut-chocolate spread(Nutella, Ovomaltine, Caotina)', 'supercategory': 'food'}, {'id': 1348, 'name': 'tomme', 'name_readable': 'Tomme', 'supercategory': 'food'}, {'id': 2580, 'name': 'water-mineral', 'name_readable': 'Water, mineral', 'supercategory': 'food'}, {'id': 1215, 'name': 'hazelnut', 'name_readable': 'Hazelnut', 'supercategory': 'food'}, {'id': 1917, 'name': 'bacon-raw', 'name_readable': 'Bacon, raw', 'supercategory': 'food'}, {'id': 1545, 'name': 'bread-nut', 'name_readable': 'Bread, nut', 'supercategory': 'food'}, {'id': 2340, 'name': 'black-forest-tart', 'name_readable': 'Black Forest Tart', 'supercategory': 'food'}, {'id': 2846, 'name': 'soup-miso', 'name_readable': 'Soup, Miso', 'supercategory': 'food'}, {'id': 1190, 'name': 'peach', 'name_readable': 'Peach', 'supercategory': 'food'}, {'id': 1164, 'name': 'figs', 'name_readable': 'Figs', 'supercategory': 'food'}, {'id': 1728, 'name': 'beef-filet', 'name_readable': 'Beef, filet', 'supercategory': 'food'}, {'id': 2811, 'name': 'mustard-dijon', 'name_readable': 'Mustard, Dijon', 'supercategory': 'food'}, {'id': 1469, 'name': 'rice-basmati', 'name_readable': 'Rice, Basmati', 'supercategory': 'food'}, {'id': 2935, 'name': 'mashed-potatoes-prepared-with-full-fat-milk-with-butter', 'name_readable': 'Mashed potatoes, prepared, with full fat milk, with butter', 'supercategory': 'food'}, {'id': 2959, 'name': 'dumplings', 'name_readable': 'Dumplings', 'supercategory': 'food'}, {'id': 1065, 'name': 'pumpkin', 'name_readable': 'Pumpkin', 'supercategory': 'food'}, {'id': 1120, 'name': 'swiss-chard', 'name_readable': 'Swiss chard', 'supercategory': 'food'}, {'id': 1092, 'name': 'red-cabbage', 'name_readable': 'Red cabbage', 'supercategory': 'food'}, {'id': 282, 'name': 'spinach-raw', 'name_readable': 'Spinach, raw', 'supercategory': 'food'}, {'id': 3248, 'name': 'naan-indien-bread', 'name_readable': 'Naan (indien bread)', 'supercategory': 'food'}, {'id': 3100, 'name': 'chicken-curry-cream-coconut-milk-curry-spices-paste', 'name_readable': 'Chicken curry (cream/coconut milk. curry spices/paste))', 'supercategory': 'food'}, {'id': 1627, 'name': 'crunch-muesli', 'name_readable': 'Crunch Müesli', 'supercategory': 'food'}, {'id': 2388, 'name': 'biscuits', 'name_readable': 'Biscuits', 'supercategory': 'food'}, {'id': 1520, 'name': 'bread-french-white-flour', 'name_readable': 'Bread, French (white flour)', 'supercategory': 'food'}, {'id': 1845, 'name': 'meatloaf', 'name_readable': 'Meatloaf', 'supercategory': 'food'}, {'id': 1300, 'name': 'fresh-cheese', 'name_readable': 'Fresh cheese', 'supercategory': 'food'}, {'id': 2103, 'name': 'honey', 'name_readable': 'Honey', 'supercategory': 'food'}, {'id': 1019, 'name': 'vegetable-mix-peas-and-carrots', 'name_readable': 'Vegetable mix, peas and carrots', 'supercategory': 'food'}, {'id': 2773, 'name': 'parsley', 'name_readable': 'Parsley', 'supercategory': 'food'}, {'id': 2254, 'name': 'brownie', 'name_readable': 'Brownie', 'supercategory': 'food'}, {'id': 1402, 'name': 'dairy-ice-cream', 'name_readable': 'Dairy ice cream', 'supercategory': 'food'}, {'id': 2534, 'name': 'tea-black', 'name_readable': 'Tea, black', 'supercategory': 'food'}, {'id': 2333, 'name': 'carrot-cake', 'name_readable': 'Carrot cake', 'supercategory': 'food'}, {'id': 2003, 'name': 'fish-fingers-breaded', 'name_readable': 'Fish fingers (breaded)', 'supercategory': 'food'}, {'id': 2741, 'name': 'salad-dressing', 'name_readable': 'Salad dressing', 'supercategory': 'food'}, {'id': 1853, 'name': 'dried-meat', 'name_readable': 'Dried meat', 'supercategory': 'food'}, {'id': 1789, 'name': 'chicken-breast', 'name_readable': 'Chicken, breast', 'supercategory': 'food'}, {'id': 1026, 'name': 'mixed-salad-chopped-without-sauce', 'name_readable': 'Mixed salad (chopped without sauce)', 'supercategory': 'food'}, {'id': 1294, 'name': 'feta', 'name_readable': 'Feta', 'supercategory': 'food'}, {'id': 2073, 'name': 'praline', 'name_readable': 'Praline', 'supercategory': 'food'}, {'id': 2562, 'name': 'tea-peppermint', 'name_readable': 'Tea, peppermint', 'supercategory': 'food'}, {'id': 1212, 'name': 'walnut', 'name_readable': 'Walnut', 'supercategory': 'food'}, {'id': 780, 'name': 'potato-salad-with-mayonnaise-yogurt-dressing', 'name_readable': 'Potato salad, with mayonnaise yogurt dressing', 'supercategory': 'food'}, {'id': 2947, 'name': 'kebab-in-pita-bread', 'name_readable': 'Kebab in pita bread', 'supercategory': 'food'}, {'id': 1089, 'name': 'kolhrabi', 'name_readable': 'Kolhrabi', 'supercategory': 'food'}, {'id': 1126, 'name': 'alfa-sprouts', 'name_readable': 'Alfa sprouts', 'supercategory': 'food'}, {'id': 1091, 'name': 'brussel-sprouts', 'name_readable': 'Brussel sprouts', 'supercategory': 'food'}, {'id': 1916, 'name': 'bacon-cooking', 'name_readable': 'Bacon, cooking', 'supercategory': 'food'}, {'id': 1307, 'name': 'gruyere', 'name_readable': 'Gruyère', 'supercategory': 'food'}, {'id': 1454, 'name': 'bulgur', 'name_readable': 'Bulgur', 'supercategory': 'food'}, {'id': 1198, 'name': 'grapes', 'name_readable': 'Grapes', 'supercategory': 'food'}, {'id': 1760, 'name': 'pork-escalope', 'name_readable': 'Pork, escalope', 'supercategory': 'food'}, {'id': 2194, 'name': 'chocolate-egg-small', 'name_readable': 'Chocolate egg, small', 'supercategory': 'food'}, {'id': 2501, 'name': 'cappuccino', 'name_readable': 'Cappuccino', 'supercategory': 'food'}, {'id': 232, 'name': 'zucchini-stewed-without-addition-of-fat-without-addition-of-salt', 'name_readable': 'Zucchini, stewed, without addition of fat, without addition of salt', 'supercategory': 'food'}, {'id': 1612, 'name': 'crisp-bread-wasa', 'name_readable': 'Crisp bread, Wasa', 'supercategory': 'food'}, {'id': 1557, 'name': 'bread-black', 'name_readable': 'Bread, black', 'supercategory': 'food'}, {'id': 2968, 'name': 'perch-fillets-lake', 'name_readable': 'Perch fillets (lake)', 'supercategory': 'food'}, {'id': 1014, 'name': 'rosti', 'name_readable': 'Rosti', 'supercategory': 'food'}, {'id': 1181, 'name': 'mango', 'name_readable': 'Mango', 'supercategory': 'food'}, {'id': 2941, 'name': 'sandwich-ham-cheese-and-butter', 'name_readable': 'Sandwich (ham, cheese and butter)', 'supercategory': 'food'}, {'id': 1670, 'name': 'muesli', 'name_readable': 'Müesli', 'supercategory': 'food'}, {'id': 281, 'name': 'spinach-steamed-without-addition-of-salt', 'name_readable': 'Spinach, steamed, without addition of salt', 'supercategory': 'food'}, {'id': 1956, 'name': 'fish', 'name_readable': 'Fish', 'supercategory': 'food'}, {'id': 2970, 'name': 'risotto-without-cheese-cooked', 'name_readable': 'Risotto, without cheese, cooked', 'supercategory': 'food'}, {'id': 5618, 'name': 'milk-chocolate-with-hazelnuts', 'name_readable': 'Milk Chocolate with hazelnuts', 'supercategory': 'food'}, {'id': 2259, 'name': 'cake-oblong', 'name_readable': 'Cake (oblong)', 'supercategory': 'food'}, {'id': 2905, 'name': 'crisps', 'name_readable': 'Crisps', 'supercategory': 'food'}, {'id': 1748, 'name': 'pork', 'name_readable': 'Pork', 'supercategory': 'food'}, {'id': 1152, 'name': 'pomegranate', 'name_readable': 'Pomegranate', 'supercategory': 'food'}, {'id': 483, 'name': 'sweet-corn-canned', 'name_readable': 'Sweet corn, canned', 'supercategory': 'food'}, {'id': 1422, 'name': 'flakes-oat', 'name_readable': 'Flakes, oat', 'supercategory': 'food'}, {'id': 2954, 'name': 'greek-salad', 'name_readable': 'Greek salad', 'supercategory': 'food'}, {'id': 5812, 'name': 'cantonese-fried-rice', 'name_readable': 'Cantonese fried rice', 'supercategory': 'food'}, {'id': 1223, 'name': 'sesame-seeds', 'name_readable': 'Sesame seeds', 'supercategory': 'food'}, {'id': 2855, 'name': 'bouillon', 'name_readable': 'Bouillon', 'supercategory': 'food'}, {'id': 10626, 'name': 'baked-potato', 'name_readable': 'Baked potato', 'supercategory': 'food'}, {'id': 1119, 'name': 'fennel', 'name_readable': 'Fennel', 'supercategory': 'food'}, {'id': 1707, 'name': 'meat', 'name_readable': 'Meat', 'supercategory': 'food'}, {'id': 1546, 'name': 'bread-olive', 'name_readable': 'Bread, olive', 'supercategory': 'food'}, {'id': 2900, 'name': 'croutons', 'name_readable': 'Croutons', 'supercategory': 'food'}, {'id': 1325, 'name': 'philadelphia', 'name_readable': 'Philadelphia', 'supercategory': 'food'}, {'id': 158, 'name': 'mushroom-average-stewed-without-addition-of-fat-without-addition-of-salt', 'name_readable': 'Mushroom, (average), stewed, without addition of fat, without addition of salt', 'supercategory': 'food'}, {'id': 656, 'name': 'bell-pepper-red-stewed-without-addition-of-fat-without-addition-of-salt', 'name_readable': 'Bell pepper, red, stewed, without addition of fat, without addition of salt', 'supercategory': 'food'}, {'id': 2133, 'name': 'white-chocolate', 'name_readable': 'White chocolate', 'supercategory': 'food'}, {'id': 1220, 'name': 'mixed-nuts', 'name_readable': 'Mixed nuts', 'supercategory': 'food'}, {'id': 1614, 'name': 'breadcrumbs-unspiced', 'name_readable': 'Breadcrumbs (unspiced)', 'supercategory': 'food'}, {'id': 1295, 'name': 'fondue', 'name_readable': 'Fondue', 'supercategory': 'food'}, {'id': 2729, 'name': 'sauce-mushroom', 'name_readable': 'Sauce, mushroom', 'supercategory': 'food'}, {'id': 2548, 'name': 'tea-spice', 'name_readable': 'Tea, spice', 'supercategory': 'food'}, {'id': 1163, 'name': 'strawberries', 'name_readable': 'Strawberries', 'supercategory': 'food'}, {'id': 2563, 'name': 'tea-rooibos', 'name_readable': 'Tea, rooibos', 'supercategory': 'food'}, {'id': 3101, 'name': 'pie-plum-baked-with-cake-dough', 'name_readable': 'Pie, plum, baked, with cake dough', 'supercategory': 'food'}, {'id': 3115, 'name': 'potatoes-au-gratin-dauphinois-prepared', 'name_readable': 'Potatoes au gratin, dauphinois, prepared', 'supercategory': 'food'}, {'id': 1062, 'name': 'capers', 'name_readable': 'Capers', 'supercategory': 'food'}, {'id': 1021, 'name': 'vegetables', 'name_readable': 'Vegetables', 'supercategory': 'food'}, {'id': 1561, 'name': 'bread-wholemeal-toast', 'name_readable': 'Bread, wholemeal toast', 'supercategory': 'food'}, {'id': 1074, 'name': 'red-radish', 'name_readable': 'Red radish', 'supercategory': 'food'}, {'id': 2278, 'name': 'fruit-tart', 'name_readable': 'Fruit tart', 'supercategory': 'food'}, {'id': 1138, 'name': 'beans-kidney', 'name_readable': 'Beans, kidney', 'supercategory': 'food'}, {'id': 1093, 'name': 'sauerkraut', 'name_readable': 'Sauerkraut', 'supercategory': 'food'}, {'id': 2810, 'name': 'mustard', 'name_readable': 'Mustard', 'supercategory': 'food'}, {'id': 1007, 'name': 'country-fries', 'name_readable': 'Country fries', 'supercategory': 'food'}, {'id': 2734, 'name': 'ketchup', 'name_readable': 'Ketchup', 'supercategory': 'food'}, {'id': 1490, 'name': 'pasta-linguini-parpadelle-tagliatelle', 'name_readable': 'Pasta, linguini, parpadelle, Tagliatelle', 'supercategory': 'food'}, {'id': 1793, 'name': 'chicken-cut-into-stripes-only-meat', 'name_readable': 'Chicken, cut into stripes (only meat)', 'supercategory': 'food'}, {'id': 2376, 'name': 'cookies', 'name_readable': 'Cookies', 'supercategory': 'food'}, {'id': 3293, 'name': 'sun-dried-tomatoe', 'name_readable': 'Sun-dried tomatoe', 'supercategory': 'food'}, {'id': 1559, 'name': 'bread-ticino', 'name_readable': 'Bread, Ticino', 'supercategory': 'food'}, {'id': 1308, 'name': 'semi-hard-cheese', 'name_readable': 'Semi-hard cheese', 'supercategory': 'food'}, {'id': 2062, 'name': 'margarine', 'name_readable': 'Margarine', 'supercategory': 'food'}, {'id': 3615, 'name': 'porridge-prepared-with-partially-skimmed-milk', 'name_readable': 'Porridge, prepared, with partially skimmed milk', 'supercategory': 'food'}, {'id': 1256, 'name': 'soya-drink-soy-milk', 'name_readable': 'Soya drink (soy milk)', 'supercategory': 'food'}, {'id': 2452, 'name': 'juice-multifruit', 'name_readable': 'Juice, multifruit', 'supercategory': 'food'}, {'id': 2906, 'name': 'popcorn-salted', 'name_readable': 'Popcorn salted', 'supercategory': 'food'}, {'id': 2135, 'name': 'chocolate-filled', 'name_readable': 'Chocolate, filled', 'supercategory': 'food'}, {'id': 2132, 'name': 'milk-chocolate', 'name_readable': 'Milk chocolate', 'supercategory': 'food'}, {'id': 1533, 'name': 'bread-fruit', 'name_readable': 'Bread, fruit', 'supercategory': 'food'}, {'id': 9594, 'name': 'mix-of-dried-fruits-and-nuts', 'name_readable': 'Mix of dried fruits and nuts', 'supercategory': 'food'}, {'id': 1108, 'name': 'corn', 'name_readable': 'Corn', 'supercategory': 'food'}, {'id': 1346, 'name': 'tete-de-moine', 'name_readable': 'Tête de Moine', 'supercategory': 'food'}, {'id': 1162, 'name': 'dates', 'name_readable': 'Dates', 'supercategory': 'food'}, {'id': 1221, 'name': 'pistachio', 'name_readable': 'Pistachio', 'supercategory': 'food'}, {'id': 1130, 'name': 'celery', 'name_readable': 'Celery', 'supercategory': 'food'}, {'id': 1076, 'name': 'white-radish', 'name_readable': 'White radish', 'supercategory': 'food'}, {'id': 3046, 'name': 'oat-milk', 'name_readable': 'Oat milk', 'supercategory': 'food'}, {'id': 1328, 'name': 'cream-cheese', 'name_readable': 'Cream cheese', 'supercategory': 'food'}, {'id': 1551, 'name': 'bread-rye', 'name_readable': 'Bread, rye', 'supercategory': 'food'}, {'id': 1033, 'name': 'witloof-chicory', 'name_readable': 'Witloof chicory', 'supercategory': 'food'}, {'id': 2994, 'name': 'apple-crumble', 'name_readable': 'Apple crumble', 'supercategory': 'food'}, {'id': 6404, 'name': 'goat-cheese-soft', 'name_readable': 'Goat cheese (soft)', 'supercategory': 'food'}, {'id': 1167, 'name': 'grapefruit-pomelo', 'name_readable': 'Grapefruit, pomelo', 'supercategory': 'food'}, {'id': 752, 'name': 'risotto-with-mushrooms-cooked', 'name_readable': 'Risotto, with mushrooms, cooked', 'supercategory': 'food'}, {'id': 1280, 'name': 'blue-mould-cheese', 'name_readable': 'Blue mould cheese', 'supercategory': 'food'}, {'id': 2408, 'name': 'biscuit-with-butter', 'name_readable': 'Biscuit with Butter', 'supercategory': 'food'}, {'id': 2749, 'name': 'guacamole', 'name_readable': 'Guacamole', 'supercategory': 'food'}, {'id': 1219, 'name': 'pecan-nut', 'name_readable': 'Pecan nut', 'supercategory': 'food'}, {'id': 1948, 'name': 'tofu', 'name_readable': 'Tofu', 'supercategory': 'food'}, {'id': 2932, 'name': 'cordon-bleu-from-pork-schnitzel-fried', 'name_readable': 'Cordon bleu, from pork schnitzel, fried', 'supercategory': 'food'}, {'id': 5689, 'name': 'paprika-chips', 'name_readable': 'Paprika chips', 'supercategory': 'food'}, {'id': 1467, 'name': 'quinoa', 'name_readable': 'Quinoa', 'supercategory': 'food'}, {'id': 1249, 'name': 'kefir-drink', 'name_readable': 'Kefir drink', 'supercategory': 'food'}, {'id': 2184, 'name': 'm-m-s', 'name_readable': "M&M's", 'supercategory': 'food'}, {'id': 1038, 'name': 'salad-rocket', 'name_readable': 'Salad, rocket', 'supercategory': 'food'}, {'id': 1528, 'name': 'bread-spelt', 'name_readable': 'Bread, spelt', 'supercategory': 'food'}, {'id': 629, 'name': 'pizza-with-ham-with-mushrooms-baked', 'name_readable': 'Pizza, with ham, with mushrooms, baked', 'supercategory': 'food'}, {'id': 3308, 'name': 'fruit-coulis', 'name_readable': 'Fruit coulis', 'supercategory': 'food'}, {'id': 1191, 'name': 'plums', 'name_readable': 'Plums', 'supercategory': 'food'}, {'id': 1730, 'name': 'beef-minced-only-meat', 'name_readable': 'Beef, minced (only meat)', 'supercategory': 'food'}, {'id': 630, 'name': 'pizza-with-ham-baked', 'name_readable': 'Pizza, with ham, baked', 'supercategory': 'food'}, {'id': 1150, 'name': 'pineapple', 'name_readable': 'Pineapple', 'supercategory': 'food'}, {'id': 2852, 'name': 'soup-tomato', 'name_readable': 'Soup, tomato', 'supercategory': 'food'}, {'id': 1290, 'name': 'cheddar', 'name_readable': 'Cheddar', 'supercategory': 'food'}, {'id': 2546, 'name': 'tea-fruit', 'name_readable': 'Tea, fruit', 'supercategory': 'food'}, {'id': 1471, 'name': 'rice-jasmin', 'name_readable': 'Rice, Jasmin', 'supercategory': 'food'}, {'id': 1205, 'name': 'seeds', 'name_readable': 'Seeds', 'supercategory': 'food'}, {'id': 1587, 'name': 'focaccia', 'name_readable': 'Focaccia', 'supercategory': 'food'}, {'id': 1237, 'name': 'milk', 'name_readable': 'Milk', 'supercategory': 'food'}, {'id': 1020, 'name': 'coleslaw-chopped-without-sauce', 'name_readable': 'Coleslaw (chopped without sauce)', 'supercategory': 'food'}, {'id': 1696, 'name': 'pastry-flaky', 'name_readable': 'Pastry, flaky', 'supercategory': 'food'}, {'id': 1266, 'name': 'curd', 'name_readable': 'Curd', 'supercategory': 'food'}, {'id': 2896, 'name': 'savoury-puff-pastry-stick', 'name_readable': 'Savoury puff pastry stick', 'supercategory': 'food'}, {'id': 1004, 'name': 'sweet-potato', 'name_readable': 'Sweet potato', 'supercategory': 'food'}, {'id': 1794, 'name': 'chicken-leg', 'name_readable': 'Chicken, leg', 'supercategory': 'food'}, {'id': 1588, 'name': 'croissant', 'name_readable': 'Croissant', 'supercategory': 'food'}, {'id': 1383, 'name': 'sour-cream', 'name_readable': 'Sour cream', 'supercategory': 'food'}, {'id': 1895, 'name': 'ham-turkey', 'name_readable': 'Ham, turkey', 'supercategory': 'food'}, {'id': 1337, 'name': 'processed-cheese', 'name_readable': 'Processed cheese', 'supercategory': 'food'}, {'id': 3474, 'name': 'fruit-compotes', 'name_readable': 'Fruit compotes', 'supercategory': 'food'}, {'id': 2962, 'name': 'cheesecake', 'name_readable': 'Cheesecake', 'supercategory': 'food'}, {'id': 1509, 'name': 'pasta-tortelloni-stuffing', 'name_readable': 'Pasta, tortelloni, stuffing', 'supercategory': 'food'}, {'id': 2718, 'name': 'sauce-cocktail', 'name_readable': 'Sauce, cocktail', 'supercategory': 'food'}, {'id': 2362, 'name': 'croissant-with-chocolate-filling', 'name_readable': 'Croissant with chocolate filling', 'supercategory': 'food'}, {'id': 1206, 'name': 'pumpkin-seeds', 'name_readable': 'Pumpkin seeds', 'supercategory': 'food'}, {'id': 1054, 'name': 'artichoke', 'name_readable': 'Artichoke', 'supercategory': 'food'}, {'id': 2605, 'name': 'champagne', 'name_readable': 'Champagne', 'supercategory': 'food'}, {'id': 1616, 'name': 'grissini', 'name_readable': 'Grissini', 'supercategory': 'food'}, {'id': 2203, 'name': 'sweets-candies', 'name_readable': 'Sweets / candies', 'supercategory': 'food'}, {'id': 1282, 'name': 'brie', 'name_readable': 'Brie', 'supercategory': 'food'}, {'id': 843, 'name': 'wienerli-swiss-sausage', 'name_readable': 'Wienerli (Swiss sausage)', 'supercategory': 'food'}, {'id': 2495, 'name': 'syrup-diluted-ready-to-drink', 'name_readable': 'Syrup (diluted, ready to drink)', 'supercategory': 'food'}, {'id': 2237, 'name': 'apple-pie', 'name_readable': 'Apple pie', 'supercategory': 'food'}, {'id': 1584, 'name': 'white-bread-with-butter-eggs-and-milk', 'name_readable': 'White bread with butter, eggs and milk', 'supercategory': 'food'}, {'id': 2895, 'name': 'savoury-puff-pastry', 'name_readable': 'Savoury puff pastry', 'supercategory': 'food'}, {'id': 1975, 'name': 'anchovies', 'name_readable': 'Anchovies', 'supercategory': 'food'}, {'id': 922, 'name': 'tuna-in-oil-drained', 'name_readable': 'Tuna, in oil, drained', 'supercategory': 'food'}, {'id': 3055, 'name': 'lemon-pie', 'name_readable': 'Lemon pie', 'supercategory': 'food'}, {'id': 1919, 'name': 'meat-terrine-pate', 'name_readable': 'Meat terrine, paté', 'supercategory': 'food'}, {'id': 2767, 'name': 'coriander', 'name_readable': 'Coriander', 'supercategory': 'food'}, {'id': 2873, 'name': 'falafel-balls', 'name_readable': 'Falafel (balls)', 'supercategory': 'food'}, {'id': 1156, 'name': 'berries', 'name_readable': 'Berries', 'supercategory': 'food'}, {'id': 2518, 'name': 'latte-macchiato-with-caffeine', 'name_readable': 'Latte macchiato, with caffeine', 'supercategory': 'food'}, {'id': 5247, 'name': 'faux-mage-cashew-vegan-chers', 'name_readable': 'Faux-mage Cashew, vegan chers', 'supercategory': 'food'}, {'id': 1141, 'name': 'beans-white', 'name_readable': 'Beans, white', 'supercategory': 'food'}, {'id': 1184, 'name': 'sugar-melon', 'name_readable': 'Sugar Melon', 'supercategory': 'food'}, {'id': 1209, 'name': 'mixed-seeds', 'name_readable': 'Mixed seeds', 'supercategory': 'food'}, {'id': 1849, 'name': 'hamburger', 'name_readable': 'Hamburger', 'supercategory': 'food'}, {'id': 1572, 'name': 'hamburger-bun', 'name_readable': 'Hamburger bun', 'supercategory': 'food'}, {'id': 2747, 'name': 'oil-vinegar-salad-dressing', 'name_readable': 'Oil & vinegar salad dressing', 'supercategory': 'food'}, {'id': 1257, 'name': 'soya-yaourt-yahourt-yogourt-ou-yoghourt', 'name_readable': 'Soya Yaourt, yahourt, yogourt ou yoghourt', 'supercategory': 'food'}, {'id': 3258, 'name': 'chocolate-milk-chocolate-drink', 'name_readable': 'Chocolate milk, chocolate drink', 'supercategory': 'food'}, {'id': 1082, 'name': 'celeriac', 'name_readable': 'Celeriac', 'supercategory': 'food'}, {'id': 2961, 'name': 'chocolate-mousse', 'name_readable': 'Chocolate mousse', 'supercategory': 'food'}, {'id': 2791, 'name': 'cenovis-yeast-spread', 'name_readable': 'Cenovis, yeast spread', 'supercategory': 'food'}, {'id': 1384, 'name': 'thickened-cream-35', 'name_readable': 'Thickened cream (> 35%)', 'supercategory': 'food'}, {'id': 2400, 'name': 'meringue', 'name_readable': 'Meringue', 'supercategory': 'food'}, {'id': 1770, 'name': 'lamb-chop', 'name_readable': 'Lamb, chop', 'supercategory': 'food'}, {'id': 1986, 'name': 'shrimp-prawn-large', 'name_readable': 'Shrimp / prawn (large)', 'supercategory': 'food'}, {'id': 1724, 'name': 'beef', 'name_readable': 'Beef', 'supercategory': 'food'}, {'id': 1200, 'name': 'lemon', 'name_readable': 'Lemon', 'supercategory': 'food'}, {'id': 2913, 'name': 'croque-monsieur', 'name_readable': 'Croque monsieur', 'supercategory': 'food'}, {'id': 2778, 'name': 'chives', 'name_readable': 'Chives', 'supercategory': 'food'}, {'id': 2413, 'name': 'chocolate-cookies', 'name_readable': 'Chocolate cookies', 'supercategory': 'food'}, {'id': 3220, 'name': 'birchermuesli-prepared-no-sugar-added', 'name_readable': 'Birchermüesli, prepared, no sugar added', 'supercategory': 'food'}, {'id': 2002, 'name': 'fish-crunchies-battered', 'name_readable': 'Fish crunchies (battered)', 'supercategory': 'food'}, {'id': 2312, 'name': 'muffin', 'name_readable': 'Muffin', 'supercategory': 'food'}, {'id': 198, 'name': 'savoy-cabbage-steamed-without-addition-of-salt', 'name_readable': 'Savoy cabbage, steamed, without addition of salt', 'supercategory': 'food'}, {'id': 1207, 'name': 'pine-nuts', 'name_readable': 'Pine nuts', 'supercategory': 'food'}, {'id': 1838, 'name': 'chorizo', 'name_readable': 'Chorizo', 'supercategory': 'food'}, {'id': 4338, 'name': 'chia-grains', 'name_readable': 'Chia grains', 'supercategory': 'food'}, {'id': 1831, 'name': 'frying-sausage', 'name_readable': 'Frying sausage', 'supercategory': 'food'}, {'id': 3417, 'name': 'french-pizza-from-alsace-baked', 'name_readable': 'French pizza from Alsace, baked', 'supercategory': 'food'}, {'id': 2134, 'name': 'chocolate', 'name_readable': 'Chocolate', 'supercategory': 'food'}, {'id': 1883, 'name': 'cooked-sausage', 'name_readable': 'Cooked sausage', 'supercategory': 'food'}, {'id': 1463, 'name': 'grits-polenta-maize-flour', 'name_readable': 'Grits, polenta, maize flour', 'supercategory': 'food'}, {'id': 2211, 'name': 'gummi-bears-fruit-jellies-jelly-babies-with-fruit-essence', 'name_readable': 'Gummi bears, fruit jellies, Jelly babies with fruit essence', 'supercategory': 'food'}, {'id': 2616, 'name': 'wine-rose', 'name_readable': 'Wine, rosé', 'supercategory': 'food'}, {'id': 2467, 'name': 'coca-cola', 'name_readable': 'Coca Cola', 'supercategory': 'food'}, {'id': 1170, 'name': 'raspberries', 'name_readable': 'Raspberries', 'supercategory': 'food'}, {'id': 1580, 'name': 'roll-with-pieces-of-chocolate', 'name_readable': 'Roll with pieces of chocolate', 'supercategory': 'food'}, {'id': 3082, 'name': 'goat-average-raw', 'name_readable': 'Goat, (average), raw', 'supercategory': 'food'}, {'id': 2262, 'name': 'lemon-cake', 'name_readable': 'Lemon Cake', 'supercategory': 'food'}, {'id': 1253, 'name': 'coconut-milk', 'name_readable': 'Coconut milk', 'supercategory': 'food'}, {'id': 1479, 'name': 'rice-wild', 'name_readable': 'Rice, wild', 'supercategory': 'food'}, {'id': 3306, 'name': 'gluten-free-bread', 'name_readable': 'Gluten-free bread', 'supercategory': 'food'}, {'id': 1115, 'name': 'pearl-onions', 'name_readable': 'Pearl onions', 'supercategory': 'food'}, {'id': 7504, 'name': 'buckwheat-pancake', 'name_readable': 'Buckwheat pancake', 'supercategory': 'food'}, {'id': 1523, 'name': 'bread-5-grain', 'name_readable': 'Bread, 5-grain', 'supercategory': 'food'}, {'id': 2636, 'name': 'light-beer', 'name_readable': 'Light beer', 'supercategory': 'food'}, {'id': 2113, 'name': 'sugar-glazing', 'name_readable': 'Sugar, glazing', 'supercategory': 'food'}, {'id': 2752, 'name': 'tzatziki', 'name_readable': 'Tzatziki', 'supercategory': 'food'}, {'id': 2056, 'name': 'butter-herb', 'name_readable': 'Butter, herb', 'supercategory': 'food'}, {'id': 2920, 'name': 'ham-croissant', 'name_readable': 'Ham croissant', 'supercategory': 'food'}, {'id': 2898, 'name': 'corn-crisps', 'name_readable': 'Corn crisps', 'supercategory': 'food'}, {'id': 3230, 'name': 'lentils-green-du-puy-du-berry', 'name_readable': 'Lentils green (du Puy, du Berry)', 'supercategory': 'food'}, {'id': 2588, 'name': 'cocktail', 'name_readable': 'Cocktail', 'supercategory': 'food'}, {'id': 1478, 'name': 'rice-whole-grain', 'name_readable': 'Rice, whole-grain', 'supercategory': 'food'}, {'id': 1856, 'name': 'veal-sausage', 'name_readable': 'Veal sausage', 'supercategory': 'food'}, {'id': 1835, 'name': 'cervelat', 'name_readable': 'Cervelat', 'supercategory': 'food'}, {'id': 1411, 'name': 'sorbet', 'name_readable': 'Sorbet', 'supercategory': 'food'}, {'id': 2585, 'name': 'aperitif-with-alcohol-aperol-spritz', 'name_readable': 'Aperitif, with alcohol, apérol, Spritz', 'supercategory': 'food'}, {'id': 2740, 'name': 'dips', 'name_readable': 'Dips', 'supercategory': 'food'}, {'id': 1626, 'name': 'corn-flakes', 'name_readable': 'Corn Flakes', 'supercategory': 'food'}, {'id': 1107, 'name': 'peas', 'name_readable': 'Peas', 'supercategory': 'food'}, {'id': 1371, 'name': 'tiramisu', 'name_readable': 'Tiramisu', 'supercategory': 'food'}, {'id': 1153, 'name': 'apricots', 'name_readable': 'Apricots', 'supercategory': 'food'}, {'id': 2300, 'name': 'cake-marble', 'name_readable': 'Cake, marble', 'supercategory': 'food'}, {'id': 1765, 'name': 'lamb', 'name_readable': 'Lamb', 'supercategory': 'food'}, {'id': 2934, 'name': 'lasagne-meat-prepared', 'name_readable': 'Lasagne, meat, prepared', 'supercategory': 'food'}, {'id': 2468, 'name': 'coca-cola-zero', 'name_readable': 'Coca Cola Zero', 'supercategory': 'food'}, {'id': 3337, 'name': 'cake-salted', 'name_readable': 'Cake, salted', 'supercategory': 'food'}, {'id': 1695, 'name': 'dough-puff-pastry-shortcrust-bread-pizza-dough', 'name_readable': 'Dough (puff pastry, shortcrust, bread, pizza dough)', 'supercategory': 'food'}, {'id': 1615, 'name': 'rice-waffels', 'name_readable': 'Rice waffels', 'supercategory': 'food'}, {'id': 2610, 'name': 'sekt', 'name_readable': 'Sekt', 'supercategory': 'food'}, {'id': 1568, 'name': 'brioche', 'name_readable': 'Brioche', 'supercategory': 'food'}, {'id': 3532, 'name': 'vegetable-au-gratin-baked', 'name_readable': 'Vegetable au gratin, baked', 'supercategory': 'food'}, {'id': 3228, 'name': 'mango-dried', 'name_readable': 'Mango dried', 'supercategory': 'food'}, {'id': 1857, 'name': 'processed-meat-charcuterie', 'name_readable': 'Processed meat, Charcuterie', 'supercategory': 'food'}, {'id': 1366, 'name': 'mousse', 'name_readable': 'Mousse', 'supercategory': 'food'}, {'id': 2731, 'name': 'sauce-sweet-sour', 'name_readable': 'Sauce, sweet & sour', 'supercategory': 'food'}, {'id': 2760, 'name': 'basil', 'name_readable': 'Basil', 'supercategory': 'food'}, {'id': 3249, 'name': 'butter-spread-puree-almond', 'name_readable': 'Butter, spread, puree almond', 'supercategory': 'food'}, {'id': 2990, 'name': 'pie-apricot-baked-with-cake-dough', 'name_readable': 'Pie, apricot, baked, with cake dough', 'supercategory': 'food'}, {'id': 1620, 'name': 'rusk-wholemeal', 'name_readable': 'Rusk, wholemeal', 'supercategory': 'food'}, {'id': 1725, 'name': 'beef-roast', 'name_readable': 'Beef, roast', 'supercategory': 'food'}, {'id': 236, 'name': 'vanille-cream-cooked-custard-creme-dessert', 'name_readable': 'Vanille cream, cooked, Custard, Crème dessert', 'supercategory': 'food'}, {'id': 1492, 'name': 'pasta-in-conch-form', 'name_readable': 'Pasta in conch form', 'supercategory': 'food'}, {'id': 1211, 'name': 'nuts', 'name_readable': 'Nuts', 'supercategory': 'food'}, {'id': 2716, 'name': 'sauce-carbonara', 'name_readable': 'Sauce, carbonara', 'supercategory': 'food'}, {'id': 3392, 'name': 'fig-dried', 'name_readable': 'Fig, dried', 'supercategory': 'food'}, {'id': 1488, 'name': 'pasta-in-butterfly-form-farfalle', 'name_readable': 'Pasta in butterfly form, farfalle', 'supercategory': 'food'}, {'id': 1711, 'name': 'minced-meat', 'name_readable': 'Minced meat', 'supercategory': 'food'}, {'id': 143, 'name': 'carrot-steamed-without-addition-of-salt', 'name_readable': 'Carrot, steamed, without addition of salt', 'supercategory': 'food'}, {'id': 1456, 'name': 'ebly', 'name_readable': 'Ebly', 'supercategory': 'food'}, {'id': 1201, 'name': 'damson-plum', 'name_readable': 'Damson plum', 'supercategory': 'food'}, {'id': 1125, 'name': 'shoots', 'name_readable': 'Shoots', 'supercategory': 'food'}, {'id': 2768, 'name': 'bouquet-garni', 'name_readable': 'Bouquet garni', 'supercategory': 'food'}, {'id': 1216, 'name': 'coconut', 'name_readable': 'Coconut', 'supercategory': 'food'}, {'id': 5748, 'name': 'banana-cake', 'name_readable': 'Banana cake', 'supercategory': 'food'}, {'id': 2355, 'name': 'waffle', 'name_readable': 'Waffle', 'supercategory': 'food'}, {'id': 2960, 'name': 'apricot-dried', 'name_readable': 'Apricot, dried', 'supercategory': 'food'}, {'id': 2719, 'name': 'sauce-curry', 'name_readable': 'Sauce, curry', 'supercategory': 'food'}, {'id': 578, 'name': 'watermelon-fresh', 'name_readable': 'Watermelon, fresh', 'supercategory': 'food'}, {'id': 3416, 'name': 'sauce-sweet-salted-asian', 'name_readable': 'Sauce, sweet-salted (asian)', 'supercategory': 'food'}, {'id': 1749, 'name': 'pork-roast', 'name_readable': 'Pork, roast', 'supercategory': 'food'}, {'id': 1158, 'name': 'blackberry', 'name_readable': 'Blackberry', 'supercategory': 'food'}, {'id': 1908, 'name': 'smoked-cooked-sausage-of-pork-and-beef-meat-sausag', 'name_readable': 'Smoked cooked sausage of pork and beef meat sausag', 'supercategory': 'food'}, {'id': 1134, 'name': 'bean-seeds', 'name_readable': 'bean seeds', 'supercategory': 'food'}, {'id': 2744, 'name': 'italian-salad-dressing', 'name_readable': 'Italian salad dressing', 'supercategory': 'food'}, {'id': 1124, 'name': 'white-asparagus', 'name_readable': 'White asparagus', 'supercategory': 'food'}, {'id': 3085, 'name': 'pie-rhubarb-baked-with-cake-dough', 'name_readable': 'Pie, rhubarb, baked, with cake dough', 'supercategory': 'food'}, {'id': 929, 'name': 'tomato-stewed-without-addition-of-fat-without-addition-of-salt', 'name_readable': 'Tomato, stewed, without addition of fat, without addition of salt', 'supercategory': 'food'}, {'id': 1175, 'name': 'cherries', 'name_readable': 'Cherries', 'supercategory': 'food'}, {'id': 1186, 'name': 'nectarine', 'name_readable': 'Nectarine', 'supercategory': 'food'}]
['bread-wholemeal', 'jam', 'water', 'bread-sourdough', 'banana', 'soft-cheese', 'ham-raw', 'hard-cheese', 'cottage-cheese', 'bread-half-white', 'coffee-with-caffeine', 'fruit-salad', 'pancakes', 'tea', 'salmon-smoked', 'avocado', 'spring-onion-scallion', 'ristretto-with-caffeine', 'ham', 'egg', 'bacon-frying', 'chips-french-fries', 'juice-apple', 'chicken', 'tomato-raw', 'broccoli', 'shrimp-boiled', 'beetroot-steamed-without-addition-of-salt', 'carrot-raw', 'chickpeas', 'french-salad-dressing', 'pasta-hornli', 'sauce-cream', 'meat-balls', 'pasta', 'tomato-sauce', 'cheese', 'pear', 'cashew-nut', 'almonds', 'lentils', 'mixed-vegetables', 'peanut-butter', 'apple', 'blueberries', 'cucumber', 'cocoa-powder', 'greek-yaourt-yahourt-yogourt-ou-yoghourt', 'maple-syrup-concentrate', 'buckwheat-grain-peeled', 'butter', 'herbal-tea', 'mayonnaise', 'soup-vegetable', 'wine-red', 'wine-white', 'green-bean-steamed-without-addition-of-salt', 'sausage', 'pizza-margherita-baked', 'salami', 'mushroom', 'bread-meat-substitute-lettuce-sauce', 'tart', 'tea-verveine', 'rice', 'white-coffee-with-caffeine', 'linseeds', 'sunflower-seeds', 'ham-cooked', 'bell-pepper-red-raw', 'zucchini', 'green-asparagus', 'tartar-sauce', 'lye-pretzel-soft', 'cucumber-pickled', 'curry-vegetarian', 'yaourt-yahourt-yogourt-ou-yoghourt-natural', 'soup-of-lentils-dahl-dhal', 'soup-cream-of-vegetables', 'balsamic-vinegar', 'salmon', 'salt-cake-vegetables-filled', 'bacon', 'orange', 'pasta-noodles', 'cream', 'cake-chocolate', 'pasta-spaghetti', 'black-olives', 'parmesan', 'spaetzle', 'salad-lambs-ear', 'salad-leaf-salad-green', 'potatoes-steamed', 'white-cabbage', 'halloumi', 'beetroot-raw', 'bread-grain', 'applesauce-unsweetened-canned', 'cheese-for-raclette', 'mushrooms', 'bread-white', 'curds-natural-with-at-most-10-fidm', 'bagel-without-filling', 'quiche-with-cheese-baked-with-puff-pastry', 'soup-potato', 'bouillon-vegetable', 'beef-sirloin-steak', 'taboule-prepared-with-couscous', 'eggplant', 'bread', 'turnover-with-meat-small-meat-pie-empanadas', 'mungbean-sprouts', 'mozzarella', 'pasta-penne', 'lasagne-vegetable-prepared', 'mandarine', 'kiwi', 'french-beans', 'tartar-meat', 'spring-roll-fried', 'pork-chop', 'caprese-salad-tomato-mozzarella', 'leaf-spinach', 'roll-of-half-white-or-white-flour-with-large-void', 'pasta-ravioli-stuffing', 'omelette-plain', 'tuna', 'dark-chocolate', 'sauce-savoury', 'dried-raisins', 'ice-tea', 'kaki', 'macaroon', 'smoothie', 'crepe-plain', 'chicken-nuggets', 'chili-con-carne-prepared', 'veggie-burger', 'cream-spinach', 'cod', 'chinese-cabbage', 'hamburger-bread-meat-ketchup', 'soup-pumpkin', 'sushi', 'chestnuts', 'coffee-decaffeinated', 'sauce-soya', 'balsamic-salad-dressing', 'pasta-twist', 'bolognaise-sauce', 'leek', 'fajita-bread-only', 'potato-gnocchi', 'beef-cut-into-stripes-only-meat', 'rice-noodles-vermicelli', 'tea-ginger', 'tea-green', 'bread-whole-wheat', 'onion', 'garlic', 'hummus', 'pizza-with-vegetables-baked', 'beer', 'glucose-drink-50g', 'chicken-wing', 'ratatouille', 'peanut', 'high-protein-pasta-made-of-lentils-peas', 'cauliflower', 'quiche-with-spinach-baked-with-cake-dough', 'green-olives', 'brazil-nut', 'eggplant-caviar', 'bread-pita', 'pasta-wholemeal', 'sauce-pesto', 'oil', 'couscous', 'sauce-roast', 'prosecco', 'crackers', 'bread-toast', 'shrimp-prawn-small', 'panna-cotta', 'romanesco', 'water-with-lemon-juice', 'espresso-with-caffeine', 'egg-scrambled-prepared', 'juice-orange', 'ice-cubes', 'braided-white-loaf', 'emmental-cheese', 'croissant-wholegrain', 'hazelnut-chocolate-spread-nutella-ovomaltine-caotina', 'tomme', 'water-mineral', 'hazelnut', 'bacon-raw', 'bread-nut', 'black-forest-tart', 'soup-miso', 'peach', 'figs', 'beef-filet', 'mustard-dijon', 'rice-basmati', 'mashed-potatoes-prepared-with-full-fat-milk-with-butter', 'dumplings', 'pumpkin', 'swiss-chard', 'red-cabbage', 'spinach-raw', 'naan-indien-bread', 'chicken-curry-cream-coconut-milk-curry-spices-paste', 'crunch-muesli', 'biscuits', 'bread-french-white-flour', 'meatloaf', 'fresh-cheese', 'honey', 'vegetable-mix-peas-and-carrots', 'parsley', 'brownie', 'dairy-ice-cream', 'tea-black', 'carrot-cake', 'fish-fingers-breaded', 'salad-dressing', 'dried-meat', 'chicken-breast', 'mixed-salad-chopped-without-sauce', 'feta', 'praline', 'tea-peppermint', 'walnut', 'potato-salad-with-mayonnaise-yogurt-dressing', 'kebab-in-pita-bread', 'kolhrabi', 'alfa-sprouts', 'brussel-sprouts', 'bacon-cooking', 'gruyere', 'bulgur', 'grapes', 'pork-escalope', 'chocolate-egg-small', 'cappuccino', 'zucchini-stewed-without-addition-of-fat-without-addition-of-salt', 'crisp-bread-wasa', 'bread-black', 'perch-fillets-lake', 'rosti', 'mango', 'sandwich-ham-cheese-and-butter', 'muesli', 'spinach-steamed-without-addition-of-salt', 'fish', 'risotto-without-cheese-cooked', 'milk-chocolate-with-hazelnuts', 'cake-oblong', 'crisps', 'pork', 'pomegranate', 'sweet-corn-canned', 'flakes-oat', 'greek-salad', 'cantonese-fried-rice', 'sesame-seeds', 'bouillon', 'baked-potato', 'fennel', 'meat', 'bread-olive', 'croutons', 'philadelphia', 'mushroom-average-stewed-without-addition-of-fat-without-addition-of-salt', 'bell-pepper-red-stewed-without-addition-of-fat-without-addition-of-salt', 'white-chocolate', 'mixed-nuts', 'breadcrumbs-unspiced', 'fondue', 'sauce-mushroom', 'tea-spice', 'strawberries', 'tea-rooibos', 'pie-plum-baked-with-cake-dough', 'potatoes-au-gratin-dauphinois-prepared', 'capers', 'vegetables', 'bread-wholemeal-toast', 'red-radish', 'fruit-tart', 'beans-kidney', 'sauerkraut', 'mustard', 'country-fries', 'ketchup', 'pasta-linguini-parpadelle-tagliatelle', 'chicken-cut-into-stripes-only-meat', 'cookies', 'sun-dried-tomatoe', 'bread-ticino', 'semi-hard-cheese', 'margarine', 'porridge-prepared-with-partially-skimmed-milk', 'soya-drink-soy-milk', 'juice-multifruit', 'popcorn-salted', 'chocolate-filled', 'milk-chocolate', 'bread-fruit', 'mix-of-dried-fruits-and-nuts', 'corn', 'tete-de-moine', 'dates', 'pistachio', 'celery', 'white-radish', 'oat-milk', 'cream-cheese', 'bread-rye', 'witloof-chicory', 'apple-crumble', 'goat-cheese-soft', 'grapefruit-pomelo', 'risotto-with-mushrooms-cooked', 'blue-mould-cheese', 'biscuit-with-butter', 'guacamole', 'pecan-nut', 'tofu', 'cordon-bleu-from-pork-schnitzel-fried', 'paprika-chips', 'quinoa', 'kefir-drink', 'm-m-s', 'salad-rocket', 'bread-spelt', 'pizza-with-ham-with-mushrooms-baked', 'fruit-coulis', 'plums', 'beef-minced-only-meat', 'pizza-with-ham-baked', 'pineapple', 'soup-tomato', 'cheddar', 'tea-fruit', 'rice-jasmin', 'seeds', 'focaccia', 'milk', 'coleslaw-chopped-without-sauce', 'pastry-flaky', 'curd', 'savoury-puff-pastry-stick', 'sweet-potato', 'chicken-leg', 'croissant', 'sour-cream', 'ham-turkey', 'processed-cheese', 'fruit-compotes', 'cheesecake', 'pasta-tortelloni-stuffing', 'sauce-cocktail', 'croissant-with-chocolate-filling', 'pumpkin-seeds', 'artichoke', 'champagne', 'grissini', 'sweets-candies', 'brie', 'wienerli-swiss-sausage', 'syrup-diluted-ready-to-drink', 'apple-pie', 'white-bread-with-butter-eggs-and-milk', 'savoury-puff-pastry', 'anchovies', 'tuna-in-oil-drained', 'lemon-pie', 'meat-terrine-pate', 'coriander', 'falafel-balls', 'berries', 'latte-macchiato-with-caffeine', 'faux-mage-cashew-vegan-chers', 'beans-white', 'sugar-melon', 'mixed-seeds', 'hamburger', 'hamburger-bun', 'oil-vinegar-salad-dressing', 'soya-yaourt-yahourt-yogourt-ou-yoghourt', 'chocolate-milk-chocolate-drink', 'celeriac', 'chocolate-mousse', 'cenovis-yeast-spread', 'thickened-cream-35', 'meringue', 'lamb-chop', 'shrimp-prawn-large', 'beef', 'lemon', 'croque-monsieur', 'chives', 'chocolate-cookies', 'birchermuesli-prepared-no-sugar-added', 'fish-crunchies-battered', 'muffin', 'savoy-cabbage-steamed-without-addition-of-salt', 'pine-nuts', 'chorizo', 'chia-grains', 'frying-sausage', 'french-pizza-from-alsace-baked', 'chocolate', 'cooked-sausage', 'grits-polenta-maize-flour', 'gummi-bears-fruit-jellies-jelly-babies-with-fruit-essence', 'wine-rose', 'coca-cola', 'raspberries', 'roll-with-pieces-of-chocolate', 'goat-average-raw', 'lemon-cake', 'coconut-milk', 'rice-wild', 'gluten-free-bread', 'pearl-onions', 'buckwheat-pancake', 'bread-5-grain', 'light-beer', 'sugar-glazing', 'tzatziki', 'butter-herb', 'ham-croissant', 'corn-crisps', 'lentils-green-du-puy-du-berry', 'cocktail', 'rice-whole-grain', 'veal-sausage', 'cervelat', 'sorbet', 'aperitif-with-alcohol-aperol-spritz', 'dips', 'corn-flakes', 'peas', 'tiramisu', 'apricots', 'cake-marble', 'lamb', 'lasagne-meat-prepared', 'coca-cola-zero', 'cake-salted', 'dough-puff-pastry-shortcrust-bread-pizza-dough', 'rice-waffels', 'sekt', 'brioche', 'vegetable-au-gratin-baked', 'mango-dried', 'processed-meat-charcuterie', 'mousse', 'sauce-sweet-sour', 'basil', 'butter-spread-puree-almond', 'pie-apricot-baked-with-cake-dough', 'rusk-wholemeal', 'beef-roast', 'vanille-cream-cooked-custard-creme-dessert', 'pasta-in-conch-form', 'nuts', 'sauce-carbonara', 'fig-dried', 'pasta-in-butterfly-form-farfalle', 'minced-meat', 'carrot-steamed-without-addition-of-salt', 'ebly', 'damson-plum', 'shoots', 'bouquet-garni', 'coconut', 'banana-cake', 'waffle', 'apricot-dried', 'sauce-curry', 'watermelon-fresh', 'sauce-sweet-salted-asian', 'pork-roast', 'blackberry', 'smoked-cooked-sausage-of-pork-and-beef-meat-sausag', 'bean-seeds', 'italian-salad-dressing', 'white-asparagus', 'pie-rhubarb-baked-with-cake-dough', 'tomato-stewed-without-addition-of-fat-without-addition-of-salt', 'cherries', 'nectarine']
In [ ]:
##Here is the raw config file, we will make changes to this to suit our purpose
!cat {config_fname}
_base_ = [
    '../_base_/datasets/coco_instance.py',
    '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# model settings
model = dict(
    type='HybridTaskCascade',
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=True),
        norm_eval=True,
        style='pytorch',
        init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
    neck=dict(
        type='FPN',
        in_channels=[256, 512, 1024, 2048],
        out_channels=256,
        num_outs=5),
    rpn_head=dict(
        type='RPNHead',
        in_channels=256,
        feat_channels=256,
        anchor_generator=dict(
            type='AnchorGenerator',
            scales=[8],
            ratios=[0.5, 1.0, 2.0],
            strides=[4, 8, 16, 32, 64]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[.0, .0, .0, .0],
            target_stds=[1.0, 1.0, 1.0, 1.0]),
        loss_cls=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
        loss_bbox=dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)),
    roi_head=dict(
        type='HybridTaskCascadeRoIHead',
        interleaved=True,
        mask_info_flow=True,
        num_stages=3,
        stage_loss_weights=[1, 0.5, 0.25],
        bbox_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        bbox_head=[
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=80,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.1, 0.1, 0.2, 0.2]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=80,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.05, 0.05, 0.1, 0.1]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=80,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.033, 0.033, 0.067, 0.067]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))
        ],
        mask_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=14, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        mask_head=[
            dict(
                type='HTCMaskHead',
                with_conv_res=False,
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=80,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=80,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=80,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))
        ]),
    # model training and testing settings
    train_cfg=dict(
        rpn=dict(
            assigner=dict(
                type='MaxIoUAssigner',
                pos_iou_thr=0.7,
                neg_iou_thr=0.3,
                min_pos_iou=0.3,
                ignore_iof_thr=-1),
            sampler=dict(
                type='RandomSampler',
                num=256,
                pos_fraction=0.5,
                neg_pos_ub=-1,
                add_gt_as_proposals=False),
            allowed_border=0,
            pos_weight=-1,
            debug=False),
        rpn_proposal=dict(
            nms_pre=2000,
            max_per_img=2000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=[
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.5,
                    neg_iou_thr=0.5,
                    min_pos_iou=0.5,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.6,
                    neg_iou_thr=0.6,
                    min_pos_iou=0.6,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.7,
                    neg_iou_thr=0.7,
                    min_pos_iou=0.7,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False)
        ]),
    test_cfg=dict(
        rpn=dict(
            nms_pre=1000,
            max_per_img=1000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=dict(
            score_thr=0.001,
            nms=dict(type='nms', iou_threshold=0.5),
            max_per_img=100,
            mask_thr_binary=0.5)))
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(1333, 800),
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip', flip_ratio=0.5),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
]
data = dict(
    val=dict(pipeline=test_pipeline), test=dict(pipeline=test_pipeline))

Edit config

We will edit the config to be suited to the food dataset, there are a lot of parameters other than the ones we have changed below that one can edit in the existing config file that might lead to a better score. We leave that upto you, do feel free to explore documentation for mmdetection.

Note: Instead of using regular expressions to edit the existing file, feel free to download the config file and edit it using the text editor of your choice and then reupload the same and have the variable config_fname point to the same

In [ ]:
import re
fname = config_fname
with open(fname) as f:
    s = f.read()

    s = re.sub('num_classes=.*?,',
               'num_classes={},'.format(len(classes_names)), s)

with open(fname, 'w') as f:
    f.write(s)
#lets check if the changes have been updated
!cat {config_fname}
_base_ = [
    '../_base_/datasets/coco_instance.py',
    '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# model settings
model = dict(
    type='HybridTaskCascade',
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=True),
        norm_eval=True,
        style='pytorch',
        init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
    neck=dict(
        type='FPN',
        in_channels=[256, 512, 1024, 2048],
        out_channels=256,
        num_outs=5),
    rpn_head=dict(
        type='RPNHead',
        in_channels=256,
        feat_channels=256,
        anchor_generator=dict(
            type='AnchorGenerator',
            scales=[8],
            ratios=[0.5, 1.0, 2.0],
            strides=[4, 8, 16, 32, 64]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[.0, .0, .0, .0],
            target_stds=[1.0, 1.0, 1.0, 1.0]),
        loss_cls=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
        loss_bbox=dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)),
    roi_head=dict(
        type='HybridTaskCascadeRoIHead',
        interleaved=True,
        mask_info_flow=True,
        num_stages=3,
        stage_loss_weights=[1, 0.5, 0.25],
        bbox_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        bbox_head=[
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.1, 0.1, 0.2, 0.2]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.05, 0.05, 0.1, 0.1]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0., 0., 0., 0.],
                    target_stds=[0.033, 0.033, 0.067, 0.067]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))
        ],
        mask_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=14, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        mask_head=[
            dict(
                type='HTCMaskHead',
                with_conv_res=False,
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))
        ]),
    # model training and testing settings
    train_cfg=dict(
        rpn=dict(
            assigner=dict(
                type='MaxIoUAssigner',
                pos_iou_thr=0.7,
                neg_iou_thr=0.3,
                min_pos_iou=0.3,
                ignore_iof_thr=-1),
            sampler=dict(
                type='RandomSampler',
                num=256,
                pos_fraction=0.5,
                neg_pos_ub=-1,
                add_gt_as_proposals=False),
            allowed_border=0,
            pos_weight=-1,
            debug=False),
        rpn_proposal=dict(
            nms_pre=2000,
            max_per_img=2000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=[
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.5,
                    neg_iou_thr=0.5,
                    min_pos_iou=0.5,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.6,
                    neg_iou_thr=0.6,
                    min_pos_iou=0.6,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.7,
                    neg_iou_thr=0.7,
                    min_pos_iou=0.7,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False)
        ]),
    test_cfg=dict(
        rpn=dict(
            nms_pre=1000,
            max_per_img=1000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=dict(
            score_thr=0.001,
            nms=dict(type='nms', iou_threshold=0.5),
            max_per_img=100,
            mask_thr_binary=0.5)))
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(1333, 800),
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip', flip_ratio=0.5),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
]
data = dict(
    val=dict(pipeline=test_pipeline), test=dict(pipeline=test_pipeline))
In [ ]:
import re
fname2 = '/content/mmdetection/configs/_base_/datasets/coco_instance.py'

with open(fname2) as f:
    s = f.read()
    s = re.sub("data_root = 'data/coco/'",
                "data_root = 'data/'", s)
    s = re.sub("annotations/instances_train2017.json",
                "train/new_ann.json", s)
    s = re.sub("annotations/instances_val2017.json",
                "val/new_ann.json", s)
    s = re.sub("annotations/instances_val2017.json",
                "val/new_ann.json", s)
    s = re.sub("train2017", "train/images", s)
    s = re.sub("val2017", "val/images", s)
    s = re.sub("workers_per_gpu=2","workers_per_gpu=0",s)
    s = re.sub("samples_per_gpu=2","samples_per_gpu=6",s) 
   

with open(fname2, 'w') as f:
    f.write(s)

#to check if the changes have been updated
# !cat {fname2}


total_epochs = 22
fname = '/content/mmdetection/configs/_base_/schedules/schedule_1x.py'
with open(fname) as f:
    s = f.read()
    s = re.sub('max_epochs=\d+',
               'max_epochs={}'.format(total_epochs), s)
    s = re.sub("lr=0.02","lr=0.0025",s)  #need to change lr to 0.0025 since we are working with only 1 gpu
with open(fname, 'w') as f:
    f.write(s)
In [ ]:
#@title Don't forget to run this cell, Modify coco dataset mmdet file (set classes list) { display-mode: "form" }
%%writefile /content/mmdetection/mmdet/datasets/coco.py


# Copyright (c) OpenMMLab. All rights reserved.
import contextlib
import io
import itertools
import logging
import os.path as osp
import tempfile
import warnings
from collections import OrderedDict

import mmcv
import numpy as np
from mmcv.utils import print_log
from terminaltables import AsciiTable

from mmdet.core import eval_recalls
from .api_wrappers import COCO, COCOeval
from .builder import DATASETS
from .custom import CustomDataset


@DATASETS.register_module()
class CocoDataset(CustomDataset):

    CLASSES = ('bread-wholemeal', 'jam', 'water', 'bread-sourdough', 'banana', 'soft-cheese', 'ham-raw', 'hard-cheese', 'cottage-cheese', 'bread-half-white', 'coffee-with-caffeine', 'fruit-salad', 'pancakes', 'tea', 'salmon-smoked', 'avocado', 'spring-onion-scallion', 'ristretto-with-caffeine', 'ham', 'egg', 'bacon-frying', 'chips-french-fries', 'juice-apple', 'chicken', 'tomato-raw', 'broccoli', 'shrimp-boiled', 'beetroot-steamed-without-addition-of-salt', 'carrot-raw', 'chickpeas', 'french-salad-dressing', 'pasta-hornli', 'sauce-cream', 'meat-balls', 'pasta', 'tomato-sauce', 'cheese', 'pear', 'cashew-nut', 'almonds', 'lentils', 'mixed-vegetables', 'peanut-butter', 'apple', 'blueberries', 'cucumber', 'cocoa-powder', 'greek-yaourt-yahourt-yogourt-ou-yoghourt', 'maple-syrup-concentrate', 'buckwheat-grain-peeled', 'butter', 'herbal-tea', 'mayonnaise', 'soup-vegetable', 'wine-red', 'wine-white', 'green-bean-steamed-without-addition-of-salt', 'sausage', 'pizza-margherita-baked', 'salami', 'mushroom', 'bread-meat-substitute-lettuce-sauce', 'tart', 'tea-verveine', 'rice', 'white-coffee-with-caffeine', 'linseeds', 'sunflower-seeds', 'ham-cooked', 'bell-pepper-red-raw', 'zucchini', 'green-asparagus', 'tartar-sauce', 'lye-pretzel-soft', 'cucumber-pickled', 'curry-vegetarian', 'yaourt-yahourt-yogourt-ou-yoghourt-natural', 'soup-of-lentils-dahl-dhal', 'soup-cream-of-vegetables', 'balsamic-vinegar', 'salmon', 'salt-cake-vegetables-filled', 'bacon', 'orange', 'pasta-noodles', 'cream', 'cake-chocolate', 'pasta-spaghetti', 'black-olives', 'parmesan', 'spaetzle', 'salad-lambs-ear', 'salad-leaf-salad-green', 'potatoes-steamed', 'white-cabbage', 'halloumi', 'beetroot-raw', 'bread-grain', 'applesauce-unsweetened-canned', 'cheese-for-raclette', 'mushrooms', 'bread-white', 'curds-natural-with-at-most-10-fidm', 'bagel-without-filling', 'quiche-with-cheese-baked-with-puff-pastry', 'soup-potato', 'bouillon-vegetable', 'beef-sirloin-steak', 'taboule-prepared-with-couscous', 'eggplant', 'bread', 'turnover-with-meat-small-meat-pie-empanadas', 'mungbean-sprouts', 'mozzarella', 'pasta-penne', 'lasagne-vegetable-prepared', 'mandarine', 'kiwi', 'french-beans', 'tartar-meat', 'spring-roll-fried', 'pork-chop', 'caprese-salad-tomato-mozzarella', 'leaf-spinach', 'roll-of-half-white-or-white-flour-with-large-void', 'pasta-ravioli-stuffing', 'omelette-plain', 'tuna', 'dark-chocolate', 'sauce-savoury', 'dried-raisins', 'ice-tea', 'kaki', 'macaroon', 'smoothie', 'crepe-plain', 'chicken-nuggets', 'chili-con-carne-prepared', 'veggie-burger', 'cream-spinach', 'cod', 'chinese-cabbage', 'hamburger-bread-meat-ketchup', 'soup-pumpkin', 'sushi', 'chestnuts', 'coffee-decaffeinated', 'sauce-soya', 'balsamic-salad-dressing', 'pasta-twist', 'bolognaise-sauce', 'leek', 'fajita-bread-only', 'potato-gnocchi', 'beef-cut-into-stripes-only-meat', 'rice-noodles-vermicelli', 'tea-ginger', 'tea-green', 'bread-whole-wheat', 'onion', 'garlic', 'hummus', 'pizza-with-vegetables-baked', 'beer', 'glucose-drink-50g', 'chicken-wing', 'ratatouille', 'peanut', 'high-protein-pasta-made-of-lentils-peas', 'cauliflower', 'quiche-with-spinach-baked-with-cake-dough', 'green-olives', 'brazil-nut', 'eggplant-caviar', 'bread-pita', 'pasta-wholemeal', 'sauce-pesto', 'oil', 'couscous', 'sauce-roast', 'prosecco', 'crackers', 'bread-toast', 'shrimp-prawn-small', 'panna-cotta', 'romanesco', 'water-with-lemon-juice', 'espresso-with-caffeine', 'egg-scrambled-prepared', 'juice-orange', 'ice-cubes', 'braided-white-loaf', 'emmental-cheese', 'croissant-wholegrain', 'hazelnut-chocolate-spread-nutella-ovomaltine-caotina', 'tomme', 'water-mineral', 'hazelnut', 'bacon-raw', 'bread-nut', 'black-forest-tart', 'soup-miso', 'peach', 'figs', 'beef-filet', 'mustard-dijon', 'rice-basmati', 'mashed-potatoes-prepared-with-full-fat-milk-with-butter', 'dumplings', 'pumpkin', 'swiss-chard', 'red-cabbage', 'spinach-raw', 'naan-indien-bread', 'chicken-curry-cream-coconut-milk-curry-spices-paste', 'crunch-muesli', 'biscuits', 'bread-french-white-flour', 'meatloaf', 'fresh-cheese', 'honey', 'vegetable-mix-peas-and-carrots', 'parsley', 'brownie', 'dairy-ice-cream', 'tea-black', 'carrot-cake', 'fish-fingers-breaded', 'salad-dressing', 'dried-meat', 'chicken-breast', 'mixed-salad-chopped-without-sauce', 'feta', 'praline', 'tea-peppermint', 'walnut', 'potato-salad-with-mayonnaise-yogurt-dressing', 'kebab-in-pita-bread', 'kolhrabi', 'alfa-sprouts', 'brussel-sprouts', 'bacon-cooking', 'gruyere', 'bulgur', 'grapes', 'pork-escalope', 'chocolate-egg-small', 'cappuccino', 'zucchini-stewed-without-addition-of-fat-without-addition-of-salt', 'crisp-bread-wasa', 'bread-black', 'perch-fillets-lake', 'rosti', 'mango', 'sandwich-ham-cheese-and-butter', 'muesli', 'spinach-steamed-without-addition-of-salt', 'fish', 'risotto-without-cheese-cooked', 'milk-chocolate-with-hazelnuts', 'cake-oblong', 'crisps', 'pork', 'pomegranate', 'sweet-corn-canned', 'flakes-oat', 'greek-salad', 'cantonese-fried-rice', 'sesame-seeds', 'bouillon', 'baked-potato', 'fennel', 'meat', 'bread-olive', 'croutons', 'philadelphia', 'mushroom-average-stewed-without-addition-of-fat-without-addition-of-salt', 'bell-pepper-red-stewed-without-addition-of-fat-without-addition-of-salt', 'white-chocolate', 'mixed-nuts', 'breadcrumbs-unspiced', 'fondue', 'sauce-mushroom', 'tea-spice', 'strawberries', 'tea-rooibos', 'pie-plum-baked-with-cake-dough', 'potatoes-au-gratin-dauphinois-prepared', 'capers', 'vegetables', 'bread-wholemeal-toast', 'red-radish', 'fruit-tart', 'beans-kidney', 'sauerkraut', 'mustard', 'country-fries', 'ketchup', 'pasta-linguini-parpadelle-tagliatelle', 'chicken-cut-into-stripes-only-meat', 'cookies', 'sun-dried-tomatoe', 'bread-ticino', 'semi-hard-cheese', 'margarine', 'porridge-prepared-with-partially-skimmed-milk', 'soya-drink-soy-milk', 'juice-multifruit', 'popcorn-salted', 'chocolate-filled', 'milk-chocolate', 'bread-fruit', 'mix-of-dried-fruits-and-nuts', 'corn', 'tete-de-moine', 'dates', 'pistachio', 'celery', 'white-radish', 'oat-milk', 'cream-cheese', 'bread-rye', 'witloof-chicory', 'apple-crumble', 'goat-cheese-soft', 'grapefruit-pomelo', 'risotto-with-mushrooms-cooked', 'blue-mould-cheese', 'biscuit-with-butter', 'guacamole', 'pecan-nut', 'tofu', 'cordon-bleu-from-pork-schnitzel-fried', 'paprika-chips', 'quinoa', 'kefir-drink', 'm-m-s', 'salad-rocket', 'bread-spelt', 'pizza-with-ham-with-mushrooms-baked', 'fruit-coulis', 'plums', 'beef-minced-only-meat', 'pizza-with-ham-baked', 'pineapple', 'soup-tomato', 'cheddar', 'tea-fruit', 'rice-jasmin', 'seeds', 'focaccia', 'milk', 'coleslaw-chopped-without-sauce', 'pastry-flaky', 'curd', 'savoury-puff-pastry-stick', 'sweet-potato', 'chicken-leg', 'croissant', 'sour-cream', 'ham-turkey', 'processed-cheese', 'fruit-compotes', 'cheesecake', 'pasta-tortelloni-stuffing', 'sauce-cocktail', 'croissant-with-chocolate-filling', 'pumpkin-seeds', 'artichoke', 'champagne', 'grissini', 'sweets-candies', 'brie', 'wienerli-swiss-sausage', 'syrup-diluted-ready-to-drink', 'apple-pie', 'white-bread-with-butter-eggs-and-milk', 'savoury-puff-pastry', 'anchovies', 'tuna-in-oil-drained', 'lemon-pie', 'meat-terrine-pate', 'coriander', 'falafel-balls', 'berries', 'latte-macchiato-with-caffeine', 'faux-mage-cashew-vegan-chers', 'beans-white', 'sugar-melon', 'mixed-seeds', 'hamburger', 'hamburger-bun', 'oil-vinegar-salad-dressing', 'soya-yaourt-yahourt-yogourt-ou-yoghourt', 'chocolate-milk-chocolate-drink', 'celeriac', 'chocolate-mousse', 'cenovis-yeast-spread', 'thickened-cream-35', 'meringue', 'lamb-chop', 'shrimp-prawn-large', 'beef', 'lemon', 'croque-monsieur', 'chives', 'chocolate-cookies', 'birchermuesli-prepared-no-sugar-added', 'fish-crunchies-battered', 'muffin', 'savoy-cabbage-steamed-without-addition-of-salt', 'pine-nuts', 'chorizo', 'chia-grains', 'frying-sausage', 'french-pizza-from-alsace-baked', 'chocolate', 'cooked-sausage', 'grits-polenta-maize-flour', 'gummi-bears-fruit-jellies-jelly-babies-with-fruit-essence', 'wine-rose', 'coca-cola', 'raspberries', 'roll-with-pieces-of-chocolate', 'goat-average-raw', 'lemon-cake', 'coconut-milk', 'rice-wild', 'gluten-free-bread', 'pearl-onions', 'buckwheat-pancake', 'bread-5-grain', 'light-beer', 'sugar-glazing', 'tzatziki', 'butter-herb', 'ham-croissant', 'corn-crisps', 'lentils-green-du-puy-du-berry', 'cocktail', 'rice-whole-grain', 'veal-sausage', 'cervelat', 'sorbet', 'aperitif-with-alcohol-aperol-spritz', 'dips', 'corn-flakes', 'peas', 'tiramisu', 'apricots', 'cake-marble', 'lamb', 'lasagne-meat-prepared', 'coca-cola-zero', 'cake-salted', 'dough-puff-pastry-shortcrust-bread-pizza-dough', 'rice-waffels', 'sekt', 'brioche', 'vegetable-au-gratin-baked', 'mango-dried', 'processed-meat-charcuterie', 'mousse', 'sauce-sweet-sour', 'basil', 'butter-spread-puree-almond', 'pie-apricot-baked-with-cake-dough', 'rusk-wholemeal', 'beef-roast', 'vanille-cream-cooked-custard-creme-dessert', 'pasta-in-conch-form', 'nuts', 'sauce-carbonara', 'fig-dried', 'pasta-in-butterfly-form-farfalle', 'minced-meat', 'carrot-steamed-without-addition-of-salt', 'ebly', 'damson-plum', 'shoots', 'bouquet-garni', 'coconut', 'banana-cake', 'waffle', 'apricot-dried', 'sauce-curry', 'watermelon-fresh', 'sauce-sweet-salted-asian', 'pork-roast', 'blackberry', 'smoked-cooked-sausage-of-pork-and-beef-meat-sausag', 'bean-seeds', 'italian-salad-dressing', 'white-asparagus', 'pie-rhubarb-baked-with-cake-dough', 'tomato-stewed-without-addition-of-fat-without-addition-of-salt', 'cherries', 'nectarine')

    def load_annotations(self, ann_file):
        """Load annotation from COCO style annotation file.

        Args:
            ann_file (str): Path of annotation file.

        Returns:
            list[dict]: Annotation info from COCO api.
        """

        self.coco = COCO(ann_file)
        # The order of returned `cat_ids` will not
        # change with the order of the CLASSES
        self.cat_ids = self.coco.getCatIds()

        self.cat2label = {cat_id: i for i, cat_id in enumerate(self.cat_ids)}
        self.img_ids = self.coco.getImgIds()
        data_infos = []
        total_ann_ids = []
        for i in self.img_ids:
            info = self.coco.load_imgs([i])[0]
            info['filename'] = info['file_name']
            data_infos.append(info)
            ann_ids = self.coco.get_ann_ids(img_ids=[i])
            total_ann_ids.extend(ann_ids)
        assert len(set(total_ann_ids)) == len(
            total_ann_ids), f"Annotation ids in '{ann_file}' are not unique!"
        return data_infos

    def get_ann_info(self, idx):
        """Get COCO annotation by index.

        Args:
            idx (int): Index of data.

        Returns:
            dict: Annotation info of specified index.
        """

        img_id = self.data_infos[idx]['id']
        ann_ids = self.coco.get_ann_ids(img_ids=[img_id])
        ann_info = self.coco.load_anns(ann_ids)
        return self._parse_ann_info(self.data_infos[idx], ann_info)

    def getCatIds(self, idx):
        """Get COCO category ids by index.

        Args:
            idx (int): Index of data.

        Returns:
            list[int]: All categories in the image of specified index.
        """

        img_id = self.data_infos[idx]['id']
        ann_ids = self.coco.get_ann_ids(img_ids=[img_id])
        ann_info = self.coco.load_anns(ann_ids)
        return [ann['category_id'] for ann in ann_info]

    def _filter_imgs(self, min_size=32):
        """Filter images too small or without ground truths."""
        valid_inds = []
        # obtain images that contain annotation
        ids_with_ann = set(_['image_id'] for _ in self.coco.anns.values())
        # obtain images that contain annotations of the required categories
        ids_in_cat = set()
        for i, class_id in enumerate(self.cat_ids):
            ids_in_cat |= set(self.coco.cat_img_map[class_id])
        # merge the image id sets of the two conditions and use the merged set
        # to filter out images if self.filter_empty_gt=True
        ids_in_cat &= ids_with_ann

        valid_img_ids = []
        for i, img_info in enumerate(self.data_infos):
            img_id = self.img_ids[i]
            if self.filter_empty_gt and img_id not in ids_in_cat:
                continue
            if min(img_info['width'], img_info['height']) >= min_size:
                valid_inds.append(i)
                valid_img_ids.append(img_id)
        self.img_ids = valid_img_ids
        return valid_inds

    def _parse_ann_info(self, img_info, ann_info):
        """Parse bbox and mask annotation.

        Args:
            ann_info (list[dict]): Annotation info of an image.
            with_mask (bool): Whether to parse mask annotations.

        Returns:
            dict: A dict containing the following keys: bboxes, bboxes_ignore,\
                labels, masks, seg_map. "masks" are raw annotations and not \
                decoded into binary masks.
        """
        gt_bboxes = []
        gt_labels = []
        gt_bboxes_ignore = []
        gt_masks_ann = []
        for i, ann in enumerate(ann_info):
            if ann.get('ignore', False):
                continue
            x1, y1, w, h = ann['bbox']
            inter_w = max(0, min(x1 + w, img_info['width']) - max(x1, 0))
            inter_h = max(0, min(y1 + h, img_info['height']) - max(y1, 0))
            if inter_w * inter_h == 0:
                continue
            if ann['area'] <= 0 or w < 1 or h < 1:
                continue
            if ann['category_id'] not in self.cat_ids:
                continue
            bbox = [x1, y1, x1 + w, y1 + h]
            if ann.get('iscrowd', False):
                gt_bboxes_ignore.append(bbox)
            else:
                gt_bboxes.append(bbox)
                gt_labels.append(self.cat2label[ann['category_id']])
                gt_masks_ann.append(ann.get('segmentation', None))

        if gt_bboxes:
            gt_bboxes = np.array(gt_bboxes, dtype=np.float32)
            gt_labels = np.array(gt_labels, dtype=np.int64)
        else:
            gt_bboxes = np.zeros((0, 4), dtype=np.float32)
            gt_labels = np.array([], dtype=np.int64)

        if gt_bboxes_ignore:
            gt_bboxes_ignore = np.array(gt_bboxes_ignore, dtype=np.float32)
        else:
            gt_bboxes_ignore = np.zeros((0, 4), dtype=np.float32)

        seg_map = img_info['filename'].replace('jpg', 'png')

        ann = dict(
            bboxes=gt_bboxes,
            labels=gt_labels,
            bboxes_ignore=gt_bboxes_ignore,
            masks=gt_masks_ann,
            seg_map=seg_map)

        return ann

    def xyxy2xywh(self, bbox):
        """Convert ``xyxy`` style bounding boxes to ``xywh`` style for COCO
        evaluation.

        Args:
            bbox (numpy.ndarray): The bounding boxes, shape (4, ), in
                ``xyxy`` order.

        Returns:
            list[float]: The converted bounding boxes, in ``xywh`` order.
        """

        _bbox = bbox.tolist()
        return [
            _bbox[0],
            _bbox[1],
            _bbox[2] - _bbox[0],
            _bbox[3] - _bbox[1],
        ]

    def _proposal2json(self, results):
        """Convert proposal results to COCO json style."""
        json_results = []
        for idx in range(len(self)):
            img_id = self.img_ids[idx]
            bboxes = results[idx]
            for i in range(bboxes.shape[0]):
                data = dict()
                data['image_id'] = img_id
                data['bbox'] = self.xyxy2xywh(bboxes[i])
                data['score'] = float(bboxes[i][4])
                data['category_id'] = 1
                json_results.append(data)
        return json_results

    def _det2json(self, results):
        """Convert detection results to COCO json style."""
        json_results = []
        for idx in range(len(self)):
            img_id = self.img_ids[idx]
            result = results[idx]
            for label in range(len(result)):
                bboxes = result[label]
                for i in range(bboxes.shape[0]):
                    data = dict()
                    data['image_id'] = img_id
                    data['bbox'] = self.xyxy2xywh(bboxes[i])
                    data['score'] = float(bboxes[i][4])
                    data['category_id'] = self.cat_ids[label]
                    json_results.append(data)
        return json_results

    def _segm2json(self, results):
        """Convert instance segmentation results to COCO json style."""
        bbox_json_results = []
        segm_json_results = []
        for idx in range(len(self)):
            img_id = self.img_ids[idx]
            det, seg = results[idx]
            for label in range(len(det)):
                # bbox results
                bboxes = det[label]
                for i in range(bboxes.shape[0]):
                    data = dict()
                    data['image_id'] = img_id
                    data['bbox'] = self.xyxy2xywh(bboxes[i])
                    data['score'] = float(bboxes[i][4])
                    data['category_id'] = self.cat_ids[label]
                    bbox_json_results.append(data)

                # segm results
                # some detectors use different scores for bbox and mask
                if isinstance(seg, tuple):
                    segms = seg[0][label]
                    mask_score = seg[1][label]
                else:
                    segms = seg[label]
                    mask_score = [bbox[4] for bbox in bboxes]
                for i in range(bboxes.shape[0]):
                    data = dict()
                    data['image_id'] = img_id
                    data['bbox'] = self.xyxy2xywh(bboxes[i])
                    data['score'] = float(mask_score[i])
                    data['category_id'] = self.cat_ids[label]
                    if isinstance(segms[i]['counts'], bytes):
                        segms[i]['counts'] = segms[i]['counts'].decode()
                    data['segmentation'] = segms[i]
                    segm_json_results.append(data)
        return bbox_json_results, segm_json_results

    def results2json(self, results, outfile_prefix):
        """Dump the detection results to a COCO style json file.

        There are 3 types of results: proposals, bbox predictions, mask
        predictions, and they have different data types. This method will
        automatically recognize the type, and dump them to json files.

        Args:
            results (list[list | tuple | ndarray]): Testing results of the
                dataset.
            outfile_prefix (str): The filename prefix of the json files. If the
                prefix is "somepath/xxx", the json files will be named
                "somepath/xxx.bbox.json", "somepath/xxx.segm.json",
                "somepath/xxx.proposal.json".

        Returns:
            dict[str: str]: Possible keys are "bbox", "segm", "proposal", and \
                values are corresponding filenames.
        """
        result_files = dict()
        if isinstance(results[0], list):
            json_results = self._det2json(results)
            result_files['bbox'] = f'{outfile_prefix}.bbox.json'
            result_files['proposal'] = f'{outfile_prefix}.bbox.json'
            mmcv.dump(json_results, result_files['bbox'])
        elif isinstance(results[0], tuple):
            json_results = self._segm2json(results)
            result_files['bbox'] = f'{outfile_prefix}.bbox.json'
            result_files['proposal'] = f'{outfile_prefix}.bbox.json'
            result_files['segm'] = f'{outfile_prefix}.segm.json'
            mmcv.dump(json_results[0], result_files['bbox'])
            mmcv.dump(json_results[1], result_files['segm'])
        elif isinstance(results[0], np.ndarray):
            json_results = self._proposal2json(results)
            result_files['proposal'] = f'{outfile_prefix}.proposal.json'
            mmcv.dump(json_results, result_files['proposal'])
        else:
            raise TypeError('invalid type of results')
        return result_files

    def fast_eval_recall(self, results, proposal_nums, iou_thrs, logger=None):
        gt_bboxes = []
        for i in range(len(self.img_ids)):
            ann_ids = self.coco.get_ann_ids(img_ids=self.img_ids[i])
            ann_info = self.coco.load_anns(ann_ids)
            if len(ann_info) == 0:
                gt_bboxes.append(np.zeros((0, 4)))
                continue
            bboxes = []
            for ann in ann_info:
                if ann.get('ignore', False) or ann['iscrowd']:
                    continue
                x1, y1, w, h = ann['bbox']
                bboxes.append([x1, y1, x1 + w, y1 + h])
            bboxes = np.array(bboxes, dtype=np.float32)
            if bboxes.shape[0] == 0:
                bboxes = np.zeros((0, 4))
            gt_bboxes.append(bboxes)

        recalls = eval_recalls(
            gt_bboxes, results, proposal_nums, iou_thrs, logger=logger)
        ar = recalls.mean(axis=1)
        return ar

    def format_results(self, results, jsonfile_prefix=None, **kwargs):
        """Format the results to json (standard format for COCO evaluation).

        Args:
            results (list[tuple | numpy.ndarray]): Testing results of the
                dataset.
            jsonfile_prefix (str | None): The prefix of json files. It includes
                the file path and the prefix of filename, e.g., "a/b/prefix".
                If not specified, a temp file will be created. Default: None.

        Returns:
            tuple: (result_files, tmp_dir), result_files is a dict containing \
                the json filepaths, tmp_dir is the temporal directory created \
                for saving json files when jsonfile_prefix is not specified.
        """
        assert isinstance(results, list), 'results must be a list'
        assert len(results) == len(self), (
            'The length of results is not equal to the dataset len: {} != {}'.
            format(len(results), len(self)))

        if jsonfile_prefix is None:
            tmp_dir = tempfile.TemporaryDirectory()
            jsonfile_prefix = osp.join(tmp_dir.name, 'results')
        else:
            tmp_dir = None
        result_files = self.results2json(results, jsonfile_prefix)
        return result_files, tmp_dir

    def evaluate(self,
                 results,
                 metric='bbox',
                 logger=None,
                 jsonfile_prefix=None,
                 classwise=False,
                 proposal_nums=(100, 300, 1000),
                 iou_thrs=None,
                 metric_items=None):
        """Evaluation in COCO protocol.

        Args:
            results (list[list | tuple]): Testing results of the dataset.
            metric (str | list[str]): Metrics to be evaluated. Options are
                'bbox', 'segm', 'proposal', 'proposal_fast'.
            logger (logging.Logger | str | None): Logger used for printing
                related information during evaluation. Default: None.
            jsonfile_prefix (str | None): The prefix of json files. It includes
                the file path and the prefix of filename, e.g., "a/b/prefix".
                If not specified, a temp file will be created. Default: None.
            classwise (bool): Whether to evaluating the AP for each class.
            proposal_nums (Sequence[int]): Proposal number used for evaluating
                recalls, such as recall@100, recall@1000.
                Default: (100, 300, 1000).
            iou_thrs (Sequence[float], optional): IoU threshold used for
                evaluating recalls/mAPs. If set to a list, the average of all
                IoUs will also be computed. If not specified, [0.50, 0.55,
                0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95] will be used.
                Default: None.
            metric_items (list[str] | str, optional): Metric items that will
                be returned. If not specified, ``['AR@100', 'AR@300',
                'AR@1000', 'AR_s@1000', 'AR_m@1000', 'AR_l@1000' ]`` will be
                used when ``metric=='proposal'``, ``['mAP', 'mAP_50', 'mAP_75',
                'mAP_s', 'mAP_m', 'mAP_l']`` will be used when
                ``metric=='bbox' or metric=='segm'``.

        Returns:
            dict[str, float]: COCO style evaluation metric.
        """

        metrics = metric if isinstance(metric, list) else [metric]
        allowed_metrics = ['bbox', 'segm', 'proposal', 'proposal_fast']
        for metric in metrics:
            if metric not in allowed_metrics:
                raise KeyError(f'metric {metric} is not supported')
        if iou_thrs is None:
            iou_thrs = np.linspace(
                .5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
        if metric_items is not None:
            if not isinstance(metric_items, list):
                metric_items = [metric_items]

        result_files, tmp_dir = self.format_results(results, jsonfile_prefix)

        eval_results = OrderedDict()
        cocoGt = self.coco
        for metric in metrics:
            msg = f'Evaluating {metric}...'
            if logger is None:
                msg = '\n' + msg
            print_log(msg, logger=logger)

            if metric == 'proposal_fast':
                ar = self.fast_eval_recall(
                    results, proposal_nums, iou_thrs, logger='silent')
                log_msg = []
                for i, num in enumerate(proposal_nums):
                    eval_results[f'AR@{num}'] = ar[i]
                    log_msg.append(f'\nAR@{num}\t{ar[i]:.4f}')
                log_msg = ''.join(log_msg)
                print_log(log_msg, logger=logger)
                continue

            iou_type = 'bbox' if metric == 'proposal' else metric
            if metric not in result_files:
                raise KeyError(f'{metric} is not in results')
            try:
                predictions = mmcv.load(result_files[metric])
                if iou_type == 'segm':
                    # Refer to https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/coco.py#L331  # noqa
                    # When evaluating mask AP, if the results contain bbox,
                    # cocoapi will use the box area instead of the mask area
                    # for calculating the instance area. Though the overall AP
                    # is not affected, this leads to different
                    # small/medium/large mask AP results.
                    for x in predictions:
                        x.pop('bbox')
                    warnings.simplefilter('once')
                    warnings.warn(
                        'The key "bbox" is deleted for more accurate mask AP '
                        'of small/medium/large instances since v2.12.0. This '
                        'does not change the overall mAP calculation.',
                        UserWarning)
                cocoDt = cocoGt.loadRes(predictions)
            except IndexError:
                print_log(
                    'The testing results of the whole dataset is empty.',
                    logger=logger,
                    level=logging.ERROR)
                break

            cocoEval = COCOeval(cocoGt, cocoDt, iou_type)
            cocoEval.params.catIds = self.cat_ids
            cocoEval.params.imgIds = self.img_ids
            cocoEval.params.maxDets = list(proposal_nums)
            cocoEval.params.iouThrs = iou_thrs
            # mapping of cocoEval.stats
            coco_metric_names = {
                'mAP': 0,
                'mAP_50': 1,
                'mAP_75': 2,
                'mAP_s': 3,
                'mAP_m': 4,
                'mAP_l': 5,
                'AR@100': 6,
                'AR@300': 7,
                'AR@1000': 8,
                'AR_s@1000': 9,
                'AR_m@1000': 10,
                'AR_l@1000': 11
            }
            if metric_items is not None:
                for metric_item in metric_items:
                    if metric_item not in coco_metric_names:
                        raise KeyError(
                            f'metric item {metric_item} is not supported')

            if metric == 'proposal':
                cocoEval.params.useCats = 0
                cocoEval.evaluate()
                cocoEval.accumulate()

                # Save coco summarize print information to logger
                redirect_string = io.StringIO()
                with contextlib.redirect_stdout(redirect_string):
                    cocoEval.summarize()
                print_log('\n' + redirect_string.getvalue(), logger=logger)

                if metric_items is None:
                    metric_items = [
                        'AR@100', 'AR@300', 'AR@1000', 'AR_s@1000',
                        'AR_m@1000', 'AR_l@1000'
                    ]

                for item in metric_items:
                    val = float(
                        f'{cocoEval.stats[coco_metric_names[item]]:.3f}')
                    eval_results[item] = val
            else:
                cocoEval.evaluate()
                cocoEval.accumulate()

                # Save coco summarize print information to logger
                redirect_string = io.StringIO()
                with contextlib.redirect_stdout(redirect_string):
                    cocoEval.summarize()
                print_log('\n' + redirect_string.getvalue(), logger=logger)

                if classwise:  # Compute per-category AP
                    # Compute per-category AP
                    # from https://github.com/facebookresearch/detectron2/
                    precisions = cocoEval.eval['precision']
                    # precision: (iou, recall, cls, area range, max dets)
                    assert len(self.cat_ids) == precisions.shape[2]

                    results_per_category = []
                    for idx, catId in enumerate(self.cat_ids):
                        # area range index 0: all area ranges
                        # max dets index -1: typically 100 per image
                        nm = self.coco.loadCats(catId)[0]
                        precision = precisions[:, :, idx, 0, -1]
                        precision = precision[precision > -1]
                        if precision.size:
                            ap = np.mean(precision)
                        else:
                            ap = float('nan')
                        results_per_category.append(
                            (f'{nm["name"]}', f'{float(ap):0.3f}'))

                    num_columns = min(6, len(results_per_category) * 2)
                    results_flatten = list(
                        itertools.chain(*results_per_category))
                    headers = ['category', 'AP'] * (num_columns // 2)
                    results_2d = itertools.zip_longest(*[
                        results_flatten[i::num_columns]
                        for i in range(num_columns)
                    ])
                    table_data = [headers]
                    table_data += [result for result in results_2d]
                    table = AsciiTable(table_data)
                    print_log('\n' + table.table, logger=logger)

                if metric_items is None:
                    metric_items = [
                        'mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'
                    ]

                for metric_item in metric_items:
                    key = f'{metric}_{metric_item}'
                    val = float(
                        f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}'
                    )
                    eval_results[key] = val
                ap = cocoEval.stats[:6]
                eval_results[f'{metric}_mAP_copypaste'] = (
                    f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} '
                    f'{ap[4]:.3f} {ap[5]:.3f}')
        if tmp_dir is not None:
            tmp_dir.cleanup()
        return eval_results
Overwriting /content/mmdetection/mmdet/datasets/coco.py

Resume Experiment or Start a new training

In [ ]:
import re
#if you want to continue experiment from your last checkpoint, set the RESUME to True and paste the model path in model_path variable,
#don't forget to use the same architecture/parameters in above config

RESUME = False
if RESUME:
  model_path = "'/content/drive/MyDrive/log_mmdet/latest.pth'"
  fname = '/content/mmdetection/configs/_base_/default_runtime.py'
  with open(fname) as f:
      s = f.read()
      s = re.sub('resume_from = None',
                'resume_from = {}'.format(model_path), s)
      s = re.sub(r'CLASSES = \(.*?\)',"EMPTY",s)

  with open(fname, 'w') as f:
      f.write(s)

Training the Model 🚂

Finally training our model!

In [ ]:
#Lets train the model
!python mmdetection/tools/train.py {config_fname} --work-dir '/content/drive/MyDrive/log_mmdet' --no-validate
fatal: not a git repository (or any of the parent directories): .git
2022-02-08 14:34:12,587 - mmdet - INFO - Environment info:
------------------------------------------------------------
sys.platform: linux
Python: 3.7.12 (default, Jan 15 2022, 18:48:18) [GCC 7.5.0]
CUDA available: True
GPU 0: Tesla P100-PCIE-16GB
CUDA_HOME: /usr/local/cuda
NVCC: Build cuda_11.1.TC455_06.29190527_0
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.10.0+cu111
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.1
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  - CuDNN 8.0.5
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, 

TorchVision: 0.11.1+cu111
OpenCV: 4.1.2
MMCV: 1.4.4
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 11.1
MMDetection: 2.21.0+
------------------------------------------------------------

2022-02-08 14:34:13,048 - mmdet - INFO - Distributed training: False
2022-02-08 14:34:13,500 - mmdet - INFO - Config:
dataset_type = 'CocoDataset'
data_root = 'data/'
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
    dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(
        type='Normalize',
        mean=[123.675, 116.28, 103.53],
        std=[58.395, 57.12, 57.375],
        to_rgb=True),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks'])
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(1333, 800),
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip', flip_ratio=0.5),
            dict(
                type='Normalize',
                mean=[123.675, 116.28, 103.53],
                std=[58.395, 57.12, 57.375],
                to_rgb=True),
            dict(type='Pad', size_divisor=32),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img'])
        ])
]
data = dict(
    samples_per_gpu=6,
    workers_per_gpu=0,
    train=dict(
        type='CocoDataset',
        ann_file='data/train/new_ann.json',
        img_prefix='data/train/images/',
        pipeline=[
            dict(type='LoadImageFromFile'),
            dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
            dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
            dict(type='RandomFlip', flip_ratio=0.5),
            dict(
                type='Normalize',
                mean=[123.675, 116.28, 103.53],
                std=[58.395, 57.12, 57.375],
                to_rgb=True),
            dict(type='Pad', size_divisor=32),
            dict(type='DefaultFormatBundle'),
            dict(
                type='Collect',
                keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks'])
        ]),
    val=dict(
        type='CocoDataset',
        ann_file='data/val/new_ann.json',
        img_prefix='data/val/images/',
        pipeline=[
            dict(type='LoadImageFromFile'),
            dict(
                type='MultiScaleFlipAug',
                img_scale=(1333, 800),
                flip=False,
                transforms=[
                    dict(type='Resize', keep_ratio=True),
                    dict(type='RandomFlip', flip_ratio=0.5),
                    dict(
                        type='Normalize',
                        mean=[123.675, 116.28, 103.53],
                        std=[58.395, 57.12, 57.375],
                        to_rgb=True),
                    dict(type='Pad', size_divisor=32),
                    dict(type='ImageToTensor', keys=['img']),
                    dict(type='Collect', keys=['img'])
                ])
        ]),
    test=dict(
        type='CocoDataset',
        ann_file='data/val/new_ann.json',
        img_prefix='data/val/images/',
        pipeline=[
            dict(type='LoadImageFromFile'),
            dict(
                type='MultiScaleFlipAug',
                img_scale=(1333, 800),
                flip=False,
                transforms=[
                    dict(type='Resize', keep_ratio=True),
                    dict(type='RandomFlip', flip_ratio=0.5),
                    dict(
                        type='Normalize',
                        mean=[123.675, 116.28, 103.53],
                        std=[58.395, 57.12, 57.375],
                        to_rgb=True),
                    dict(type='Pad', size_divisor=32),
                    dict(type='ImageToTensor', keys=['img']),
                    dict(type='Collect', keys=['img'])
                ])
        ]))
evaluation = dict(metric=['bbox', 'segm'])
optimizer = dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001)
optimizer_config = dict(grad_clip=None)
lr_config = dict(
    policy='step',
    warmup='linear',
    warmup_iters=500,
    warmup_ratio=0.001,
    step=[8, 11])
runner = dict(type='EpochBasedRunner', max_epochs=22)
checkpoint_config = dict(interval=1)
log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')])
custom_hooks = [dict(type='NumClassCheckHook')]
dist_params = dict(backend='nccl')
log_level = 'INFO'
load_from = None
resume_from = None
workflow = [('train', 1)]
opencv_num_threads = 0
mp_start_method = 'fork'
model = dict(
    type='HybridTaskCascade',
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(0, 1, 2, 3),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=True),
        norm_eval=True,
        style='pytorch',
        init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
    neck=dict(
        type='FPN',
        in_channels=[256, 512, 1024, 2048],
        out_channels=256,
        num_outs=5),
    rpn_head=dict(
        type='RPNHead',
        in_channels=256,
        feat_channels=256,
        anchor_generator=dict(
            type='AnchorGenerator',
            scales=[8],
            ratios=[0.5, 1.0, 2.0],
            strides=[4, 8, 16, 32, 64]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[0.0, 0.0, 0.0, 0.0],
            target_stds=[1.0, 1.0, 1.0, 1.0]),
        loss_cls=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
        loss_bbox=dict(
            type='SmoothL1Loss', beta=0.1111111111111111, loss_weight=1.0)),
    roi_head=dict(
        type='HybridTaskCascadeRoIHead',
        interleaved=True,
        mask_info_flow=True,
        num_stages=3,
        stage_loss_weights=[1, 0.5, 0.25],
        bbox_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        bbox_head=[
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0.0, 0.0, 0.0, 0.0],
                    target_stds=[0.1, 0.1, 0.2, 0.2]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0.0, 0.0, 0.0, 0.0],
                    target_stds=[0.05, 0.05, 0.1, 0.1]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
                               loss_weight=1.0)),
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=498,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[0.0, 0.0, 0.0, 0.0],
                    target_stds=[0.033, 0.033, 0.067, 0.067]),
                reg_class_agnostic=True,
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))
        ],
        mask_roi_extractor=dict(
            type='SingleRoIExtractor',
            roi_layer=dict(type='RoIAlign', output_size=14, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        mask_head=[
            dict(
                type='HTCMaskHead',
                with_conv_res=False,
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0)),
            dict(
                type='HTCMaskHead',
                num_convs=4,
                in_channels=256,
                conv_out_channels=256,
                num_classes=498,
                loss_mask=dict(
                    type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))
        ]),
    train_cfg=dict(
        rpn=dict(
            assigner=dict(
                type='MaxIoUAssigner',
                pos_iou_thr=0.7,
                neg_iou_thr=0.3,
                min_pos_iou=0.3,
                ignore_iof_thr=-1),
            sampler=dict(
                type='RandomSampler',
                num=256,
                pos_fraction=0.5,
                neg_pos_ub=-1,
                add_gt_as_proposals=False),
            allowed_border=0,
            pos_weight=-1,
            debug=False),
        rpn_proposal=dict(
            nms_pre=2000,
            max_per_img=2000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=[
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.5,
                    neg_iou_thr=0.5,
                    min_pos_iou=0.5,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.6,
                    neg_iou_thr=0.6,
                    min_pos_iou=0.6,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False),
            dict(
                assigner=dict(
                    type='MaxIoUAssigner',
                    pos_iou_thr=0.7,
                    neg_iou_thr=0.7,
                    min_pos_iou=0.7,
                    ignore_iof_thr=-1),
                sampler=dict(
                    type='RandomSampler',
                    num=512,
                    pos_fraction=0.25,
                    neg_pos_ub=-1,
                    add_gt_as_proposals=True),
                mask_size=28,
                pos_weight=-1,
                debug=False)
        ]),
    test_cfg=dict(
        rpn=dict(
            nms_pre=1000,
            max_per_img=1000,
            nms=dict(type='nms', iou_threshold=0.7),
            min_bbox_size=0),
        rcnn=dict(
            score_thr=0.001,
            nms=dict(type='nms', iou_threshold=0.5),
            max_per_img=100,
            mask_thr_binary=0.5)))
work_dir = '/content/drive/MyDrive/log_mmdet'
auto_resume = False
gpu_ids = [0]

2022-02-08 14:34:13,574 - mmdet - INFO - Set random seed to 1159096791, deterministic: False
2022-02-08 14:34:14,563 - mmdet - INFO - initialize ResNet with init_cfg {'type': 'Pretrained', 'checkpoint': 'torchvision://resnet50'}
2022-02-08 14:34:14,564 - mmcv - INFO - load model from: torchvision://resnet50
2022-02-08 14:34:14,564 - mmcv - INFO - load checkpoint from torchvision path: torchvision://resnet50
Downloading: "https://download.pytorch.org/models/resnet50-0676ba61.pth" to /root/.cache/torch/hub/checkpoints/resnet50-0676ba61.pth
100% 97.8M/97.8M [00:00<00:00, 123MB/s]
2022-02-08 14:34:15,642 - mmcv - WARNING - The model and loaded state dict do not match exactly

unexpected key in source state_dict: fc.weight, fc.bias

2022-02-08 14:34:15,669 - mmdet - INFO - initialize FPN with init_cfg {'type': 'Xavier', 'layer': 'Conv2d', 'distribution': 'uniform'}
2022-02-08 14:34:15,694 - mmdet - INFO - initialize RPNHead with init_cfg {'type': 'Normal', 'layer': 'Conv2d', 'std': 0.01}
2022-02-08 14:34:15,705 - mmdet - INFO - initialize Shared2FCBBoxHead with init_cfg [{'type': 'Normal', 'std': 0.01, 'override': {'name': 'fc_cls'}}, {'type': 'Normal', 'std': 0.001, 'override': {'name': 'fc_reg'}}, {'type': 'Xavier', 'distribution': 'uniform', 'override': [{'name': 'shared_fcs'}, {'name': 'cls_fcs'}, {'name': 'reg_fcs'}]}]
2022-02-08 14:34:15,821 - mmdet - INFO - initialize Shared2FCBBoxHead with init_cfg [{'type': 'Normal', 'std': 0.01, 'override': {'name': 'fc_cls'}}, {'type': 'Normal', 'std': 0.001, 'override': {'name': 'fc_reg'}}, {'type': 'Xavier', 'distribution': 'uniform', 'override': [{'name': 'shared_fcs'}, {'name': 'cls_fcs'}, {'name': 'reg_fcs'}]}]
2022-02-08 14:34:15,933 - mmdet - INFO - initialize Shared2FCBBoxHead with init_cfg [{'type': 'Normal', 'std': 0.01, 'override': {'name': 'fc_cls'}}, {'type': 'Normal', 'std': 0.001, 'override': {'name': 'fc_reg'}}, {'type': 'Xavier', 'distribution': 'uniform', 'override': [{'name': 'shared_fcs'}, {'name': 'cls_fcs'}, {'name': 'reg_fcs'}]}]
loading annotations into memory...
Done (t=3.18s)
creating index...
index created!
fatal: not a git repository (or any of the parent directories): .git
2022-02-08 14:34:28,452 - mmdet - INFO - Start running, host: root@a13ebaa82cca, work_dir: /content/drive/MyDrive/log_mmdet
2022-02-08 14:34:28,452 - mmdet - INFO - Hooks will be executed in the following order:
before_run:
(VERY_HIGH   ) StepLrUpdaterHook                  
(NORMAL      ) CheckpointHook                     
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
before_train_epoch:
(VERY_HIGH   ) StepLrUpdaterHook                  
(NORMAL      ) NumClassCheckHook                  
(LOW         ) IterTimerHook                      
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
before_train_iter:
(VERY_HIGH   ) StepLrUpdaterHook                  
(LOW         ) IterTimerHook                      
 -------------------- 
after_train_iter:
(ABOVE_NORMAL) OptimizerHook                      
(NORMAL      ) CheckpointHook                     
(LOW         ) IterTimerHook                      
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
after_train_epoch:
(NORMAL      ) CheckpointHook                     
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
before_val_epoch:
(NORMAL      ) NumClassCheckHook                  
(LOW         ) IterTimerHook                      
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
before_val_iter:
(LOW         ) IterTimerHook                      
 -------------------- 
after_val_iter:
(LOW         ) IterTimerHook                      
 -------------------- 
after_val_epoch:
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
after_run:
(VERY_LOW    ) TextLoggerHook                     
 -------------------- 
2022-02-08 14:34:28,452 - mmdet - INFO - workflow: [('train', 1)], max: 22 epochs
2022-02-08 14:34:28,453 - mmdet - INFO - Checkpoints will be saved to /content/drive/MyDrive/log_mmdet by HardDiskBackend.
2022-02-08 14:35:32,284 - mmdet - INFO - Epoch [1][50/6661]	lr: 2.473e-04, eta: 2 days, 3:52:54, time: 1.275, data_time: 0.254, memory: 8910, loss_rpn_cls: 0.4932, loss_rpn_bbox: 0.0151, s0.loss_cls: 2.7474, s0.acc: 72.7083, s0.loss_bbox: 0.0436, s0.loss_mask: 0.7132, s1.loss_cls: 1.5067, s1.acc: 64.1074, s1.loss_bbox: 0.0119, s1.loss_mask: 0.3636, s2.loss_cls: 0.8323, s2.acc: 54.0618, s2.loss_bbox: 0.0017, s2.loss_mask: 0.1825, loss: 6.9112
2022-02-08 14:36:37,741 - mmdet - INFO - Epoch [1][100/6661]	lr: 4.970e-04, eta: 2 days, 4:33:33, time: 1.309, data_time: 0.215, memory: 8910, loss_rpn_cls: 0.0551, loss_rpn_bbox: 0.0112, s0.loss_cls: 0.3312, s0.acc: 96.3633, s0.loss_bbox: 0.0901, s0.loss_mask: 0.6976, s1.loss_cls: 0.0815, s1.acc: 98.4408, s1.loss_bbox: 0.0270, s1.loss_mask: 0.3520, s2.loss_cls: 0.0226, s2.acc: 99.3079, s2.loss_bbox: 0.0035, s2.loss_mask: 0.1748, loss: 1.8465
Traceback (most recent call last):
  File "mmdetection/tools/train.py", line 209, in <module>
    main()
  File "mmdetection/tools/train.py", line 205, in main
    meta=meta)
  File "/content/mmdetection/mmdet/apis/train.py", line 208, in train_detector
    runner.run(data_loaders, cfg.workflow)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/epoch_based_runner.py", line 127, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/epoch_based_runner.py", line 50, in train
    self.run_iter(data_batch, train_mode=True, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/epoch_based_runner.py", line 30, in run_iter
    **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/parallel/data_parallel.py", line 75, in train_step
    return self.module.train_step(*inputs[0], **kwargs[0])
  File "/content/mmdetection/mmdet/models/detectors/base.py", line 248, in train_step
    losses = self(**data)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/fp16_utils.py", line 109, in new_func
    return old_func(*args, **kwargs)
  File "/content/mmdetection/mmdet/models/detectors/base.py", line 172, in forward
    return self.forward_train(img, img_metas, **kwargs)
  File "/content/mmdetection/mmdet/models/detectors/two_stage.py", line 150, in forward_train
    **kwargs)
  File "/content/mmdetection/mmdet/models/roi_heads/htc_roi_head.py", line 283, in forward_train
    rcnn_train_cfg, semantic_feat)
  File "/content/mmdetection/mmdet/models/roi_heads/htc_roi_head.py", line 98, in _bbox_forward_train
    stage, x, rois, semantic_feat=semantic_feat)
  File "/content/mmdetection/mmdet/models/roi_heads/htc_roi_head.py", line 163, in _bbox_forward
    x[:len(bbox_roi_extractor.featmap_strides)], rois)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/fp16_utils.py", line 197, in new_func
    return old_func(*args, **kwargs)
  File "/content/mmdetection/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py", line 100, in forward
    inds = mask.nonzero(as_tuple=False).squeeze(1)
KeyboardInterrupt

Testing

In [ ]:
#lets get the latest checkpoint file 

work_dir = "/content/drive/MyDrive/log_mmdet"
checkpoint_file = os.path.join(work_dir, "latest.pth")
assert os.path.isfile(
    checkpoint_file), '`{}` not exist'.format(checkpoint_file)
checkpoint_file = os.path.abspath(checkpoint_file)
checkpoint_file
Out[ ]:
'/content/drive/MyDrive/log_mmdet/latest.pth'
In [ ]:
#Lets visualize some results
import time
import matplotlib
import matplotlib.pylab as plt
plt.rcParams["axes.grid"] = False

import mmcv
from mmcv.runner import load_checkpoint
import mmcv.visualization.image as mmcv_image
# fix for colab

def imshow(img, win_name='', wait_time=0): plt.figure(
    figsize=(50, 50)); plt.imshow(img)


mmcv_image.imshow = imshow
from mmdet.models import build_detector
from mmdet.apis import inference_detector, show_result_pyplot, init_detector


score_thr = 0.1 #decrease the threshold if you feel like you are missing some predictions


# build the model from a config file and a checkpoint file
model = init_detector(config_fname, checkpoint_file)

# test a single image and show the results
img = '/content/data/val/images/008082.jpg'   #you can change this to any image you want!

result = inference_detector(model, img)
show_result_pyplot(model, img, result, score_thr=0.1, title='result', wait_time=0)
load checkpoint from local path: /content/drive/MyDrive/log_mmdet/latest.pth
/content/mmdetection/mmdet/datasets/utils.py:69: UserWarning: "ImageToTensor" pipeline is replaced by "DefaultFormatBundle" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.
  'data pipeline in your config file.', UserWarning)

Create categories files for correct annotations during inference

In [ ]:
import json, os
annotation_path = os.path.join("data", "train/annotations.json")
json_file = open(annotation_path)
coco = json.load(json_file)

with open("classes.json",'w') as f:
    json.dump(coco["categories"],f)

Copy the config file and trained model

In [ ]:
#copy the trained model and config file to home directory
%cp /content/drive/MyDrive/log_mmdet/htc_without_semantic_r50_fpn_1x_coco.py /content/htc_without_semantic_r50_fpn_1x_coco.py
%cp /content/drive/MyDrive/log_mmdet/latest.pth /content/latest.pth

Quick Submission 💪

Inference on the public test set

  • loading the model config and setting up related paths
  • running inference and generating json file for submission
In [ ]:
#@title Inference code from myfood exp repo, Used for quick submission
%%writefile inference_mmdet.py
'''
@Author: Gaurav Singhal
@Description: Standalone file for testing and evaluating
the models. It doesn't do any post-processing or ensembling.
'''

import argparse
import os
import warnings
import glob
import json
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
                         wrap_fp16_model)
from mmdet.apis import init_detector, inference_detector

from mmdet.apis import multi_gpu_test
from mmdet.datasets import (build_dataloader, build_dataset,
                            replace_ImageToTensor)
from mmdet.models import build_detector
# import aicrowd_helpers
import os.path as osp
import traceback
import pickle
import shutil
import tempfile
import time
import torch.distributed as dist
from mmcv.image import tensor2imgs
from mmdet.core import encode_mask_results

import uuid

# TEST_IMAGES_PATH = "/mnt/public/xxx/imrec/data/val/images"

def create_test_predictions(images_path):
    test_predictions_file = tempfile.NamedTemporaryFile(mode="w+", suffix=".json")
	
    annotations = {'categories': [], 'info': {}, 'images': []}
    for item in glob.glob(images_path+'/*.jpg'):
        image_dict = dict()
        img = mmcv.imread(item)
        height,width,__ = img.shape
        id = int(os.path.basename(item).split('.')[0])
        image_dict['id'] = id
        image_dict['file_name'] = os.path.basename(item)
        image_dict['width'] = width
        image_dict['height'] = height
        annotations['images'].append(image_dict)
    annotations['categories'] = json.loads(open("classes.json").read())
    json.dump(annotations, open(test_predictions_file.name, 'w'))

    return test_predictions_file

def single_gpu_test(model,
                    data_loader,
                    show=False,
                    out_dir=None,
                    show_score_thr=0.3):
    
    model.eval()
    results = []
    dataset = data_loader.dataset
    prog_bar = mmcv.ProgressBar(len(dataset))
    for i, data in enumerate(data_loader):
        # aicrowd_helpers.execution_progress({"image_ids" : [i]})
        with torch.no_grad():
            result = model(return_loss=False, rescale=True, **data)

        batch_size = len(result)
        if show or out_dir:
            if batch_size == 1 and isinstance(data['img'][0], torch.Tensor):
                img_tensor = data['img'][0]
            else:
                img_tensor = data['img'][0].data[0]
            img_metas = data['img_metas'][0].data[0]
            imgs = tensor2imgs(img_tensor, **img_metas[0]['img_norm_cfg'])
            assert len(imgs) == len(img_metas)

            for i, (img, img_meta) in enumerate(zip(imgs, img_metas)):
                h, w, _ = img_meta['img_shape']
                img_show = img[:h, :w, :]

                ori_h, ori_w = img_meta['ori_shape'][:-1]
                img_show = mmcv.imresize(img_show, (ori_w, ori_h))

                if out_dir:
                    out_file = osp.join(out_dir, img_meta['ori_filename'])
                else:
                    out_file = None

                model.module.show_result(
                    img_show,
                    result[i],
                    show=show,
                    out_file=out_file,
                    score_thr=show_score_thr)

        # Perform RLE encode for masks
        if isinstance(result[0], tuple):
            result = [(bbox_results, encode_mask_results(mask_results))
                      for bbox_results, mask_results in result]
        results.extend(result)

        for _ in range(batch_size):
            prog_bar.update()
    return results

def parse_args():
    parser = argparse.ArgumentParser(
        description='MMDet test (and eval) a model')
    parser.add_argument('--config', help='test config file path')
    parser.add_argument('--checkpoint', help='checkpoint file')
    parser.add_argument('--data', help='test data folder path')
    parser.add_argument('--out', help='output result file in pickle format')
    parser.add_argument(
        '--fuse-conv-bn',
        action='store_true',
        help='Whether to fuse conv and bn, this will slightly increase'
        'the inference speed')
    parser.add_argument(
        '--format-only',
        action='store_true',
        help='Format the output results without perform evaluation. It is'
        'useful when you want to format the result to a specific format and '
        'submit it to the test server')
    parser.add_argument(
        '--eval',
        type=str,
        nargs='+',
        help='evaluation metrics, which depends on the dataset, e.g., "bbox",'
        ' "segm", "proposal" for COCO, and "mAP", "recall" for PASCAL VOC')
    parser.add_argument('--show', action='store_true', help='show results')
    parser.add_argument(
        '--show-dir', help='directory where painted images will be saved')
    parser.add_argument(
        '--show-score-thr',
        type=float,
        default=0.3,
        help='score threshold (default: 0.3)')
    parser.add_argument(
        '--gpu-collect',
        action='store_true',
        help='whether to use gpu to collect results.')
    parser.add_argument(
        '--tmpdir',
        help='tmp directory used for collecting results from multiple '
        'workers, available when gpu-collect is not specified')
    parser.add_argument(
        '--cfg-options',
        nargs='+',
        action=DictAction,
        help='override some settings in the used config, the key-value pair '
        'in xxx=yyy format will be merged into config file.')
    parser.add_argument(
        '--options',
        nargs='+',
        action=DictAction,
        help='custom options for evaluation, the key-value pair in xxx=yyy '
        'format will be kwargs for dataset.evaluate() function (deprecate), '
        'change to --eval-options instead.')
    parser.add_argument(
        '--eval-options',
        nargs='+',
        action=DictAction,
        help='custom options for evaluation, the key-value pair in xxx=yyy '
        'format will be kwargs for dataset.evaluate() function')
    parser.add_argument(
        '--launcher',
        choices=['none', 'pytorch', 'slurm', 'mpi'],
        default='none',
        help='job launcher')
    parser.add_argument('--out_file', help='output result file')
    parser.add_argument('--local_rank', type=int, default=0)
    parser.add_argument('--type', type=str, choices=['val', 'test'], default='test')
    parser.add_argument('--reduce_ms', action='store_true',
        help='Whether to reduce the multi-scale aug')
    args = parser.parse_args()

    if 'LOCAL_RANK' not in os.environ:
        os.environ['LOCAL_RANK'] = str(args.local_rank)

    if args.options and args.eval_options:
        raise ValueError(
            '--options and --eval-options cannot be both '
            'specified, --options is deprecated in favor of --eval-options')
    if args.options:
        warnings.warn('--options is deprecated in favor of --eval-options')
        args.eval_options = args.options
    return args

def reduce_multiscale_TTA(cfg):
    '''
    Keep only 1st and last image sizes from Multi-Scale TTA
    
    @input
    cfg -> Configuration file
    '''

    scale = cfg.data.test.pipeline[1]['img_scale']
    if len(scale) > 2:
        new_scale = [scale[0], scale[-1]]
        cfg.data.test.pipeline[1]['img_scale'] = new_scale   
    return cfg

def main():
    ########################################################################
    # Register Prediction Start
    ########################################################################

    # aicrowd_helpers.execution_start()
    args = parse_args()
    data_folder = args.data
    # Create annotations if not already created
    test_predictions_file = create_test_predictions(data_folder)
    
    # Load annotations
    with open(test_predictions_file.name) as f:
        annotations = json.loads(f.read())

    assert args.out or args.eval or args.format_only or args.show \
        or args.show_dir, \
        ('Please specify at least one operation (save/eval/format/show the '
         'results / save the results) with the argument "--out", "--eval"'
         ', "--format-only", "--show" or "--show-dir"')

    if args.eval and args.format_only:
        raise ValueError('--eval and --format_only cannot be both specified')

    if args.out is not None and not args.out.endswith(('.pkl', '.pickle')):
        raise ValueError('The output file must be a pkl file.')

    cfg = Config.fromfile(args.config)
    if args.cfg_options is not None:
        cfg.merge_from_dict(args.cfg_options)
    
    JSONFILE_PREFIX="predictions_{}".format(str(uuid.uuid4())) 
    # import modules present in list of strings.
    if cfg.get('custom_imports', None):
        from mmcv.utils import import_modules_from_strings
        import_modules_from_strings(**cfg['custom_imports'])
    
    # set cudnn_benchmark
    if cfg.get('cudnn_benchmark', False):
        torch.backends.cudnn.benchmark = True
    
    cfg.data.samples_per_gpu = 1
    cfg.data.workers_per_gpu = 2
    cfg.model.pretrained = None
    cfg.data.test.test_mode = True
    cfg.data.test.ann_file = test_predictions_file.name
    cfg.data.test.img_prefix = data_folder

    if cfg.model.get('neck'):
        if isinstance(cfg.model.neck, list):
            for neck_cfg in cfg.model.neck:
                if neck_cfg.get('rfp_backbone'):
                    if neck_cfg.rfp_backbone.get('pretrained'):
                        neck_cfg.rfp_backbone.pretrained = None
        elif cfg.model.neck.get('rfp_backbone'):
            if cfg.model.neck.rfp_backbone.get('pretrained'):
                cfg.model.neck.rfp_backbone.pretrained = None

    # in case the test dataset is concatenated
    if isinstance(cfg.data.test, dict):
        cfg.data.test.test_mode = True
    elif isinstance(cfg.data.test, list):
        for ds_cfg in cfg.data.test:
            ds_cfg.test_mode = True

    cfg.data.test.ann_file = test_predictions_file.name
    cfg.data.test.img_prefix = data_folder
        
    # if args.reduce_ms:
    #     print("Reduce multi-scale TTA")
    #     cfg = reduce_multiscale_tta(cfg)
    #     print(cfg.data.test.pipeline[1]['img_scale'])
        
    if args.launcher == 'none':
        distributed = False
    else:
        distributed = True
        init_dist(args.launcher, **cfg.dist_params)
    
    # build the dataloader
    samples_per_gpu = cfg.data.test.pop('samples_per_gpu', 1)
    if samples_per_gpu > 1:
        # Replace 'ImageToTensor' to 'DefaultFormatBundle'
        cfg.data.test.pipeline = replace_ImageToTensor(cfg.data.test.pipeline)
    dataset = build_dataset(cfg.data.test)
    print(dataset)
    dataset.cat_ids = [category["id"] for category in annotations["categories"]]
    data_loader = build_dataloader(
        dataset,
        samples_per_gpu=1,
        workers_per_gpu=2,
        dist=distributed,
        shuffle=False)

    # build the model and load checkpoint
    # model = build_detector(cfg.model, train_cfg=None, test_cfg=cfg.model.test_cfg)
    model = init_detector(args.config,args.checkpoint,device='cuda:0')

    fp16_cfg = cfg.get('fp16', None)
    if fp16_cfg is not None:
        wrap_fp16_model(model)
    # checkpoint = load_checkpoint(model, args.checkpoint, map_location='cuda')
    if args.fuse_conv_bn:
        model = fuse_conv_bn(model)

    model.CLASSES = [category['name'] for category in annotations['categories']]
    # if 'CLASSES' in checkpoint['meta']:
        # model.CLASSES = checkpoint['meta']['CLASSES']
    # else:
        # model.CLASSES = dataset.CLASSES

    if not distributed:
        model = MMDataParallel(model, device_ids=[0])
        outputs = single_gpu_test(model, data_loader, args.show, args.show_dir,
                                  args.show_score_thr)
    else:
        model = MMDistributedDataParallel(
            model.cuda(),
            device_ids=[torch.cuda.current_device()],
            broadcast_buffers=False)
        outputs = multi_gpu_test(model, data_loader, args.tmpdir,
                                 args.gpu_collect)

    rank, _ = get_dist_info()
    if rank == 0:
        if args.out:
            print(f'\nwriting results to {args.out}')
            mmcv.dump(outputs, args.out)
        kwargs = {} if args.eval_options is None else args.eval_options
        if args.format_only:
            dataset.format_results(outputs, **kwargs)
        if args.eval:
            eval_kwargs = cfg.get('evaluation', {}).copy()
            for key in ['interval', 'tmpdir', 'start', 'gpu_collect']:
                eval_kwargs.pop(key, None)
            eval_kwargs.update(dict(metric=args.eval, **kwargs))
            print(dataset.evaluate(outputs, **eval_kwargs))
    
    # consolidate_results(["predictions.segm.json"], 'test_predictions.json', args.out_file)
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    # aicrowd_helpers.execution_success({
    #     "predictions_output_path" : args.out_file
    # })
    print("\nAICrowd register complete")
    # preds = []
    # with open("predictions.segm.json", "r") as pred_file:
    #     preds.extend(json.loads(pred_file.read()))
    # print(preds)
    JSONFILE_PREFIX = args.eval_options['jsonfile_prefix']
    shutil.move("{}.segm.json".format(JSONFILE_PREFIX), args.out_file)
    os.remove("{}.bbox.json".format(JSONFILE_PREFIX))
        
if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        error = traceback.format_exc()
        print(error)
Writing inference_mmdet.py
In [ ]:
#setting the paths for images and output file
test_images_dir="/content/data/test/images"
output_filepath="/content/predictions_mmdetection.json"

#path of trained model & config
model_path="/content/latest.pth"
config_file="/content/htc_without_semantic_r50_fpn_1x_coco.py"
In [ ]:
!python inference_mmdet.py --config $config_file --checkpoint $model_path \
--data $test_images_dir \
--format-only --eval-options "jsonfile_prefix=preds" --out_file $output_filepath
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!

CocoDataset Test dataset with number of images 3000, and instance counts: 
+----------------------------------------------------------------------+-------+--------------------------------------------------------------------------------+-------+-------------------------------------------------------------------------------+-------+------------------------------------------------------------------------+-------+-----------------------------------------------------------------+-------+
| category                                                             | count | category                                                                       | count | category                                                                      | count | category                                                               | count | category                                                        | count |
+----------------------------------------------------------------------+-------+--------------------------------------------------------------------------------+-------+-------------------------------------------------------------------------------+-------+------------------------------------------------------------------------+-------+-----------------------------------------------------------------+-------+
| 0 [bread-wholemeal]                                                  | 0     | 1 [jam]                                                                        | 0     | 2 [water]                                                                     | 0     | 3 [bread-sourdough]                                                    | 0     | 4 [banana]                                                      | 0     |
| 5 [soft-cheese]                                                      | 0     | 6 [ham-raw]                                                                    | 0     | 7 [hard-cheese]                                                               | 0     | 8 [cottage-cheese]                                                     | 0     | 9 [bread-half-white]                                            | 0     |
| 10 [coffee-with-caffeine]                                            | 0     | 11 [fruit-salad]                                                               | 0     | 12 [pancakes]                                                                 | 0     | 13 [tea]                                                               | 0     | 14 [salmon-smoked]                                              | 0     |
| 15 [avocado]                                                         | 0     | 16 [spring-onion-scallion]                                                     | 0     | 17 [ristretto-with-caffeine]                                                  | 0     | 18 [ham]                                                               | 0     | 19 [egg]                                                        | 0     |
| 20 [bacon-frying]                                                    | 0     | 21 [chips-french-fries]                                                        | 0     | 22 [juice-apple]                                                              | 0     | 23 [chicken]                                                           | 0     | 24 [tomato-raw]                                                 | 0     |
| 25 [broccoli]                                                        | 0     | 26 [shrimp-boiled]                                                             | 0     | 27 [beetroot-steamed-without-addition-of-salt]                                | 0     | 28 [carrot-raw]                                                        | 0     | 29 [chickpeas]                                                  | 0     |
| 30 [french-salad-dressing]                                           | 0     | 31 [pasta-hornli]                                                              | 0     | 32 [sauce-cream]                                                              | 0     | 33 [meat-balls]                                                        | 0     | 34 [pasta]                                                      | 0     |
| 35 [tomato-sauce]                                                    | 0     | 36 [cheese]                                                                    | 0     | 37 [pear]                                                                     | 0     | 38 [cashew-nut]                                                        | 0     | 39 [almonds]                                                    | 0     |
| 40 [lentils]                                                         | 0     | 41 [mixed-vegetables]                                                          | 0     | 42 [peanut-butter]                                                            | 0     | 43 [apple]                                                             | 0     | 44 [blueberries]                                                | 0     |
| 45 [cucumber]                                                        | 0     | 46 [cocoa-powder]                                                              | 0     | 47 [greek-yaourt-yahourt-yogourt-ou-yoghourt]                                 | 0     | 48 [maple-syrup-concentrate]                                           | 0     | 49 [buckwheat-grain-peeled]                                     | 0     |
| 50 [butter]                                                          | 0     | 51 [herbal-tea]                                                                | 0     | 52 [mayonnaise]                                                               | 0     | 53 [soup-vegetable]                                                    | 0     | 54 [wine-red]                                                   | 0     |
| 55 [wine-white]                                                      | 0     | 56 [green-bean-steamed-without-addition-of-salt]                               | 0     | 57 [sausage]                                                                  | 0     | 58 [pizza-margherita-baked]                                            | 0     | 59 [salami]                                                     | 0     |
| 60 [mushroom]                                                        | 0     | 61 [bread-meat-substitute-lettuce-sauce]                                       | 0     | 62 [tart]                                                                     | 0     | 63 [tea-verveine]                                                      | 0     | 64 [rice]                                                       | 0     |
| 65 [white-coffee-with-caffeine]                                      | 0     | 66 [linseeds]                                                                  | 0     | 67 [sunflower-seeds]                                                          | 0     | 68 [ham-cooked]                                                        | 0     | 69 [bell-pepper-red-raw]                                        | 0     |
| 70 [zucchini]                                                        | 0     | 71 [green-asparagus]                                                           | 0     | 72 [tartar-sauce]                                                             | 0     | 73 [lye-pretzel-soft]                                                  | 0     | 74 [cucumber-pickled]                                           | 0     |
| 75 [curry-vegetarian]                                                | 0     | 76 [yaourt-yahourt-yogourt-ou-yoghourt-natural]                                | 0     | 77 [soup-of-lentils-dahl-dhal]                                                | 0     | 78 [soup-cream-of-vegetables]                                          | 0     | 79 [balsamic-vinegar]                                           | 0     |
| 80 [salmon]                                                          | 0     | 81 [salt-cake-vegetables-filled]                                               | 0     | 82 [bacon]                                                                    | 0     | 83 [orange]                                                            | 0     | 84 [pasta-noodles]                                              | 0     |
| 85 [cream]                                                           | 0     | 86 [cake-chocolate]                                                            | 0     | 87 [pasta-spaghetti]                                                          | 0     | 88 [black-olives]                                                      | 0     | 89 [parmesan]                                                   | 0     |
| 90 [spaetzle]                                                        | 0     | 91 [salad-lambs-ear]                                                           | 0     | 92 [salad-leaf-salad-green]                                                   | 0     | 93 [potatoes-steamed]                                                  | 0     | 94 [white-cabbage]                                              | 0     |
| 95 [halloumi]                                                        | 0     | 96 [beetroot-raw]                                                              | 0     | 97 [bread-grain]                                                              | 0     | 98 [applesauce-unsweetened-canned]                                     | 0     | 99 [cheese-for-raclette]                                        | 0     |
| 100 [mushrooms]                                                      | 0     | 101 [bread-white]                                                              | 0     | 102 [curds-natural-with-at-most-10-fidm]                                      | 0     | 103 [bagel-without-filling]                                            | 0     | 104 [quiche-with-cheese-baked-with-puff-pastry]                 | 0     |
| 105 [soup-potato]                                                    | 0     | 106 [bouillon-vegetable]                                                       | 0     | 107 [beef-sirloin-steak]                                                      | 0     | 108 [taboule-prepared-with-couscous]                                   | 0     | 109 [eggplant]                                                  | 0     |
| 110 [bread]                                                          | 0     | 111 [turnover-with-meat-small-meat-pie-empanadas]                              | 0     | 112 [mungbean-sprouts]                                                        | 0     | 113 [mozzarella]                                                       | 0     | 114 [pasta-penne]                                               | 0     |
| 115 [lasagne-vegetable-prepared]                                     | 0     | 116 [mandarine]                                                                | 0     | 117 [kiwi]                                                                    | 0     | 118 [french-beans]                                                     | 0     | 119 [tartar-meat]                                               | 0     |
| 120 [spring-roll-fried]                                              | 0     | 121 [pork-chop]                                                                | 0     | 122 [caprese-salad-tomato-mozzarella]                                         | 0     | 123 [leaf-spinach]                                                     | 0     | 124 [roll-of-half-white-or-white-flour-with-large-void]         | 0     |
| 125 [pasta-ravioli-stuffing]                                         | 0     | 126 [omelette-plain]                                                           | 0     | 127 [tuna]                                                                    | 0     | 128 [dark-chocolate]                                                   | 0     | 129 [sauce-savoury]                                             | 0     |
| 130 [dried-raisins]                                                  | 0     | 131 [ice-tea]                                                                  | 0     | 132 [kaki]                                                                    | 0     | 133 [macaroon]                                                         | 0     | 134 [smoothie]                                                  | 0     |
| 135 [crepe-plain]                                                    | 0     | 136 [chicken-nuggets]                                                          | 0     | 137 [chili-con-carne-prepared]                                                | 0     | 138 [veggie-burger]                                                    | 0     | 139 [cream-spinach]                                             | 0     |
| 140 [cod]                                                            | 0     | 141 [chinese-cabbage]                                                          | 0     | 142 [hamburger-bread-meat-ketchup]                                            | 0     | 143 [soup-pumpkin]                                                     | 0     | 144 [sushi]                                                     | 0     |
| 145 [chestnuts]                                                      | 0     | 146 [coffee-decaffeinated]                                                     | 0     | 147 [sauce-soya]                                                              | 0     | 148 [balsamic-salad-dressing]                                          | 0     | 149 [pasta-twist]                                               | 0     |
| 150 [bolognaise-sauce]                                               | 0     | 151 [leek]                                                                     | 0     | 152 [fajita-bread-only]                                                       | 0     | 153 [potato-gnocchi]                                                   | 0     | 154 [beef-cut-into-stripes-only-meat]                           | 0     |
| 155 [rice-noodles-vermicelli]                                        | 0     | 156 [tea-ginger]                                                               | 0     | 157 [tea-green]                                                               | 0     | 158 [bread-whole-wheat]                                                | 0     | 159 [onion]                                                     | 0     |
| 160 [garlic]                                                         | 0     | 161 [hummus]                                                                   | 0     | 162 [pizza-with-vegetables-baked]                                             | 0     | 163 [beer]                                                             | 0     | 164 [glucose-drink-50g]                                         | 0     |
| 165 [chicken-wing]                                                   | 0     | 166 [ratatouille]                                                              | 0     | 167 [peanut]                                                                  | 0     | 168 [high-protein-pasta-made-of-lentils-peas]                          | 0     | 169 [cauliflower]                                               | 0     |
| 170 [quiche-with-spinach-baked-with-cake-dough]                      | 0     | 171 [green-olives]                                                             | 0     | 172 [brazil-nut]                                                              | 0     | 173 [eggplant-caviar]                                                  | 0     | 174 [bread-pita]                                                | 0     |
| 175 [pasta-wholemeal]                                                | 0     | 176 [sauce-pesto]                                                              | 0     | 177 [oil]                                                                     | 0     | 178 [couscous]                                                         | 0     | 179 [sauce-roast]                                               | 0     |
| 180 [prosecco]                                                       | 0     | 181 [crackers]                                                                 | 0     | 182 [bread-toast]                                                             | 0     | 183 [shrimp-prawn-small]                                               | 0     | 184 [panna-cotta]                                               | 0     |
| 185 [romanesco]                                                      | 0     | 186 [water-with-lemon-juice]                                                   | 0     | 187 [espresso-with-caffeine]                                                  | 0     | 188 [egg-scrambled-prepared]                                           | 0     | 189 [juice-orange]                                              | 0     |
| 190 [ice-cubes]                                                      | 0     | 191 [braided-white-loaf]                                                       | 0     | 192 [emmental-cheese]                                                         | 0     | 193 [croissant-wholegrain]                                             | 0     | 194 [hazelnut-chocolate-spread-nutella-ovomaltine-caotina]      | 0     |
| 195 [tomme]                                                          | 0     | 196 [water-mineral]                                                            | 0     | 197 [hazelnut]                                                                | 0     | 198 [bacon-raw]                                                        | 0     | 199 [bread-nut]                                                 | 0     |
| 200 [black-forest-tart]                                              | 0     | 201 [soup-miso]                                                                | 0     | 202 [peach]                                                                   | 0     | 203 [figs]                                                             | 0     | 204 [beef-filet]                                                | 0     |
| 205 [mustard-dijon]                                                  | 0     | 206 [rice-basmati]                                                             | 0     | 207 [mashed-potatoes-prepared-with-full-fat-milk-with-butter]                 | 0     | 208 [dumplings]                                                        | 0     | 209 [pumpkin]                                                   | 0     |
| 210 [swiss-chard]                                                    | 0     | 211 [red-cabbage]                                                              | 0     | 212 [spinach-raw]                                                             | 0     | 213 [naan-indien-bread]                                                | 0     | 214 [chicken-curry-cream-coconut-milk-curry-spices-paste]       | 0     |
| 215 [crunch-muesli]                                                  | 0     | 216 [biscuits]                                                                 | 0     | 217 [bread-french-white-flour]                                                | 0     | 218 [meatloaf]                                                         | 0     | 219 [fresh-cheese]                                              | 0     |
| 220 [honey]                                                          | 0     | 221 [vegetable-mix-peas-and-carrots]                                           | 0     | 222 [parsley]                                                                 | 0     | 223 [brownie]                                                          | 0     | 224 [dairy-ice-cream]                                           | 0     |
| 225 [tea-black]                                                      | 0     | 226 [carrot-cake]                                                              | 0     | 227 [fish-fingers-breaded]                                                    | 0     | 228 [salad-dressing]                                                   | 0     | 229 [dried-meat]                                                | 0     |
| 230 [chicken-breast]                                                 | 0     | 231 [mixed-salad-chopped-without-sauce]                                        | 0     | 232 [feta]                                                                    | 0     | 233 [praline]                                                          | 0     | 234 [tea-peppermint]                                            | 0     |
| 235 [walnut]                                                         | 0     | 236 [potato-salad-with-mayonnaise-yogurt-dressing]                             | 0     | 237 [kebab-in-pita-bread]                                                     | 0     | 238 [kolhrabi]                                                         | 0     | 239 [alfa-sprouts]                                              | 0     |
| 240 [brussel-sprouts]                                                | 0     | 241 [bacon-cooking]                                                            | 0     | 242 [gruyere]                                                                 | 0     | 243 [bulgur]                                                           | 0     | 244 [grapes]                                                    | 0     |
| 245 [pork-escalope]                                                  | 0     | 246 [chocolate-egg-small]                                                      | 0     | 247 [cappuccino]                                                              | 0     | 248 [zucchini-stewed-without-addition-of-fat-without-addition-of-salt] | 0     | 249 [crisp-bread-wasa]                                          | 0     |
| 250 [bread-black]                                                    | 0     | 251 [perch-fillets-lake]                                                       | 0     | 252 [rosti]                                                                   | 0     | 253 [mango]                                                            | 0     | 254 [sandwich-ham-cheese-and-butter]                            | 0     |
| 255 [muesli]                                                         | 0     | 256 [spinach-steamed-without-addition-of-salt]                                 | 0     | 257 [fish]                                                                    | 0     | 258 [risotto-without-cheese-cooked]                                    | 0     | 259 [milk-chocolate-with-hazelnuts]                             | 0     |
| 260 [cake-oblong]                                                    | 0     | 261 [crisps]                                                                   | 0     | 262 [pork]                                                                    | 0     | 263 [pomegranate]                                                      | 0     | 264 [sweet-corn-canned]                                         | 0     |
| 265 [flakes-oat]                                                     | 0     | 266 [greek-salad]                                                              | 0     | 267 [cantonese-fried-rice]                                                    | 0     | 268 [sesame-seeds]                                                     | 0     | 269 [bouillon]                                                  | 0     |
| 270 [baked-potato]                                                   | 0     | 271 [fennel]                                                                   | 0     | 272 [meat]                                                                    | 0     | 273 [bread-olive]                                                      | 0     | 274 [croutons]                                                  | 0     |
| 275 [philadelphia]                                                   | 0     | 276 [mushroom-average-stewed-without-addition-of-fat-without-addition-of-salt] | 0     | 277 [bell-pepper-red-stewed-without-addition-of-fat-without-addition-of-salt] | 0     | 278 [white-chocolate]                                                  | 0     | 279 [mixed-nuts]                                                | 0     |
| 280 [breadcrumbs-unspiced]                                           | 0     | 281 [fondue]                                                                   | 0     | 282 [sauce-mushroom]                                                          | 0     | 283 [tea-spice]                                                        | 0     | 284 [strawberries]                                              | 0     |
| 285 [tea-rooibos]                                                    | 0     | 286 [pie-plum-baked-with-cake-dough]                                           | 0     | 287 [potatoes-au-gratin-dauphinois-prepared]                                  | 0     | 288 [capers]                                                           | 0     | 289 [vegetables]                                                | 0     |
| 290 [bread-wholemeal-toast]                                          | 0     | 291 [red-radish]                                                               | 0     | 292 [fruit-tart]                                                              | 0     | 293 [beans-kidney]                                                     | 0     | 294 [sauerkraut]                                                | 0     |
| 295 [mustard]                                                        | 0     | 296 [country-fries]                                                            | 0     | 297 [ketchup]                                                                 | 0     | 298 [pasta-linguini-parpadelle-tagliatelle]                            | 0     | 299 [chicken-cut-into-stripes-only-meat]                        | 0     |
| 300 [cookies]                                                        | 0     | 301 [sun-dried-tomatoe]                                                        | 0     | 302 [bread-ticino]                                                            | 0     | 303 [semi-hard-cheese]                                                 | 0     | 304 [margarine]                                                 | 0     |
| 305 [porridge-prepared-with-partially-skimmed-milk]                  | 0     | 306 [soya-drink-soy-milk]                                                      | 0     | 307 [juice-multifruit]                                                        | 0     | 308 [popcorn-salted]                                                   | 0     | 309 [chocolate-filled]                                          | 0     |
| 310 [milk-chocolate]                                                 | 0     | 311 [bread-fruit]                                                              | 0     | 312 [mix-of-dried-fruits-and-nuts]                                            | 0     | 313 [corn]                                                             | 0     | 314 [tete-de-moine]                                             | 0     |
| 315 [dates]                                                          | 0     | 316 [pistachio]                                                                | 0     | 317 [celery]                                                                  | 0     | 318 [white-radish]                                                     | 0     | 319 [oat-milk]                                                  | 0     |
| 320 [cream-cheese]                                                   | 0     | 321 [bread-rye]                                                                | 0     | 322 [witloof-chicory]                                                         | 0     | 323 [apple-crumble]                                                    | 0     | 324 [goat-cheese-soft]                                          | 0     |
| 325 [grapefruit-pomelo]                                              | 0     | 326 [risotto-with-mushrooms-cooked]                                            | 0     | 327 [blue-mould-cheese]                                                       | 0     | 328 [biscuit-with-butter]                                              | 0     | 329 [guacamole]                                                 | 0     |
| 330 [pecan-nut]                                                      | 0     | 331 [tofu]                                                                     | 0     | 332 [cordon-bleu-from-pork-schnitzel-fried]                                   | 0     | 333 [paprika-chips]                                                    | 0     | 334 [quinoa]                                                    | 0     |
| 335 [kefir-drink]                                                    | 0     | 336 [m-m-s]                                                                    | 0     | 337 [salad-rocket]                                                            | 0     | 338 [bread-spelt]                                                      | 0     | 339 [pizza-with-ham-with-mushrooms-baked]                       | 0     |
| 340 [fruit-coulis]                                                   | 0     | 341 [plums]                                                                    | 0     | 342 [beef-minced-only-meat]                                                   | 0     | 343 [pizza-with-ham-baked]                                             | 0     | 344 [pineapple]                                                 | 0     |
| 345 [soup-tomato]                                                    | 0     | 346 [cheddar]                                                                  | 0     | 347 [tea-fruit]                                                               | 0     | 348 [rice-jasmin]                                                      | 0     | 349 [seeds]                                                     | 0     |
| 350 [focaccia]                                                       | 0     | 351 [milk]                                                                     | 0     | 352 [coleslaw-chopped-without-sauce]                                          | 0     | 353 [pastry-flaky]                                                     | 0     | 354 [curd]                                                      | 0     |
| 355 [savoury-puff-pastry-stick]                                      | 0     | 356 [sweet-potato]                                                             | 0     | 357 [chicken-leg]                                                             | 0     | 358 [croissant]                                                        | 0     | 359 [sour-cream]                                                | 0     |
| 360 [ham-turkey]                                                     | 0     | 361 [processed-cheese]                                                         | 0     | 362 [fruit-compotes]                                                          | 0     | 363 [cheesecake]                                                       | 0     | 364 [pasta-tortelloni-stuffing]                                 | 0     |
| 365 [sauce-cocktail]                                                 | 0     | 366 [croissant-with-chocolate-filling]                                         | 0     | 367 [pumpkin-seeds]                                                           | 0     | 368 [artichoke]                                                        | 0     | 369 [champagne]                                                 | 0     |
| 370 [grissini]                                                       | 0     | 371 [sweets-candies]                                                           | 0     | 372 [brie]                                                                    | 0     | 373 [wienerli-swiss-sausage]                                           | 0     | 374 [syrup-diluted-ready-to-drink]                              | 0     |
| 375 [apple-pie]                                                      | 0     | 376 [white-bread-with-butter-eggs-and-milk]                                    | 0     | 377 [savoury-puff-pastry]                                                     | 0     | 378 [anchovies]                                                        | 0     | 379 [tuna-in-oil-drained]                                       | 0     |
| 380 [lemon-pie]                                                      | 0     | 381 [meat-terrine-pate]                                                        | 0     | 382 [coriander]                                                               | 0     | 383 [falafel-balls]                                                    | 0     | 384 [berries]                                                   | 0     |
| 385 [latte-macchiato-with-caffeine]                                  | 0     | 386 [faux-mage-cashew-vegan-chers]                                             | 0     | 387 [beans-white]                                                             | 0     | 388 [sugar-melon]                                                      | 0     | 389 [mixed-seeds]                                               | 0     |
| 390 [hamburger]                                                      | 0     | 391 [hamburger-bun]                                                            | 0     | 392 [oil-vinegar-salad-dressing]                                              | 0     | 393 [soya-yaourt-yahourt-yogourt-ou-yoghourt]                          | 0     | 394 [chocolate-milk-chocolate-drink]                            | 0     |
| 395 [celeriac]                                                       | 0     | 396 [chocolate-mousse]                                                         | 0     | 397 [cenovis-yeast-spread]                                                    | 0     | 398 [thickened-cream-35]                                               | 0     | 399 [meringue]                                                  | 0     |
| 400 [lamb-chop]                                                      | 0     | 401 [shrimp-prawn-large]                                                       | 0     | 402 [beef]                                                                    | 0     | 403 [lemon]                                                            | 0     | 404 [croque-monsieur]                                           | 0     |
| 405 [chives]                                                         | 0     | 406 [chocolate-cookies]                                                        | 0     | 407 [birchermuesli-prepared-no-sugar-added]                                   | 0     | 408 [fish-crunchies-battered]                                          | 0     | 409 [muffin]                                                    | 0     |
| 410 [savoy-cabbage-steamed-without-addition-of-salt]                 | 0     | 411 [pine-nuts]                                                                | 0     | 412 [chorizo]                                                                 | 0     | 413 [chia-grains]                                                      | 0     | 414 [frying-sausage]                                            | 0     |
| 415 [french-pizza-from-alsace-baked]                                 | 0     | 416 [chocolate]                                                                | 0     | 417 [cooked-sausage]                                                          | 0     | 418 [grits-polenta-maize-flour]                                        | 0     | 419 [gummi-bears-fruit-jellies-jelly-babies-with-fruit-essence] | 0     |
| 420 [wine-rose]                                                      | 0     | 421 [coca-cola]                                                                | 0     | 422 [raspberries]                                                             | 0     | 423 [roll-with-pieces-of-chocolate]                                    | 0     | 424 [goat-average-raw]                                          | 0     |
| 425 [lemon-cake]                                                     | 0     | 426 [coconut-milk]                                                             | 0     | 427 [rice-wild]                                                               | 0     | 428 [gluten-free-bread]                                                | 0     | 429 [pearl-onions]                                              | 0     |
| 430 [buckwheat-pancake]                                              | 0     | 431 [bread-5-grain]                                                            | 0     | 432 [light-beer]                                                              | 0     | 433 [sugar-glazing]                                                    | 0     | 434 [tzatziki]                                                  | 0     |
| 435 [butter-herb]                                                    | 0     | 436 [ham-croissant]                                                            | 0     | 437 [corn-crisps]                                                             | 0     | 438 [lentils-green-du-puy-du-berry]                                    | 0     | 439 [cocktail]                                                  | 0     |
| 440 [rice-whole-grain]                                               | 0     | 441 [veal-sausage]                                                             | 0     | 442 [cervelat]                                                                | 0     | 443 [sorbet]                                                           | 0     | 444 [aperitif-with-alcohol-aperol-spritz]                       | 0     |
| 445 [dips]                                                           | 0     | 446 [corn-flakes]                                                              | 0     | 447 [peas]                                                                    | 0     | 448 [tiramisu]                                                         | 0     | 449 [apricots]                                                  | 0     |
| 450 [cake-marble]                                                    | 0     | 451 [lamb]                                                                     | 0     | 452 [lasagne-meat-prepared]                                                   | 0     | 453 [coca-cola-zero]                                                   | 0     | 454 [cake-salted]                                               | 0     |
| 455 [dough-puff-pastry-shortcrust-bread-pizza-dough]                 | 0     | 456 [rice-waffels]                                                             | 0     | 457 [sekt]                                                                    | 0     | 458 [brioche]                                                          | 0     | 459 [vegetable-au-gratin-baked]                                 | 0     |
| 460 [mango-dried]                                                    | 0     | 461 [processed-meat-charcuterie]                                               | 0     | 462 [mousse]                                                                  | 0     | 463 [sauce-sweet-sour]                                                 | 0     | 464 [basil]                                                     | 0     |
| 465 [butter-spread-puree-almond]                                     | 0     | 466 [pie-apricot-baked-with-cake-dough]                                        | 0     | 467 [rusk-wholemeal]                                                          | 0     | 468 [beef-roast]                                                       | 0     | 469 [vanille-cream-cooked-custard-creme-dessert]                | 0     |
| 470 [pasta-in-conch-form]                                            | 0     | 471 [nuts]                                                                     | 0     | 472 [sauce-carbonara]                                                         | 0     | 473 [fig-dried]                                                        | 0     | 474 [pasta-in-butterfly-form-farfalle]                          | 0     |
| 475 [minced-meat]                                                    | 0     | 476 [carrot-steamed-without-addition-of-salt]                                  | 0     | 477 [ebly]                                                                    | 0     | 478 [damson-plum]                                                      | 0     | 479 [shoots]                                                    | 0     |
| 480 [bouquet-garni]                                                  | 0     | 481 [coconut]                                                                  | 0     | 482 [banana-cake]                                                             | 0     | 483 [waffle]                                                           | 0     | 484 [apricot-dried]                                             | 0     |
| 485 [sauce-curry]                                                    | 0     | 486 [watermelon-fresh]                                                         | 0     | 487 [sauce-sweet-salted-asian]                                                | 0     | 488 [pork-roast]                                                       | 0     | 489 [blackberry]                                                | 0     |
| 490 [smoked-cooked-sausage-of-pork-and-beef-meat-sausag]             | 0     | 491 [bean-seeds]                                                               | 0     | 492 [italian-salad-dressing]                                                  | 0     | 493 [white-asparagus]                                                  | 0     | 494 [pie-rhubarb-baked-with-cake-dough]                         | 0     |
|                                                                      |       |                                                                                |       |                                                                               |       |                                                                        |       |                                                                 |       |
| 495 [tomato-stewed-without-addition-of-fat-without-addition-of-salt] | 0     | 496 [cherries]                                                                 | 0     | 497 [nectarine]                                                               | 0     | -1 background                                                          | 3000  |                                                                 |       |
+----------------------------------------------------------------------+-------+--------------------------------------------------------------------------------+-------+-------------------------------------------------------------------------------+-------+------------------------------------------------------------------------+-------+-----------------------------------------------------------------+-------+
load checkpoint from local path: /content/latest.pth
[>>] 3000/3000, 1.3 task/s, elapsed: 2270s, ETA:     0s
AICrowd register complete

Now that the prediction file is generated for public test set, To make quick submission:

  • Use AIcrowd CLL aicrowd submit command to do a quick submission. </br>

Alternatively:

  • download the predictions_mmdetection.json file by running below cell
  • visit the create submission page
  • Upload the predictions_mmdetection.json file
  • Voila!! You just made your first submission!
In [ ]:
#use aicrowd CLI to make quick submission
!aicrowd submission create -c food-recognition-benchmark-2022 -f $output_filepath

Active submission 🤩

Step 0 : Fork the baseline to make your own changes to it. Go to settings and make the repo private.

Step 1 : For first time setup, Setting up SSH to login to Gitlab.

  1. Run the next cell to check if you already have SSH keys in your drive, if yes, skip this step.
  2. Run ssh-keygen -t ecdsa -b 521
  3. Run cat ~./ssh/id_ecdsa.pub and copy the output
  4. Go to Gitlab SSH Keys and then paste the output inside the key and use whaever title you like.

Step 2: Clone your forked Repo & Add Models & Push Changes

  1. Run git clone git@gitlab.aicrowd.com:[Your Username]/mmdetection-starter-food-2022.git
  2. Put your model inside the models directioary and then run git-lfs track "*.pth"
  3. Run git add . then git commit -m " adding model"
  4. Run git push origin master

Step 3. Create Submission

  1. Go to the repo and then tags and then New Tag.
  2. In the tag name,you can use submission_v1, ( Everytime you make a new submission, just increase the no. like - submission_v2, submission_v3 )
  3. A new issue will be created with showing the process. Enjoy!

If you do not have SSH Keys, Check this Page

Add your SSH Keys to your GitLab account by following the instructions here

In [ ]:
%%bash
SSH_PRIV_KEY=/content/drive/MyDrive/id_ecdsa
SSH_PUB_KEY=/content/drive/MyDrive/id_ecdsa.pub
if [ -f "$SSH_PRIV_KEY" ]; then
    echo "SSH Key found! ✅\n"
    mkdir -p /root/.ssh
    cp /content/drive/MyDrive/id_ecdsa ~/.ssh/id_ecdsa
    cp /content/drive/MyDrive/id_ecdsa.pub ~/.ssh/id_ecdsa.pub
    echo "SSH key successfully copied to local!"
else
    echo "SSH Key does not exist."
    ssh-keygen -t ecdsa -b521 -f ~/.ssh/id_ecdsa
    cat ~/.ssh/id_ecdsa.pub
    echo "❗️Please open https://gitlab.aicrowd.com/profile/keys and copy-paste the above text in the **key** textbox."
    cp  ~/.ssh/id_ecdsa /content/drive/MyDrive/id_ecdsa
    cp  ~/.ssh/id_ecdsa.pub /content/drive/MyDrive/id_ecdsa.pub
    echo "SSH key successfully created and copied to drive!"
fi
SSH Key found! ✅\n
SSH key successfully copied to local!
In [ ]:
import IPython

html = "<b>Copy paste below SSH key in your GitLab account here (one time):</b><br/>"
html += '<a href="https://gitlab.aicrowd.com/-/profile/keys" target="_blank">https://gitlab.aicrowd.com/-/profile/keys</a><br><br>'

public_key = open("/content/drive/MyDrive/id_ecdsa.pub").read()
html += '<br/><textarea>'+public_key+'</textarea><button onclick="navigator.clipboard.writeText(\''+public_key.strip()+'\');this.innerHTML=\'Copied ✅\'">Click to copy</button>'
IPython.display.HTML(html)
Out[ ]:
Copy paste below SSH key in your GitLab account here (one time):
https://gitlab.aicrowd.com/-/profile/keys


Clone the gitlab starter repo and add submission files

In [ ]:
# Set your AIcrowd username for action submission.
# This username will store repository and used for submitter's username, etc
username = "jerome_patel"
!echo -n {username} > author.txt
In [ ]:
%%bash
username=$(cat author.txt)
echo "Username $username"

git config --global user.name "$username"
git config --global user.email "$username@noreply.gitlab.aicrowd.com"

touch ${HOME}/.ssh/known_hosts
ssh-keyscan -H gitlab.aicrowd.com >> ${HOME}/.ssh/known_hosts 2> /dev/null


apt install -qq -y jq git-lfs &> /dev/null

git lfs install
cd /content/

echo "Checking if repository already exist, otherwise create one"
export SUBMISSION_REPO="git@gitlab.aicrowd.com:$username/mmdetection-starter-food-2022.git"
echo "cloning the $SUBMISSION_REPO"
git clone $SUBMISSION_REPO mmdetection-starter-food-2022
ALREADYEXIST=$?

if [ $ALREADYEXIST -ne 0 ]; then
  echo "Project didn't exist, forking from upstream"
  git clone https://github.com/AIcrowd/food-recognition-benchmark-starter-kit.git mmdetection-starter-food-2022
fi

cd /content/mmdetection-starter-food-2022
git remote remove origin
git remote add origin "$SUBMISSION_REPO"
Username jerome_patel
Git LFS initialized.
Checking if repository already exist, otherwise create one
cloning the git@gitlab.aicrowd.com:jerome_patel/mmdetection-starter-food-2022.git
Error: Failed to call git rev-parse --git-dir --show-toplevel: "fatal: not a git repository (or any of the parent directories): .git\n"
Cloning into 'mmdetection-starter-food-2022'...
Warning: Permanently added the ECDSA host key for IP address '54.93.129.179' to the list of known hosts.

To make active submission:

  • Required Files are aicrowd.json, apt.txt, requirements.txt, predict.py (already configured for mmdetection)
  • [IMP] Copy mmdetection trained model, corresponding config file to repo
  • for inference place these files : predict_mmdetection.py mmdet_inference.py (already present in repo)
  • Modify requirements.txt and predict.py for mmdetection
  • [IMP] Modify aicrowd.json for your submission

Note: You only need to place your trained model and modify aicrowd.json to create your first easy submission.

In [ ]:
#@title Modify mmdet_inference.py (modify and run only if you want to change the inference)
%%writefile /content/mmdetection-starter-food-2022/utils/mmdet_inference.py

import mmcv
import numpy as np
import torch
from mmcv.ops import RoIPool
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint

from mmdet.core import get_classes
from mmdet.datasets import replace_ImageToTensor
from mmdet.datasets.pipelines import Compose
from mmdet.models import build_detector
# import time


def inference(model, imgs):

    # start = time.process_time()
    imgs = [imgs]
    cfg = model.cfg
    device = 'cuda:0'
    if isinstance(imgs[0], np.ndarray):
        cfg = cfg.copy()
        # set loading pipeline type
        cfg.data.test.pipeline[0].type = 'LoadImageFromWebcam'

    cfg.data.test.pipeline = replace_ImageToTensor(cfg.data.test.pipeline)
    test_pipeline = Compose(cfg.data.test.pipeline)

    datas = []
    data = dict(img_info=dict(filename=imgs[0]), img_prefix=None)
    # build the data pipeline
    data = test_pipeline(data)
    datas.append(data)

    data = collate(datas, samples_per_gpu=len(imgs))
    # just get the actual data from DataContainer
    data['img_metas'] = [img_metas.data[0] for img_metas in data['img_metas']]
    data['img'] = [img.data[0] for img in data['img']]
    # scatter to specified GPU
    data = scatter(data, [device])[0]
    
    # forward the model
    with torch.no_grad():
        results = model(return_loss=False, rescale=True, **data)
    # your code here    
    # print(time.process_time() - start)
    return results[0]
Overwriting /content/mmdetection-starter-food-2022/utils/mmdet_inference.py
In [ ]:
#@title Modify predict_mmdetection.py (modify & run this only if you want to change inference code part)
%%writefile /content/mmdetection-starter-food-2022/predict_mmdetection.py

import os
import json
import glob
from PIL import Image
import importlib
import numpy as np
import cv2
import torch
import traceback
import pickle
import shutil
import glob
import tempfile
import time
import mmcv
import torch.distributed as dist
from mmcv.image import tensor2imgs
from mmdet.core import encode_mask_results
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
                         wrap_fp16_model)
from mmdet.apis import init_detector, inference_detector

from mmdet.apis import multi_gpu_test
from mmdet.datasets import (build_dataloader, build_dataset,
                            replace_ImageToTensor)
from mmdet.models import build_detector
import pycocotools.mask as mask_util

from utils.mmdet_inference import inference
from evaluator.food_challenge import FoodChallengePredictor


"""
Expected ENVIRONMENT Variables
* AICROWD_TEST_IMAGES_PATH : abs path to  folder containing all the test images
* AICROWD_PREDICTIONS_OUTPUT_PATH : path where you are supposed to write the output predictions.json
"""

class MMDetectionPredictor(FoodChallengePredictor):

    """
    PARTICIPANT_TODO:
    You can do any preprocessing required for your codebase here like loading up models into memory, etc.
    """
    def prediction_setup(self):
        # self.PADDING = 50
        # self.SEGMENTATION_LENGTH = 10
        # self.MAX_NUMBER_OF_ANNOTATIONS = 10

        #set the config parameters, including the architecture which was previously used
        self.cfg_name, self.checkpoint_name = self.get_mmdetection_config()
        self.cfg = Config.fromfile(self.cfg_name)
        # self.test_img_path = os.getenv("AICROWD_TEST_IMAGES_PATH", os.getcwd() + "/data/images/")
        self.test_predictions_file = self.create_test_predictions(self.test_data_path)

        if self.cfg.get('cudnn_benchmark', False):
            torch.backends.cudnn.benchmark = True
        self.cfg.data.samples_per_gpu = 1
        self.cfg.data.workers_per_gpu = 2
        self.cfg.model.pretrained = None
        self.cfg.data.test.test_mode = True
        self.cfg.data.test.ann_file = self.test_predictions_file.name
        self.cfg.data.test.img_prefix = self.test_data_path

        self.model = init_detector(self.cfg_name,self.checkpoint_name,device='cuda:0')

        fp16_cfg = self.cfg.get('fp16', None)
        if fp16_cfg is not None:
            wrap_fp16_model(self.model)

         # Load annotations
        with open(self.test_predictions_file.name) as f:
            self.annotations = json.loads(f.read())
        self.cat_ids = [category["id"] for category in self.annotations["categories"]]

        self.model.CLASSES = [category['name'] for category in self.annotations['categories']]

    """
    PARTICIPANT_TODO:
    During the evaluation all image file path will be provided one by one.
    NOTE: In case you want to load your model, please do so in `predict_setup` function.
    """
    def prediction(self, image_path):
        print("Generating for", image_path)
        # read the image
        result = inference(self.model, image_path)
        #RLE Encode the masks
        result = (result[0], encode_mask_results(result[1]))
        result = self.segm2jsonformat(result,image_path)
        return result

    def xyxy2xywh(self,bbox):
        _bbox = bbox.tolist()
        return [
            _bbox[0],
            _bbox[1],
            _bbox[2] - _bbox[0] + 1,
            _bbox[3] - _bbox[1] + 1,
        ]

    def segm2jsonformat(self, result,image_path):
        segm_json_results = []
        img_id = int(os.path.basename(image_path).split(".")[0])
        det, seg = result
        # print("image:",img_id)
        for label in range(len(det)):
                bboxes = det[label]
                #print(type(bboxes))
                segms = seg[label]
                mask_score = [bbox[4] for bbox in bboxes]
                for i in range(len(bboxes)):
                        data = dict()
                        data['image_id'] = img_id
                        data['bbox'] = self.xyxy2xywh(bboxes[i])
                        data['score'] = float(mask_score[i])
                        data['category_id'] = self.cat_ids[label]
                        if isinstance(segms[i]['counts'], bytes):
                                segms[i]['counts'] = segms[i]['counts'].decode()
                        data['segmentation'] = segms[i]
                        segm_json_results.append(data)
        return segm_json_results


    def create_test_predictions(self,images_path):
        test_predictions_file = tempfile.NamedTemporaryFile(mode="w+", suffix=".json")
        annotations = {'categories': [], 'info': {}, 'images': []}
        for item in glob.glob(images_path+'/*.jpg'):
            image_dict = dict()
            img = mmcv.imread(item)
            height,width,__ = img.shape
            id = int(os.path.basename(item).split('.')[0])
            image_dict['image_id'] = id
            image_dict['file_name'] = os.path.basename(item)
            image_dict['width'] = width
            image_dict['height'] = height
            annotations['images'].append(image_dict)
        annotations['categories'] = json.loads(open("classes.json").read())
        json.dump(annotations, open(test_predictions_file.name, 'w'))

        return test_predictions_file

    def get_mmdetection_config(self):
        with open('aicrowd.json') as f:
            content = json.load(f)
            config_fname = content['model_config_file']
            checkpoint_fname = content['model_path']
        # config = Config.fromfile(config_fname)
        return (config_fname, checkpoint_fname)


if __name__ == "__main__":
    submission = MMDetectionPredictor()
    submission.run()
    print("Successfully generated predictions!")
Overwriting /content/mmdetection-starter-food-2022/predict_mmdetection.py
In [ ]:
MODEL_ARCH = "htc_without_semantic_r50_fpn_1x_coco.py"
aicrowd_json = {
  "challenge_id" : "food-recognition-benchmark-2022",
  "authors" : ["jerome_patel"],
  "description" : "Food Recognition Benchmark 2022 Submission mmdetection",
  "license" : "MIT",
  "gpu": True,
  "debug": False,
  "model_path": "models/latest.pth",
  "model_type": "mmdetection",
  "model_config_file": "models/" + MODEL_ARCH
}
import json
with open('/content/mmdetection-starter-food-2022/aicrowd.json', 'w') as fp:
  fp.write(json.dumps(aicrowd_json, indent=4))

Copy required files (trained model, config, classes.json) to mmdetection repo

In [ ]:
!mkdir -p /content/mmdetection-starter-food-2022/models
!cp /content/classes.json /content/mmdetection-starter-food-2022/utils/classes.json
!cp /content/latest.pth /content/mmdetection-starter-food-2022/models/latest.pth
!cp $MODEL_ARCH /content/mmdetection-starter-food-2022/models/$MODEL_ARCH

Finally push the repo for active submission

In [ ]:
%%bash

## Set your unique tag for this submission (no spaces), example:
# export MSG="v1"
# export MSG="v2" ...
# or something more informative...
export MSG="mmdetection_submission_v0_1"

username=$(cat author.txt)
echo "Username $username"


cd /content/mmdetection-starter-food-2022
git lfs track "*.pth"
git add .gitattributes
git add --all
git commit -m "$MSG" || true

find . -type f -size +5M -exec git lfs migrate import --include={} &> /dev/null \;

git tag -am "submission_$MSG" "submission_$MSG"
git config lfs.https://gitlab.aicrowd.com/$username/mmdetection-starter-food-2022.git/info/lfs.locksverify false

git remote remove origin
git remote add origin git@gitlab.aicrowd.com:$username/mmdetection-starter-food-2022.git

git lfs push origin master
git push origin master
git push origin "submission_$MSG"

echo "Track your submission status here: https://gitlab.aicrowd.com/$username/mmdetection-starter-food-2022/issues"
Username jerome_patel
"*.pth" already supported
On branch master
nothing to commit, working tree clean
Git LFS: (0 of 0 files, 3 skipped) 0 B / 0 B, 1.26 GB skipped                  Track your submission status here: https://gitlab.aicrowd.com/jerome_patel/mmdetection-starter-food-2022/issues
fatal: tag 'submission_mmdetection_submission_v0_1' already exists
Everything up-to-date
Everything up-to-date

Local Evaluation for Active Submission Repo

In [ ]:
%%bash
cd /content/mmdetection-starter-food-2022

export TEST_DATASET_PATH=../data/test/images
export RESULTS_DATASET_PATH=../data
./run.sh

Comments

You must login before you can post a comment.

Execute