<commit_before># Module google/aiy/vision/classifier/food_V1/1

Food classification model.

<!-- asset-path: @visionkit/aiy/classifier/seefood_V1/2 -->
<!-- task: image-classification -->
<!-- fine-tunable: false -->
<!-- format: hub -->
<!-- language: en -->
<!-- network-architecture: mobilenet-v1 -->
<!-- interactive-visualizer: vision -->

## Overview

This model is trained to recognize 2023 food dishes from images. It is based on
[MobileNet V1](https://arxiv.org/abs/1704.04861).

### Input

This model takes images as input.

*   Inputs are expected to be 3-channel RGB color images of size 224 x 224,
    scaled to [0, 1].

### Output

This model outputs to `image_classifier`.

*   `image_classifier`: A probability vector of dimension 2024, corresponding to
    a `background` class and one of 2023 food dishes in the
    [labelmap](https://www.gstatic.com/aihub/tfhub/labelmaps/aiy_food_V1_labelmap.csv).

## Example use

```python

# TF1 version
import tensorflow.compat.v1 as tf
import tensorflow_hub as hub

m = hub.Module('https://tfhub.dev/google/aiy/vision/classifier/food_V1/1')
...

# TF2 version
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub

m = hub.KerasLayer('https://tfhub.dev/google/aiy/vision/classifier/food_V1/1')
...
```

## Model architecture

For details of the model architecture, see<commit_msg>Add snippet for image classification<commit_after># Module google/aiy/vision/classifier/food_V1/1

Food classification model.

<!-- asset-path: @visionkit/aiy/classifier/seefood_V1/2 -->
<!-- task: image-classification -->
<!-- fine-tunable: false -->
<!-- format: hub -->
<!-- language: en -->
<!-- network-architecture: mobilenet-v1 -->
<!-- interactive-visualizer: vision -->

## Overview

This model is trained to recognize 2023 food dishes from images. It is based on
[MobileNet V1](https://arxiv.org/abs/1704.04861).

### Input

This model takes images as input.

*   Inputs are expected to be 3-channel RGB color images of size 224 x 224,
    scaled to [0, 1].

### Output

This model outputs to `image_classifier`.

*   `image_classifier`: A probability vector of dimension 2024, corresponding to
    a `background` class and one of 2023 food dishes in the
    [labelmap](https://www.gstatic.com/aihub/tfhub/labelmaps/aiy_food_V1_labelmap.csv).

## Example use

Depending on the used TensorFlow version, the model can be loaded like so:

```python

# TF1 version
import tensorflow.compat.v1 as tf
import tensorflow_hub as hub

m = hub.Module('https://tfhub.dev/google/aiy/vision/classifier/food_V1/1')
...

# TF2 version
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub

m = hub.KerasLayer('https://tfhub.dev/google/aiy/vision/classifier/food_V1/1')
...
```

Using the loaded model, food can be classified like so:

```python
import numpy as np
import pandas as pd
import cv2
from skimage import io

cake_url = "https://storage.googleapis.com/tfhub-visualizers/google/aiy/vision/classifier/food_V1/1/image_1.jpg"
labelmap_url = "https://www.gstatic.com/aihub/tfhub/labelmaps/aiy_food_V1_labelmap.csv"
input_shape = (224, 224)

image = np.asarray(io.imread(cake_url), dtype="float")
image = cv2.resize(image, dsize=input_shape, interpolation=cv2.INTER_CUBIC)
# Scale values to [0, 1].
image = image / image.max()
# The model expects an input of (?, 224, 224, 3).
images = np.expand_dims(image, 0)
# This assumes you're using TF2.
output = m(images)
predicted_index = output.numpy().argmax()
classes = list(pd.read_csv(labelmap_url)["name"])
print("Prediction: ", classes[predicted_index])
```

## Model architecture

For details of the model architecture, see
{'fraction_non_alphanumeric': 0.1353735869864902, 'fraction_numerical': 0.03143093465674111, 'mean_word_length': 4.081232492997199, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 10, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507486', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1188, 'n_words': 340}