How to build a neural network without using keras compile method
I have the following neural network:
normalizer = preprocessing.Normalization()
normalizer.adapt(np.array(trainX))
batch_size=32
learning_rate=1e-3
model = tf.keras.Sequential([
normalizer,
layers.Dense(128, activation='elu', kernel_regularizer=regularizers.l2(0.01)),
layers.Dropout(0.5),
layers.Dense(128, activation='elu', kernel_regularizer=regularizers.l2(0.01)),
layers.Dropout(0.5),
layers.Dense(2),
layers.Softmax()])
model.compile(optimizer = keras.optimizers.Adam(learning_rate=learning_rate),
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = False),
metrics = ['accuracy'])
fitted_model = model.fit(trainX, trainY, epochs=50, verbose=0, batch_size=batch_size)
I would like to know how to build this neural network without using the compile function
Also what would I need to change if I want to run it on gpu instead of cpu
Topic gpu keras deep-learning optimization python
Category Data Science