Skip to content

Instantly share code, notes, and snippets.

@keithmgould
Created April 22, 2019 19:59
Show Gist options
  • Save keithmgould/9f1cb7c738caa7b1f7d869c2526c670e to your computer and use it in GitHub Desktop.
Save keithmgould/9f1cb7c738caa7b1f7d869c2526c670e to your computer and use it in GitHub Desktop.
failing code snippet for multiple models
import numpy as np
from keras.models import Sequential
from keras.callbacks import TensorBoard
from keras.layers import *
from keras.optimizers import *
N=10
INPUT_LEN = 4
OUTPUT_LEN = 2
def make_model(model):
model.add(Dense(units=8, activation='relu', input_dim=INPUT_LEN))
model.add(Dense(units=OUTPUT_LEN, activation='linear'))
model.compile(loss='categorical_crossentropy', optimizer='adam')
model1 = Sequential()
model2 = Sequential()
make_model(model1)
make_model(model2)
print(model1.summary())
print(model2.summary())
x = np.random.rand(N, INPUT_LEN)
y = np.random.randint(0,5, size=(N,OUTPUT_LEN))
print("x shape: {}".format(x.shape))
print("y shape: {}".format(y.shape))
model1.fit(x, y, callbacks=[TensorBoard(log_dir='./tmp', histogram_freq=1)], epochs=10, validation_data=(x,y))
model2.fit(x, y, callbacks=[TensorBoard(log_dir='./tmp', histogram_freq=1)], epochs=10, validation_data=(x,y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment