Code Monkey home page Code Monkey logo

Comments (1)

a-sarabi avatar a-sarabi commented on June 26, 2024 1

Thank you. I solved this issue by implementing a data_generator function to facilitate training based on batch size.

    def data_generator(X, correlation, decoder_Y, Y, batch_size=50):
        while True:
            perm = np.random.permutation(len(X))
            for i in range(0, len(X), batch_size):
                batch_X = X[perm[i:i + batch_size]]

                # Efficiently broadcasting the correlation matrix for this batch
                batch_correlation = np.repeat(correlation[np.newaxis, ...], len(batch_X), axis=0)

                batch_decoder_Y = decoder_Y[perm[i:i + batch_size]]
                batch_Y = Y[perm[i:i + batch_size]]
                yield [batch_X, batch_correlation, batch_decoder_Y], batch_Y

.......................
.......................

        # Create the training generator
        train_gen = data_generator(X_train_train, correlation_train_train, decoder_Y_train_train, Y_train_train, batch_size=50)

        # Create the validation generator
        val_gen = data_generator(X_train_valid, correlation_train_train, decoder_Y_train_valid, Y_train_valid,
                                   batch_size=50)

        # Calculate the steps per epoch for training and validation
        train_steps = len(X_train_train) // 50
        val_steps = len(X_train_valid) // 50

        # Use the generators in model.fit()
        model.fit(train_gen,
                  steps_per_epoch=train_steps,
                  validation_data=val_gen,
                  validation_steps=val_steps,
                  epochs=100,
                  callbacks=callbacks)

from spektral.

Related Issues (20)

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.