Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LinguoLi authored Oct 23, 2018
1 parent 58d34e5 commit 27ca18b
Show file tree
Hide file tree
Showing 5 changed files with 654 additions and 1 deletion.
14 changes: 14 additions & 0 deletions EE369.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# For EE369 students from SJTU

## 作业要求:
1. star并fork当前的repository,完成以下notebook(至少完成两个)中的空白:
* [`numpy_matplotlib_sklearn.ipynb`](numpy_matplotlib_sklearn.ipynb)
* [OPTIONAL] [`pytorch.ipynb`](pytorch.ipynb)
* [OPTIONAL] [`keras.ipynb`](keras.ipynb)
2. 将完成notebook的公开在你fork的GitHub的repository上;
3. 完成作业回收问卷(需要填写一些分类精度和代码链接)。

## 通过这个项目,你将收获:
1. 学会如何使用numpy和matplotlib来处理数据;
2. 熟悉mnist手写数据集的形式和处理方式;
3. 初步了解pytorch或keras等深度学习框架的使用。
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# mnist_tutorial
# mnist_tutorial
A tutorial for mnist hand writen digit classification using sklearn, pytorch and keras.

# Code structure
* [`numpy_matplotlib_sklearn.ipynb`](numpy_matplotlib_sklearn.ipynb): for numpy, matplotlib and sklearn.
* [`pytorch.ipynb`](pytorch.ipynb): for pytorch.
* [`keras.ipynb`](keras.ipynb): for keras.
* Reference solution: (not published yet)
* [`numpy_matplotlib_sklearn_solution.ipynb`](numpy_matplotlib_sklearn_solution.ipynb)
* [`pytorch_solution.ipynb`](pytorch_solution.ipynb)
* [`keras_solution.ipynb`](keras_solution.ipynb)

# Requirements
Code tested on following environments, other version should also work:
* linux system (ubuntu 16.04)
* python 3.6.3
* numpy 1.13.3
* matplotlib 2.1.0
* sklearn 0.19.1
* pytorch 0.4.1
* keras 2.1.2

# For EE369 students from SJTU
Please read [HEAR](EE369.md).
150 changes: 150 additions & 0 deletions keras.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Keras Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Keras is a popular deep learning framework and it's easy to get started."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import keras\n",
"from keras.datasets import mnist\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D\n",
"\n",
"BATCH_SIZE = 128\n",
"NUM_CLASSES = 10\n",
"NUM_EPOCHS = 10"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we read the mnist data and preprocess them."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# download and load the data (split them between train and test sets)\n",
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
"\n",
"# expand the channel dimension\n",
"x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)\n",
"x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)\n",
"input_shape = (28, 28, 1)\n",
"\n",
"# make the value of pixels from [0, 255] to [0, 1] for further process\n",
"x_train = x_train.astype('float32') / 255.\n",
"x_test = x_test.astype('float32') / 255.\n",
"\n",
"# convert class vectors to binary class matrics\n",
"y_train = keras.utils.to_categorical(y_train, NUM_CLASSES)\n",
"y_test = keras.utils.to_categorical(y_test, NUM_CLASSES)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, we define the model, object function and optimizer that we use to classify."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# define the model\n",
"model = Sequential()\n",
"model.add(...)\n",
"model.add(...)\n",
"...\n",
"...\n",
"...\n",
"model.add(...)\n",
"\n",
"# define the object function, optimizer and metrics\n",
"model.compile(...)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we can start to train and evaluate!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# train\n",
"model.fit(...)\n",
"\n",
"# evaluate\n",
"score_train = \n",
"print('Training loss: %.4f, Training accuracy: %.2f%%' % (...))\n",
"score_test = \n",
"print('Testing loss: %.4f, Testing accuracy: %.2f%%' % (...))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Q6:\n",
"Please print the training and testing accuracy."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 27ca18b

Please sign in to comment.