ai-guru / ngdlm Goto Github PK
View Code? Open in Web Editor NEWNext Generation Deep Learning Models
License: GNU General Public License v3.0
Next Generation Deep Learning Models
License: GNU General Public License v3.0
input_shape = (28, 28)
latent_dim = 128
encoder_input = layers.Input(shape=input_shape)
encoder_output = encoder_input
encoder_output = layers.Reshape(input_shape + (1,))(encoder_input)
encoder_output = layers.Conv2D(16, (3, 3), activation="relu", padding="same")(encoder_output)
encoder_output = layers.MaxPooling2D((2, 2), padding="same")(encoder_output)
encoder_output = layers.Conv2D(8, (3, 3), activation="relu", padding="same")(encoder_output)
encoder_output = layers.MaxPooling2D((2, 2), padding="same")(encoder_output)
encoder_output = layers.Conv2D(8, (3, 3), activation="relu", padding="same")(encoder_output)
encoder_output = layers.MaxPooling2D((2, 2), padding="same")(encoder_output)
encoder_output = layers.Flatten()(encoder_output)
encoder = models.Model(encoder_input, encoder_output)
# Create the decoder.
decoder_input = layers.Input(shape=(latent_dim,))
decoder_output = decoder_input
#decoder_output = layers.Dense(128, activation="relu")(decoder_output)
decoder_output = layers.Reshape((4, 4, 8))(decoder_output)
decoder_output = layers.Conv2D(8, (3, 3), activation="relu", padding="same")(decoder_output)
decoder_output = layers.UpSampling2D((2, 2))(decoder_output)
decoder_output = layers.Conv2D(8, (3, 3), activation="relu", padding="same")(decoder_output)
decoder_output = layers.UpSampling2D((2, 2))(decoder_output)
decoder_output = layers.Conv2D(16, (3, 3), activation="relu")(decoder_output)
decoder_output = layers.UpSampling2D((2, 2))(decoder_output)
decoder_output = layers.Conv2D(1, (3, 3), activation="sigmoid", padding="same")(decoder_output)
decoder_output = layers.Reshape((28, 28))(decoder_output)
decoder = models.Model(decoder_input, decoder_output)
# Create the VAE.
vae = ngdlmodels.VAE(encoder, decoder, latent_dim=latent_dim)
vae.compile(optimizer='adadelta', reconstruction_loss="binary_crossentropy")
vae.summary()
# Train.
print("Train...")
history = vae.fit(
x_input_train, x_input_train,
epochs=100,
batch_size=32,
shuffle=True,
validation_data=(x_input_test, x_input_test)
)
# Evaluate.
print("Evaluate...")
loss = vae.model.evaluate(x_input_test, x_input_test)
print("Loss:", loss)
Throws error
TypeError Traceback (most recent call last)
<ipython-input-22-1acf0e514e9b> in <module>()
31 # Create the VAE.
32 vae = ngdlmodels.VAE(encoder, decoder, latent_dim=latent_dim)
---> 33 vae.compile(optimizer='adadelta', reconstruction_loss="binary_crossentropy")
34 vae.summary()
35
~/anaconda3/lib/python3.6/site-packages/ngdlm/models.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs)
433 # Compile model.
434 loss = vae_loss
--> 435 self.autoencoder.compile(optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, **kwargs)
436
437
~/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs)
330 with K.name_scope(self.output_names[i] + '_loss'):
331 output_loss = weighted_loss(y_true, y_pred,
--> 332 sample_weight, mask)
333 if len(self.outputs) > 1:
334 self.metrics_tensors.append(output_loss)
~/anaconda3/lib/python3.6/site-packages/keras/engine/training_utils.py in weighted(y_true, y_pred, weights, mask)
401 """
402 # score_array has ndim >= 2
--> 403 score_array = fn(y_true, y_pred)
404 if mask is not None:
405 # Cast the mask to floatX to avoid float64 upcasting in Theano
~/anaconda3/lib/python3.6/site-packages/ngdlm/models.py in vae_loss(loss_inputs, loss_outputs)
419 else:
420 r_loss = self.loss
--> 421 r_loss *= inputs_dim
422
423 # kl loss.
TypeError: unsupported operand type(s) for *=: 'NoneType' and 'int'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.