Skip to content

Commit

Permalink
Merge pull request lukas#17 from lukas/feature/wandb
Browse files Browse the repository at this point in the history
Move things around
  • Loading branch information
lukas authored Oct 3, 2017
2 parents f880cd8 + e464234 commit 43b6978
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 172 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wandb-debug.log
114 changes: 62 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,37 @@ If you've never used pandas or numpy - they are great tools and I use them heavi
## Installation
Before the class, please run the following commands to install the prerequisite code.

### Linux and Mac OS X
#### Install python
### Windows

You can download python from https://www.python.org/downloads/. There are more detailed instructions for windows installation at https://www.howtogeek.com/197947/how-to-install-python-on-windows/.
#### Git

The material should work with python 2 or 3. *On Windows, you need to install thre 64 bit version of python 3.5 or 3.6 in order to install tensorflow*.
Install git: https://git-scm.com/download/win

#### Anaconda

Install [anaconda](https://repo.continuum.io/archive/Anaconda3-4.4.0-Windows-x86_64.exe)

Try running the following from the command prompt:

#### Clone this github repository
```
git clone https://github.com/lukas/ml-class.git
cd ml-class
python --version
```

If you get an error message here, most likely you don't have git installed. Go to https://www.atlassian.com/git/tutorials/install-git for intructions on installing git.
You should see something like

#### Install necessary pip libraries
```
pip install pandas
pip install scikit-learn
pip install tensorflow
pip install keras
Python 3.6.1 :: Anaconda 4.4.0 (64-bit)
```

#### Install python libraries for optional material
If don't see "Anaconda" in the output, search for "anaconda prompt" from the start menu and enter your command prompt this way. It's also best to use a virtual environment to keep your packages silo'ed. Do so with:

```
pip install h5py
pip install flask
pip install scikit-image
pip install scipy
pip install pillow
conda create -n ml-class python=3.6
activate ml-class
```

Whenever you start a new terminal, you will need to call `activate ml-class`.

#### Common problems

The most common problem is an old version of python. Its easy to have multiple versions of python installed at once and Macs in particular come with a default version of python that is too old to install tensorflow.
Expand All @@ -77,42 +76,53 @@ python --version

If your version is less than 2.7.12, you have a version issue. Try reinstalling python 2.

### Windows

#### Git

Install git from https://git-for-windows.github.io/

#### Anaconda

Install anaconda from https://www.anaconda.com/download/#download

Add Anaconda3 and Anaconda3/Scripts to your path environmental variable

try running

#### Clone this github repository
```
python --version
git clone https://github.com/lukas/ml-class.git
cd ml-class
```

You should see something like
#### libraries

```
Python 3.6.1 :: Anaconda 4.4.0 (64-bit)
pip install wandb
conda install -c conda-forge scikit-learn
conda install -c conda-forge tensorflow
conda install -c conda-forge keras
```

### Linux and Mac OS X
#### Install python

You can download python from https://www.python.org/downloads/. There are more detailed instructions for windows installation at https://www.howtogeek.com/197947/how-to-install-python-on-windows/.

The material should work with python 2 or 3. *On Windows, you need to install thre 64 bit version of python 3.5 or 3.6 in order to install tensorflow*.

#### Clone this github repository
```
git clone https://github.com/lukas/ml-class.git
cd ml-class
```

#### libraries
If you get an error message here, most likely you don't have git installed. Go to https://www.atlassian.com/git/tutorials/install-git for intructions on installing git.

#### Install necessary pip libraries
```
conda install -c conda-forge scikit-learn
conda install -c conda-forge tensorflow
conda install -c conda-forge keras
pip install wandb
pip install pandas
pip install scikit-learn
pip install tensorflow
pip install keras
```

#### Install python libraries for optional material
```
pip install h5py
pip install flask
pip install scikit-image
pip install scipy
pip install pillow
```


Expand Down Expand Up @@ -192,16 +202,16 @@ Order of presentation of files, if you want to follow along
- keras-scikit-learn.py
- keras-one-hot.py
- log-loss.py
- keras-perceptron-1.py
- keras-perceptron-2.py
- keras-perceptron-3.py
- keras-perceptron-4.py
- keras-perceptron-checkpoint.py
- keras-perceptron-save.py
- keras-perceptron-load.py
- keras-perceptron-regression.py
- keras-mlp.py
- keras-dropout.py
- keras-perceptron/perceptron-1.py
- keras-perceptron/perceptron-2.py
- keras-perceptron/perceptron-3.py
- keras-perceptron/perceptron-4.py
- keras-perceptron/perceptron-checkpoint.py
- keras-perceptron/perceptron-save.py
- keras-perceptron/perceptron-load.py
- keras-perceptron/perceptron-regression.py
- keras-mlp/mlp.py
- keras-mlp/dropout.py

### tensorflow
- tensorflow-mult.py
Expand All @@ -214,9 +224,9 @@ Order of presentation of files, if you want to follow along
### conv neural nets
- convolution-demo.py
- maxpool-demo.py
- keras-cnn-1.py
- keras-cnn-2.py
- keras-cnn-inspect.py
- keras-cnn/cnn-1.py
- keras-cnn/cnn-2.py
- keras-cnn/cnn-inspect.py

### deep dream
- keras-deep-dream.py
Expand Down
41 changes: 0 additions & 41 deletions keras-cnn-2.py

This file was deleted.

16 changes: 2 additions & 14 deletions keras-cnn-wandb.py → keras-cnn/cnn-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
run = wandb.init()
config = run.config


(X_train, y_train), (X_test, y_test) = mnist.load_data()

config = wandb.run.config
config.first_layer_convs = 32
config.first_layer_conv_width = 3
config.first_layer_conv_height = 3
config.dropout = 0.2
config.dense_layer_size = 128
config.img_width=28
config.img_height=28

X_train = X_train.astype('float32')
X_train /= 255.
X_test = X_test.astype('float32')
Expand All @@ -29,14 +19,12 @@
X_train = X_train.reshape(X_train.shape[0], config.img_width, config.img_height, 1)
X_test = X_test.reshape(X_test.shape[0], config.img_width, config.img_height, 1)


# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]

# build model

model = Sequential()
model.add(Conv2D(32,
(config.first_layer_conv_width, config.first_layer_conv_height),
Expand All @@ -48,5 +36,5 @@

model.compile(loss='categorical_crossentropy', optimizer='adam',
metrics=['accuracy'])
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)
25 changes: 12 additions & 13 deletions keras-cnn-1.py → keras-cnn/cnn-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Dense, Flatten
from keras.utils import np_utils

from wandb.wandb_keras import WandbKerasCallback
import wandb

run = wandb.init()
config = run.config


(X_train, y_train), (X_test, y_test) = mnist.load_data()

img_width=28
img_height=28

X_train = X_train.astype('float32')
X_train /= 255.
X_test = X_test.astype('float32')
X_test /= 255.

#reshape input data
X_train = X_train.reshape(X_train.shape[0], img_width, img_height, 1)
X_test = X_test.reshape(X_test.shape[0], img_width, img_height, 1)
X_train = X_train.reshape(X_train.shape[0], config.img_width, config.img_height, 1)
X_test = X_test.reshape(X_test.shape[0], config.img_width, config.img_height, 1)

# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]

# build model

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(img_width, img_height,1), activation='relu'))
model.add(Conv2D(8, (5, 5), input_shape=(config.img_width, config.img_height,1), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(16, (5, 5), input_shape=(config.img_width, config.img_height,1), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, y_train)
model.compile(loss='categorical_crossentropy', optimizer='adam',
metrics=['accuracy'])
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)


File renamed without changes.
26 changes: 26 additions & 0 deletions keras-cnn/config-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
wandb_version: 1

first_layer_convs:
desc: Number of convolutions in the first layer
value: 32
first_layer_conv_width:
desc: The width of the convolution
value: 3
first_layer_conv_height:
desc: The height of the convolution
value: 3
dropout:
desc: Percentage of neurons to dropout
value: 0.2
dense_layer_size:
desc: The size of the dense layer
value: 128
img_width:
desc: The width of the input image
value: 28
img_height:
desc: The height of the input image
value: 28
epochs:
desc: The number of epochs to run
value: 10
3 changes: 3 additions & 0 deletions keras-cnn/wandb/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
entity: qualcomm
project: cnn
35 changes: 0 additions & 35 deletions keras-mlp.py

This file was deleted.

11 changes: 11 additions & 0 deletions keras-mlp/config-defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
wandb_version: 1

# Example variables below. Uncomment (remove leading '# ') to use them, or just
# delete and create your own.

epochs:
desc: Number of epochs to train over
value: 10
hidden_nodes:
desc: Size of the hidden layer
value: 100
Loading

0 comments on commit 43b6978

Please sign in to comment.