harimkang / food-image-classifier

Food classifier trained the inception_v3 model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

food-image-classifier

Hits License Stars

fc_logo

The repository is a classifier project that allows you to easily categorize food photos using the CLI. Currently, a total of 101 types of food can be classified, and the model can be trained using a new dataset according to code commands.

  • [O] Food Image Classification
  • [O] Learning a new model
  • [O] Assessing existing and new models
  • [Need-to-check] Transfer learning for the current model

We have organized data sets and codes with the goal of matching the type of food, and we have achieved the goal by learning about them. These simple projects can easily be applied to new research and ideas in the future.

Table of Contents

Environment

Dependencies

food-image-classifier was developed using the following library version:

  • [Python3] - 3.8.3
  • [Tensorflow] - 2.3.0
  • [CUDA] - 10.1
  • [Cudnn] - 7.6.5

and GPU enable Environment (Slow, but also in a CPU environment.)

Installation

  1. Clone food-image-classifier Repository
$ git clone https://github.com/harimkang/food-image-classifier.git
$ cd food-image-classifier
  1. Configure virtual environment
$ python -m venv .venv
$ (windows) .venv\Scripts\activate
$ (Linux) source .venv/bin/activate
  1. Install the dependencies.
$ pip install -r requirements.txt

Usage

  • CLI Model
$ python food_classifier.py [-m/--mode] [-d/--data_set] [-t/--test_data] \
                            [-b/ --batch_size] [-e/--epoch]

Examples

  • prediction (If you have trained models/checkpoints)

    1. Put the picture of the food you want to predict in the examples folder.
    2. Perform the command below.
    $ python food_classifire -m pred -t A.jpg B.jpg
    1. check result - If you predict the picture of bibimbap found on Google, it's as below. prediction_bibimbap
  • training new model

    1. Perform the command below.
    $ python food_classifire -m train
  • evaluate model (If you have trained models/checkpoints)

    1. Perform the command below.
    $ python food_classifire -m eval
  • test model (evaluate + pred some examples)

    1. Perform the command below.
    $ python food_classifire -m test
    Dataset already exists
    --------------------TEST Mode--------------------
    Classes : 101
    Model loaded...:  food_classifier_checkpoint_20201210.hdf5
    Found 25250 images belonging to 101 classes.
    Evaluation data: food-101/test/
    accuracy: 83.75%
    [Model Prediction] applepie: apple_pie
    [Model Prediction] pizza: pizza
    [Model Prediction] samosa: samosa

Dataset

  • We found that the data set was opened with a data set called food-101 in the kaggle.

  • There are 101 food classes in total, and there are 1000 each.

  • The dataset is divided into trains (75750 imgs, 75%)/test (25250 imgs, 25%) in metadata.

  • We only used the train (75750 imgs) set for training. Instead, the train set was divided into train (60600 imgs, 80%)/validation (15150 imgs, 20%) sets for model training. The remaining test sets (25250 imgs) were used only to evaluate the trained model.

    Total Train Validation Test
    101000 imgs 60600 imgs 15150 imgs 25250 imgs
    100 % 60 % 15 % 25 %

Model

The project was written based on the inception_v3 model provided by Keras.application and was trained.

Model Reference
Inception v3 inception_v3

The model we have trained is as follows.

pretrained_model

Once you download and extract the model data above, you can place the models folder on root basis. The above models are 10 epochs trained based on batch_size=16.

Accuracy Loss Val_Accuracy Val_Loss
69.4 % 1.612 72.5 % 1.467

You can improve the performance of the model through transfer learning. Alternatively, you can train with more appropriate hyperparameters or train longer to get a good performance model.

TEST

We wrote the test code together to check the normal code operation. It is written as unittest of Python and needs coverage program to check coverage.

$ coverage run -m unittest discover tests
$ coverage report -i
Name                  Stmts   Miss  Cover
-----------------------------------------
model.py                122     46    62%
set_data_env.py          63     29    54%
tests\test_model.py      12      0   100%
tests\test_train.py      41      0   100%
-----------------------------------------
TOTAL                   238     75    68%

image

TO-DO

  • New model plug-in
  • New Dataset plug-in
  • Increasing test code coverage

Contributing

Feel free to open an Issue, if you think something needs to be changed. You are welcome to participate in development, instructions are available in our contribution guide (TBD).

Or, if you have any questions, you can ask them via email.

License


Copyright © 2020 Harim Kang.

MIT

About

Food classifier trained the inception_v3 model

License:MIT License


Languages

Language:Python 100.0%