Code Monkey home page Code Monkey logo

ngdlm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ngdlm's Issues

TypeError: unsupported operand type(s) for *=: 'NoneType' and 'int'

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.