Shallow CNN for Fashion MNIST using Keras and SageMaker
This project contains code and notebooks for training a custom CNN on the Fashion MNIST dataset either locally or in the cloud using Amazon SageMaker.
The CNN is written with Keras and Tensorflow backend. Generic and Fashion MNIST specific-versions are implemented as classes in cnn.py
.
data/
- Fashion MNIST data filesmodels/keras_checkpoints
- Keras checkpoints
To train the network on your local machine:
python train_script_local.py
To train in the cloud using Amazon SageMaker use train_script_sagemaker.py
and script mode.
This can be done locally or it can be done in a Sagemaker notebook instance 1.
There are two Jupyter notebooks:
explore_data_and_model.ipynb
-- An introductio to the dataset and default modeltrain_tune_test.ipynb
- training, tuning and testing the model using Sagemaker resources.
If you're running the scripts or notebooks locally, it's recommended to create a virtual environment directly from the included environment files
Using virtualenv
python3 -m venv fashion
source env/bin/activate
pip install -r requirements.txt
Using conda
conda env create -f environment.yml
If you're running anything in a SageMaker notebook instance, you can use the built-in conda_python3
kernel, provided you install
keras
2
Footnotes
-
The easiest way to get up and running in a SageMaker notebook instance is probably to fork this repo and link it to the notebook instance. ↩
-
At the time of writing, this wouldn't work using a Lifecycle configuration due to a timeout, but you can install directly from a Python notebook within the instance using
! conda install --name conda_python3 keras
↩