Hagbard
Hagbard

Reputation: 3680

No console output using Keras model.fit() function

I'm following this tutorial to perform time series classifications using Transformers with Keras and TensorFlow. I'm using Windows 10 and the PyDev Eclipse plugin. Unfortunately, my program stops and the console output is completely blank every time I run the following code:

n_classes = len(np.unique(y_train))
input_shape = np.array(x_trainScaled).shape[0:]

model = build_model(n_classes,input_shape,head_size=256,num_heads=4,ff_dim=4,num_transformer_blocks=4,mlp_units=[128],mlp_dropout=0.4,dropout=0.25)

model.compile(loss="sparse_categorical_crossentropy",optimizer=keras.optimizers.Adam(learning_rate=1e-4),metrics=["sparse_categorical_accuracy"])
print(model.summary())

callbacks = [keras.callbacks.EarlyStopping(patience=100, restore_best_weights=True)]

model.fit(x_trainScaled,y_train,validation_split=0.2,epochs=200,batch_size=64,callbacks=callbacks)

pathToModel = 'my/path/to/model/'
model.save(pathToModel)

Even previous warnings or print statements are completely erased and I have no idea what's going on. If I comment the model.fit(...) statement out, the program terminates and crashes with an error message resulting from a model.predict(...) call.

Any help is highly appreciated.

Upvotes: 1

Views: 1644

Answers (1)

Hagbard
Hagbard

Reputation: 3680

The solution was to transform the input data and labels to numpy arrays first. Thus, calling the fit function as follows:

model.fit(np.array(x_trainScaled),np.array(y_train),validation_split=0.2,epochs=200,batch_size=64,callbacks=callbacks)

worked perfectly fine for me, as opposed to:

model.fit(x_trainScaled,y_train,validation_split=0.2,epochs=200,batch_size=64,callbacks=callbacks)

Upvotes: 2

Related Questions