Skip to content

Commit

Permalink
prep for new class
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas committed May 9, 2018
1 parent c32dbd1 commit 699bfa8
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 68 deletions.
4 changes: 2 additions & 2 deletions keras-autoencoder/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from keras.callbacks import Callback
import numpy as np
import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

run = wandb.init()
config = run.config
Expand Down Expand Up @@ -41,7 +41,7 @@ def on_epoch_end(self, epoch, logs):
model.fit(x_train, x_train,
epochs=config.epochs,
validation_data=(x_test, x_test),
callbacks=[Images(), WandbKerasCallback()])
callbacks=[Images(), WandbCallback()])


model.save('auto-small.h5')
Expand Down
4 changes: 2 additions & 2 deletions keras-autoencoder/autoencoder_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

run = wandb.init()
config = run.config
Expand Down Expand Up @@ -44,7 +44,7 @@ def on_epoch_end(self, epoch, logs):
model.fit(x_train, x_train,
epochs=config.epochs,
validation_data=(x_test, x_test),
callbacks=[Images(), WandbKerasCallback()])
callbacks=[Images(), WandbCallback()])


model.save('auto-cnn.h5')
Expand Down
4 changes: 2 additions & 2 deletions keras-autoencoder/denoising_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.datasets import mnist
import numpy as np
import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

def add_noise(x_train, x_test):
noise_factor = 0.5
Expand Down Expand Up @@ -50,7 +50,7 @@ def on_epoch_end(self, epoch, logs):

model.fit(x_train_noisy, x_train,
epochs=config.epochs,
validation_data=(x_test_noisy, x_test), callbacks=[Images(), WandbKerasCallback()])
validation_data=(x_test_noisy, x_test), callbacks=[Images(), WandbCallback()])


model.save("auto-denoise.h5")
Expand Down
4 changes: 2 additions & 2 deletions keras-autoencoder/denoising_autoencoder_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.datasets import mnist
import numpy as np
import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

def add_noise(x_train, x_test):
noise_factor = 0.5
Expand Down Expand Up @@ -60,7 +60,7 @@ def on_epoch_end(self, epoch, logs):

model.fit(x_train_noisy, x_train,
epochs=config.epochs,
validation_data=(x_test_noisy, x_test), callbacks=[Images(), WandbKerasCallback()])
validation_data=(x_test_noisy, x_test), callbacks=[Images(), WandbCallback()])


model.save("auto-denoise.h5")
Expand Down
4 changes: 2 additions & 2 deletions keras-autoencoder/wandb/settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[default]
entity: qualcomm
project: autoencoder-apr10
entity: trainai
project: encoding
base_url: https://api.wandb.ai
6 changes: 4 additions & 2 deletions keras-cnn/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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
from wandb.keras import WandbCallback
import wandb

run = wandb.init()
Expand All @@ -23,6 +23,7 @@
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]
labels=range(10)

# build model
model = Sequential()
Expand All @@ -41,4 +42,5 @@
model.summary()

model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)
epochs=config.epochs,
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])
2 changes: 1 addition & 1 deletion keras-cnn/convolution-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
image = io.imread('dog.jpg', as_grey=True)

kernel = [[0.0, 0.0, 0.0],
[0.5, 0.0, -0.5],
[0.0, 1.0, 0.0],
[0.0, 0.0, 0.0]]

new_image = convolve2d(image, kernel)
Expand Down
4 changes: 2 additions & 2 deletions keras-cnn/wandb/settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[default]
entity: mlclass
project: cnn-may1
entity: trainai
project: digits
base_url: https://api.wandb.ai
4 changes: 2 additions & 2 deletions keras-encoding/wandb/settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[default]
entity: mlclass
project: encoding-may1
entity: trainai
project: encoding
base_url: https://api.wandb.ai
4 changes: 2 additions & 2 deletions keras-fashion/wandb/settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[default]
entity: mlclass
project: fashion-may1
entity: trainai
project: fashion
base_url: https://api.wandb.ai
9 changes: 5 additions & 4 deletions keras-mlp/dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from keras.utils import np_utils
import json

from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback
import wandb

run = wandb.init()
Expand All @@ -23,9 +23,10 @@

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

y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

# create model
model=Sequential()
Expand All @@ -40,4 +41,4 @@

# Fit the model
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)
epochs=config.epochs, callbacks=[WandbCallback(validation_data=X_test, labels=labels)])
30 changes: 7 additions & 23 deletions keras-mlp/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from keras.callbacks import Callback
import json

from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback
import wandb

run = wandb.init()
Expand All @@ -26,9 +26,11 @@

# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

y_test = np_utils.to_categorical(y_test)

