Skip to content

dimkastan/Torch-Train-on-food-dataset

Repository files navigation

Using Torch to train a Deep CNN- an example case on a food dataset

Torch demo for training squeezenet from scratch to recognize foods.

Note: why I am using food-101

  • Is a large enough dataset, however better manageable as compared to ImageNet
  • Is better than MNIST
  • Is bettern than cats-vs-dogs
  • It is worth studying the efficiency wrt the color space
  • It is very interesting to study week localization and transfer learning.

Setup


Before begin you have to setup your environment. First of all you must have allready installed, Torch and the image, optim, nn, cudnn and cunn packages. This can be done easilly via luarocks install
After installing all requirements follow these steps:
Get this repo:
git clone https://github.com/dimkastan/Torch-Train-on-food-dataset

Download and extract data
All steps are included into setup.sh . Call it using:
./setup.sh

If you are under Windows 10 OS you can use Windows 10 Ubuntu bash.
Now everything ready to start training.
Currently, only "Train from scratch" is supported. In a few weeks I will add two very basic "Transfer Learning" scenarios.

Train from scratch


After extracting the data you can easily start training your model by calling the train.lua as follows:
th main.lua

The program will draw the Classification accuracy as well as the loss per epoch.
According to your GPU's memory you can modify the batch size. Also I would advise you to work on a SSD


Here are the accuracy plots for both train and test set (single crop)

Train Set


Test Set

Upcoming features


In a few weeks I plan to add one or more of the following features:
- Perform data augmentation
- Operate in different color spaces
- Incorporate food localization
- Incorporate semantic image segmentation

Test a pretrained model


For convinience here, I also provide a pretrained model (squeezenet_v1) as well as sample code demonstrating how to load and classify images.
In order to test the model run the following:
th demo_food.lua

This will crop one rectangle from apple_pie.jpg and evaluate it. Run multiple times to see how the output is affected by random crops.


About

Training a Deep neural network with torch- Application on food recognition

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published