Machine learning project based on Keras and Tensorflow to classify objects on pictures. There are three deep neural network architectures implemented:
- CNN implemented from scratch named simple
- CNN implemented with transfer learning and fine-tuning from VGG16 net with convolutional layers weight initialized from imagenet named vgg16
- CNN implemented with transfer learning and fine-tuning from ResNet50 net with convolutional layers weight initialized from imagenet named resnet
-
Python >= 3.6
-
pip >= 20.1.1
Run install.sh
script which creates Python virtual environment and installs packages.
-
Create Python local virtual environment (12. Virtual Environments and Packages)
-
Activate Python local virtual environment
-
Run
pip install -r ./requirements.txt
to install packages -
Deactivate Python local virtual environment
Download pretrained models from Google Drive and unpack models to pretrained_models folder or use download_models.sh
script.
Use download_data.sh
script to download and unpack image dataset. Use generate_data.sh
script to run data augmentation in another directory.
Use Runme.sh
script with pretrained models. Go to directory with subdirectories named "car" and "other" and run Runme.sh
script. In the result program will show the list of photos classified as car and classification accuracy.
Example directory structure:
.
├── download_data.sh
├── .........
├── resources
│ └── pa3_images
│ └── test_samples
│ ├── car
│ │ ├── 0000.jpg
│ │ ├── 0001.jpg
│ │ ├── 0002.jpg
│ │ ├── 0003.jpg
│ │ ├── 0004.jpg
│ │ ├── 0005.jpg
│ │ └── 0006.jpg
│ └── other
│ ├── 1000.jpg
│ ├── 1001.jpg
│ ├── 1002.jpg
│ ├── 1003.jpg
│ └── 1004.jpg
├── Runme.py
├── Runme.sh
├── .........
└── train.sh
Go to directory resources/pa3_images/test_samples/
and call:
../../../Runme.sh
By default Runme.sh
uses resnet model. Call Runme.sh
with model name to use another one, e.g.:
Runme.sh resnet
Runme.sh vgg16
Runme.sh simple
train_save_best.py
script executes given number of epochs saving model with the best validation accuracy value.
Use train_local_save_best.sh
script to train all networks with the best parameters locally.
Use ML.ipynb
ipython script in Google Colab if local computation resources are not available.
In your Google Drive create folder named ML_car and place there ML.ipynb
, then open script with Google Colaboratory tool. ML.ipynb
calls train_google_save_best.sh
script.
Select GPU Hardware accelerator in Runtime>Change runtime type>.
Run script with Runtime>Run all.
To train one of implemented model use ./train.py
script. An example is in train.sh
script. To print all available command line arguments run python ./train.py --help
.
To test one of implemented model use ./test.py
script. An example is in test.sh
script. To print all available command line arguments run python ./test.py --help
.
In order to install packages activate local Python virtual environment and run command: pip install <package_name>
To save installed packages run command: pip freeze > requirements.txt
-
Max line width: 100
-
Variable, function, file naming convention: snake_case
-
Project introduction: http://www.cse.chalmers.se/%7Erichajo/dit866/PA3.html
-
Image dataset: http://www.cse.chalmers.se/%7Erichajo/dit866/data/pa3_images.zip