# create model
model=Sequential()
Expand All @@ -38,25 +40,7 @@
model.compile(loss='categorical_crossentropy', optimizer=config.optimizer,
metrics=['accuracy'])

class Images(Callback):
def on_epoch_end(self, epoch, logs):
# indices = np.random.randint(self.validation_data[0].shape[0], size=8)
test_data = self.validation_data[0][:10]
val_data = self.validation_data[1][:10]

test_data = X_test[:10]
val_data = y_test[:10]
print(val_data)

pred_data = self.model.predict(test_data)
run.history.row.update({
"examples": [
wandb.Image(test_data[i], caption=str(val_data[i])+str(np.argmax(val_data[i]))) for i in range(8)
]
})



# Fit the model
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[Images(), WandbKerasCallback()], epochs=config.epochs)
model.fit(X_train, y_train, validation_data=(X_test, y_test),
epochs=config.epochs,
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])
4 changes: 2 additions & 2 deletions keras-mlp/wandb/settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[default]
entity: mlclass
project: mlp-may1
entity: trainai
project: digits
base_url: https://api.wandb.ai
5 changes: 3 additions & 2 deletions keras-perceptron/perceptron-linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.utils import np_utils

import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

# logging code
run = wandb.init()
Expand All @@ -19,6 +19,7 @@
# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

Expand All @@ -31,6 +32,6 @@

# Fit the model
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()])
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])


5 changes: 3 additions & 2 deletions keras-perceptron/perceptron-log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from keras.callbacks import TensorBoard
import json

from wandb.wandb_keras import WandbKerasCallback
import wandb
from wandb.keras import WandbCallback

run = wandb.init()
config = run.config
Expand All @@ -29,6 +29,7 @@
# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

Expand All @@ -44,7 +45,7 @@
# Fit the model
history = model.fit(X_train, y_train, epochs=config.epochs,
batch_size=config.batch_size, validation_data=(X_test, y_test),
callbacks=[tensorboard, WandbKerasCallback()])
callbacks=[tensorboard, WandbCallback(validation_data=X_test, labels=labels)])

# Final evaluation of the model
scores = model.evaluate(X_test, y_test, verbose=0)
Expand Down
5 changes: 3 additions & 2 deletions keras-perceptron/perceptron-logistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.utils import np_utils

import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

# logging code
run = wandb.init()
Expand All @@ -19,6 +19,7 @@
# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

Expand All @@ -31,4 +32,4 @@

# Fit the model
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()])
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])
6 changes: 4 additions & 2 deletions keras-perceptron/perceptron-normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.layers import Dense, Flatten, Dropout
from keras.utils import np_utils
import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

# logging code
run = wandb.init()
Expand All @@ -24,6 +24,7 @@
# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
labels = range(10)

num_classes = y_train.shape[1]

Expand All @@ -36,4 +37,5 @@

# Fit the model
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()])
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])

8 changes: 4 additions & 4 deletions keras-perceptron/perceptron-single-fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.utils import np_utils

import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

# logging code
run = wandb.init()
Expand All @@ -15,6 +15,7 @@

is_five_train = y_train == 5
is_five_test = y_test == 5
labels = ["Not Five", "Is Five"]

img_width = X_train.shape[1]
img_height = X_train.shape[2]
Expand All @@ -27,7 +28,6 @@
metrics=['binary_accuracy'])

# Fit the model
model.fit(X_train[:1000], is_five_train[:1000], epochs=10, validation_data=(X_test, is_five_test),
callbacks=[WandbKerasCallback()])
model.fit(X_train, is_five_train, epochs=10, validation_data=(X_test, is_five_test),
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])

print(model.predict(X_test[:20]))
9 changes: 5 additions & 4 deletions keras-perceptron/perceptron-single.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from keras.utils import np_utils

import wandb
from wandb.wandb_keras import WandbKerasCallback
from wandb.keras import WandbCallback

# logging code
run = wandb.init()
Expand All @@ -15,19 +15,20 @@

is_five_train = y_train == 5
is_five_test = y_test == 5
labels = ["Not Five", "Is Five"]

img_width = X_train.shape[1]
img_height = X_train.shape[2]

# create model
model=Sequential()
model.add(Flatten(input_shape=(img_width,img_height)))
model.add(Dense(1))
model.add(Dense(1, activation="sigmoid"))
model.compile(loss='mse', optimizer='adam',
metrics=['binary_accuracy'])
metrics=['accuracy'])

# Fit the model
model.fit(X_train, is_five_train, epochs=10, validation_data=(X_test, is_five_test),
callbacks=[WandbKerasCallback()])
callbacks=[WandbCallback(validation_data=X_test, labels=labels)])


Loading

0 comments on commit 699bfa8

Please sign in to comment.