Hello all,
i’am getting this Warning: WARNING:tensorflow:Found duplicated Variable
s in Model’s weights
. This is usually caused by Variable
s being shared by Layers in the Model. These Variable
s will be treated as separate Variable
s when the Model is restored. To avoid this, please save with save_format="tf"
.
from keras.models import Model
import keras
from keras.datasets import mnist
from keras.layers import Dense, Input
from keras.layers import Conv2D, Flatten, Lambda,LeakyReLU
from keras.layers import Reshape, Conv2DTranspose
from keras import backend as K
from keras.losses import binary_crossentropy
from numpy import reshape
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
#import tensorflow._api.v2.compat.v1 as tf
#tf.disable_v2_behavior()
TrainingsSet = np.load('TrainingsSet_CONV.npy')
ValidationSet = np.load('ValidationSet_CONV.npy')
print(TrainingsSet.shape)
print(ValidationSet.shape)
latent_dim = 1500
def sample_z(args):
z_mu, z_sigma = args
eps = K.random_normal(shape=(K.shape(z_mu)[0], K.int_shape(z_mu)[1]))
return z_mu + K.exp(z_sigma / 2) * eps
input_img = tf.keras.layers.Input(shape=(64,256,3))
x = tf.keras.layers.Conv2D(128, (2, 2), strides=(2,2), activation=LeakyReLU(alpha=0.3), padding='same')(input_img)
x = tf.keras.layers.Conv2D(64, (2, 2), strides=(2,2), activation=LeakyReLU(alpha=0.3), padding='same')(x)
x = tf.keras.layers.Conv2D(16, (2, 2), strides=(2,2), activation=LeakyReLU(alpha=0.3), padding='same')(x)
conv_shape = K.int_shape(x)
x = Flatten()(x)
x = Dense(32, activation='relu')(x)
z_mu = Dense(latent_dim, name='latent_mu')(x) #Mean values of encoded input
z_sigma = Dense(latent_dim, name='latent_sigma')(x) #Std dev. (variance) of encoded input
z = Lambda(sample_z, output_shape=(latent_dim, ), name='z')([z_mu, z_sigma])
encoder = Model(input_img, [z_mu, z_sigma, z], name='encoder')
print(encoder.summary())
decoder_input = Input(shape=(latent_dim, ), name='decoder_input')
x = Dense(conv_shape[1]*conv_shape[2]*conv_shape[3], activation='relu')(decoder_input)
x = Reshape((conv_shape[1], conv_shape[2], conv_shape[3]))(x)
x = tf.keras.layers.Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same', activation=LeakyReLU(alpha=0.3))(x)
x = tf.keras.layers.Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same', activation=LeakyReLU(alpha=0.3))(x)
x = tf.keras.layers.Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same', activation=LeakyReLU(alpha=0.3))(x)
decoder_outputs = tf.keras.layers.Conv2DTranspose(3, (3, 3), padding='same', activation=LeakyReLU(alpha=0.3))(x)
decoder = Model(decoder_input, decoder_outputs, name='decoder')
decoder.summary()
outputs = decoder(encoder(input_img)[2])
vae = Model(input_img, outputs, name='vae')
reconst_loss = binary_crossentropy(K.flatten(input_img), K.flatten(outputs))
reconst_loss *= 64 *256*3
kl_loss = -0.5 * K.sum(1 + z_sigma - K.square(z_mu) - K.exp(z_sigma), axis = 1)
vae_loss = K.mean(reconst_loss + kl_loss)
vae.add_loss(vae_loss)
vae.compile(optimizer='adam')
vae.summary()
vae.fit(TrainingsSet,epochs=1,batch_size=128,shuffle=True,validation_data=(ValidationSet,None))
vae.save("modellname.h5", save_format="tf")
my Code is above. How can i save my VAE properly? My Network works fine. But i cant save my model, so i can start training it on antoher day. Please can someone help me.
yours MU SO