ubuntu_noob
ubuntu_noob

Reputation: 2365

WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built

My model-

from tensorflow.keras.layers import ReLU
from keras.layers import Dropout
from tensorflow.keras.utils import plot_model
from matplotlib import pyplot

# define encoder
visible = Input(shape=(n_inputs,))



# encoder level 1
e = Dense(300)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(200)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(100)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(50)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)



# bottleneck
n_bottleneck = round(float(n_inputs))
bottleneck = Dense(n_bottleneck)(e)


# define decoder, level 1
# encoder level 1
d = Dense(50)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(100)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(200)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(300)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

# output layer
output = Dense(n_inputs, activation='sigmoid')(d)
# define autoencoder model
model = Model(inputs=visible, outputs=output)

# compile autoencoder model
model.compile(optimizer='adam', loss='binary_crossentropy')

# plot the autoencoder
plot_model(model, 'autoencoder_compress.png', show_shapes=True)
# fit the autoencoder model to reconstruct input
history = model.fit(X_train_norm, X_train_norm, epochs=100, batch_size=32, verbose=2, validation_data=(X_test_norm,X_test_norm))
# plot loss
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()
# define an encoder model (without the decoder)
encoder = Model(inputs=visible, outputs=bottleneck)
plot_model(encoder, 'encoder_compress.png', show_shapes=True)
# save the encoder to file
encoder.save('drive/MyDrive/encoder_rf.h5')

Im getting this error-

WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.

The model has been trained.

enter image description here

Upvotes: 5

Views: 27909

Answers (2)

Jim
Jim

Reputation: 111

Just compile the new encoder model before plotting it.

This code does not give a warning:

from tensorflow.keras.layers import ReLU, Input, Dense
from keras.layers import Dropout
from tensorflow.keras.utils import plot_model
from matplotlib import pyplot
from tensorflow.keras.models import Model

n_inputs = 100

# define encoder
visible = Input(shape=(n_inputs,))



# encoder level 1
e = Dense(300)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(200)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(100)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)

# encoder level 1
e = Dense(50)(visible)
e = ReLU()(e)
e = Dropout(0.05)(e)



# bottleneck
n_bottleneck = round(float(n_inputs))
bottleneck = Dense(n_bottleneck)(e)


# define decoder, level 1
# encoder level 1
d = Dense(50)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(100)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(200)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

d = Dense(300)(bottleneck)
d = ReLU()(d)
d = Dropout(0.05)(d)

# output layer
output = Dense(n_inputs, activation='sigmoid')(d)

# define an encoder model (without the decoder)
encoder = Model(inputs=visible, outputs=bottleneck)



# Compile before plotting
encoder.compile(optimizer='adam', loss='binary_crossentropy')



plot_model(encoder, 'encoder_compress.png', show_shapes=True)
# save the encoder to file
encoder.save('drive/MyDrive/encoder_rf.h5')

Upvotes: 3

In your code, model.compiled_metrics is None, check this

model.compiled_metrics == None

you have defined a new encoder instance without weights, updated weights from your model. save encoder after training.

There is no encoder-decoder in your code.

Upvotes: 2

Related Questions